Skip to main content

Posts

Difference between wait (), notify () and notifyAll ()

Wait , notify and notifyAll is one of the very much required object class methods required for inter Thread communication. wait () method is responsible of releasing the lock on shared resources where as on the other side notify () and notifyAll () methods are responsible for notify the waited Threads to start consuming the lock again.
Recent posts

Grail All Domain class Variables By Default null.

Many of the time we have the need that to make the Grail domain class variables as null; where as Grail implicit concept is all the variables of domain class are not null, so we will have to make the static constraints{nullable:true} many times for each variable. where as we have a sweet option via which we can make all the domain class variables by default null and can overwrite the behavior to not null in constraints declaration block. To make the by default null behavior for each domain class we will have to put the below code snippet on config.groovy file. grails.gorm.default.constraints = {'*'(nullable: true)}

JSF Lifecycle Phases

JSF Lifecycle Phases JSF follows MVC design pattern to handle request-response process. Basically JSF handles three types of requests. Non-Faces Request Generates Faces Response Faces Request Generates Non-Faces Response Faces Request Generates Faces Response In another case of course non-jsf to non-jsf is there but in this case there is no involvement of JSF action here, so this is not a part of jsf lifecycle process. A JavaServer Faces page is represented by a tree of UI components, called a view . When a client makes a request for the page, the life cycle starts. During the life cycle, the JavaServer Faces implementation must build the view while considering state saved from a previous submission of the page. When the client submits a page, the JavaServer Faces implementation must perform several tasks, such as validating the data input of components in the view and converting input data to types specified on the server side. The JavaServer Faces implementation performs a...

Hibernate session.merge(persistingObject) Vs session.saveOrUpdate(persistingObject)

Hibernate provide two techniques to deal with save and update functionality, As per those techniques it first checks the instance in db, if It is already persisted in that database, if that is the case then it will simply persist the updated fields into DB otherwise it will persist the new instance in to DB. session.saveOrUpdate(persistingInstance) :It also persist the new instance in to DB and update the already persisted instances. Insert the data if the primary key is not exist. Problem:In some scenario's you might face the issue of NonUniqueObjectException : message "a different object with the same identifier value was already associated with the session." Technically before persisting in to db it first check in to the Hibernate cache, and by any reason if that object is present in cache then you will get the above exception. So by remedy of the above issue we can use session.merge(persistingObject) : It is directly checking in to your databa...

java.lang.Comparator Vs java.lang.Comparable

What are Java Comparators and Comparables? As both names suggest (and you may have guessed), these are used for comparing objects in Java. Using these concepts; Java objects can be sorted according to a predefined order. Two of these concepts can be explained as follows. Comparable A comparable object is capable of comparing itself with another object. The class itself must implements the java.lang.Comparable interface in order to be able to compare its instances. Comparator A comparator object is capable of comparing two different objects. The class is not comparing its instances, but some other class’s instances. This comparator class must implement the java.lang.Comparator interface. How to use these? There are two interfaces in Java to support these concepts, and each of these has one method to be implemented by user. Those are; java.lang.Comparable: int compareTo(Object o1) This method compares this object with o1 object. Returned int value has the following meanings. 1. positiv...

Linked List Example

/* * Copyright (c) 2000 David Flanagan. All rights reserved. * This code is from the book Java Examples in a Nutshell, 2nd Edition. * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied. * You may study, use, and modify it for any non-commercial purpose. * You may distribute it non-commercially as long as you retain this notice. * For a commercial use license, or to purchase the book (recommended), * visit http://www.davidflanagan.com/javaexamples2. */ /** * This class implements a linked list that can contain any type of object that * implements the nested Linkable interface. Note that the methods are all * synchronized, so that it can safely be used by multiple threads at the same * time. */ public class LinkedList { /** * This interface defines the methods required by any object that can be * linked into a linked list. */ public interface Linkable { public Linkable getNext(); // Returns the next element in the list public...

Sorting an List in Java

// Create a list String[] strArray = new String[] {"z", "a", "C"}; List list = Arrays.asList(strArray); // Sort Collections.sort(list); // C, a, z // Case-insensitive sort Collections.sort(list, String.CASE_INSENSITIVE_ORDER); // a, C, z // Reverse-order sort Collections.sort(list, Collections.reverseOrder()); // z, a, C // Case-insensitive reverse-order sort Collections.sort(list, String.CASE_INSENSITIVE_ORDER); Collections.reverse(list); // z, C, a