Monday, December 26, 2016


public static void main(String[] args) Next, describe what each of public, static, void, main, String[], and args does. It is probably sufficient to just verbalize what each means. But if you want to write each word down as you verbalize, it helps to get the point across.

a) public means that the method is visible everywhere
b) static means you don’t need an instance of the class to call the method
c) void means the method doesn’t return anything
d) main is just the predefined method name for how to start a Java program
e) String[] means the method accepts an array of strings as arguments to the method
f) args is the name of the parameter to the method. Any name will do here. There is no hard and fast requirement that the parameter be called args.

Wednesday, September 14, 2016

Interface


What is an Interface


As you've already learned, objects define their interaction with the outside world through the methods that they expose. Methods form the object's interface with the outside world; the buttons on the front of your television set, for example, are the interface between you and the electrical wiring on the other side of its plastic casing. You press the "power" button to turn the television on and off.


In its most common form, an interface is a group of related methods with empty bodies. A bicycle's behavior, if specified as an interface, might appear as follows:

interface Bicycle {

    //  wheel revolutions per minute
    void changeCadence(int newValue);

    void changeGear(int newValue);

    void speedUp(int increment);

    void applyBrakes(int decrement);
}





To implement this interface, the name of your class would change (to a particular brand of bicycle, for example, such as ACMEBicycle), and you'd use the implements keyword in the class declaration: class ACMEBicycle implements Bicycle { int cadence = 0; int speed = 0; int gear = 1; // The compiler will now require that methods // changeCadence, changeGear, speedUp, and applyBrakes // all be implemented. Compilation will fail if those // methods are missing from this class. void changeCadence(int newValue) { cadence = newValue; } void changeGear(int newValue) { gear = newValue; } void speedUp(int increment) { speed = speed + increment; } void applyBrakes(int decrement) { speed = speed - decrement; } void printStates() { System.out.println("cadence:" + cadence + " speed:" + speed + " gear:" + gear); } }


Interface==product Specification==Rule setter==No implementation==No instantiation==class will give implementation

For more details

Monday, May 23, 2016


welcome to jsf hello world in tomcat with eclipse using mojarra FCS jsf 2.0 file....... New......dynamic web project.... project name===== hellojsf Refferences Go to tutorial

Ways to create object in java


there are six different ways to create object in java
  1. new keyword
  2. class.forName()=====CrunchifyObj object2 = (CrunchifyObj) Class.forName("crunchify.com.tutorial.CrunchifyObj").newInstance();
  3. clone()
  4. newInstance() ====CrunchifyObj.class.getClassLoader().loadClass("crunchify.com.tutorial.CrunchifyObj").newInstance();
  5. Deserialization
  6. use the Constructor class from the java.lang.reflect

for more details


ClassNotFoundException vs NoClassDefFoundError


Though both of these errors are related to missing classes in the classpath, the main difference between them is their root cause.

ClassNotFoundExcpetion comes when you try to load a class at runtime by using Class.forName() or loadClass() and requested class is not present

in classpath for example when you try to load MySQL or Oracle driver class and their JAR is not available, while in case of

NoClassDefFoundError requested class was present at compile time but not available at runtime. Sometimes due to an exception during class

initialization e.g. exception from static block causes NoClassDefFoundError when a failed-to-load class was later referenced by the runtime

for more details

Sunday, May 22, 2016


Difference between ArrayList and LinkedList in Java


for more details 1. Implementation : ArrayList is the resizable array implementation of list interface , while LinkedList is the Doubly-linked list implementation of the list interface. 2. Performance : Performance of ArrayList and LinkedList depends on the type of operation a. get(int index) or search operation : ArrayList get(int index) operation runs in constant time i.e O(1) while LinkedList get(int index) operation run time is O(n) . The reason behind ArrayList being faster than LinkedList is that ArrayList uses index based system for its elements as it internally uses array data structure , on the other hand , LinkedList does not provide index based access for its elements as it iterates either from the beginning or end (whichever is closer) to retrieve the node at the specified element index. b. insert() or add(Object) operation : Insertions in LinkedList are generally fast as compare to ArrayList. In LinkedList adding or insertion is O(1) operation . While in ArrayList, if array is full i.e worst case, there is extra cost of resizing array and copying elements to the new array , which makes runtime of add operation in ArrayList O(n) , otherwise it is O(1) . c. remove(int) operation : Remove operation in LinkedList is generally same as ArrayList i.e. O(n). In LinkedList , there are two overloaded remove methods. one is remove() without any parameter which removes the head of the list and runs in constant time O(1) . The other overloaded remove method in LinkedList is remove(int) or remove(Object) which removes the Object or int passed as parameter . This method traverses the LinkedList until it found the Object and unlink it from the original list . Hence this method run time is O(n). While in ArrayList remove(int) method involves copying elements from old array to new updated array , hence its run time is O(n). 3. Reverse Iterator : LinkedList can be iterated in reverse direction using descendingIterator() while there is no descendingIterator() in ArrayList , so we need to write our own code to iterate over the ArrayList in reverse direction. 4. Initial Capacity : If the constructor is not overloaded , then ArrayList creates an empty list of initial capacity 10 , while LinkedList only constructs the empty list without any initial capacity. 5. Memory Overhead : Memory overhead in LinkedList is more as compared to ArrayList as node in LinkedList needs to maintain the addresses of next and previous node. While in ArrayList each index only holds the actual object(data).

Friday, May 20, 2016

Hashmap bucket concept with Hashcode and equals method implementation

Bucket concept of HashMap
please look how the bucket id is calculated for a particular key ------------
Hashtable: obj.hashCode() % Hashtable.length
where
legth==capacity for the hashtable or Hashmap or no of bucket
Default no of buckets or capacity for Hashmap is == 16 with 0.75 load factor
load factor 0.75 means on 13th insert again it will grows the buckets with specified capacity


Hashcode and equals Contract example with two different map object having same hashcode for same keys and same values for both the Maps 

public class Test {
    public static void main(String[] args) {

        Map map = new HashMap();
        map.put(1, 11);
        map.put(4, 11);
        System.out.println(map.hashCode());
        Map map1 = new HashMap();
        map1.put(1, 11);
        map1.put(4, 11);
        System.out.println(map1.hashCode());
        if (map.equals(map1)) {
            System.out.println("equal ");
        }
    }
}


click for more details for bucket ID

Thursday, May 5, 2016

What is JAVA ? Java is pure object oriented,platform independent ,distributed,multi threaded,web based ,secure and robust programming language used world wide.