Posts

Showing posts with the label JAVA INTERVIEW

Java interview questions and answers

Describe what happens when an object is created in Java? Several things happen in a particular order to ensure the object is constructed properly: 1. Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implementation-specific data includes pointers to class and method data. 2. The instance variables of the objects are initialized to their default values. 3. The constructor for the most derived class is invoked. The first thing a constructor does is call the constructor for its uppercase. This process continues until the constructor for java.lang.Object is called, as java.lang.Object is the base class for all objects in java. 4. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes l...

Difference Between ArrayList,Vector,LinkList?

ArrayList  Think of this as a growable array. It gives you fast iteration and fast random access. To state the obvious: it is an ordered collection (by index), but not sorted.ArrayList now implements the new RandomAccess interface—a marker interface (meaning it has no methods)  that says, "this list supports fast (generally constant time) random access." Choose this over a LinkedList when you need fast iteration but aren't as likely to be doing a lot of insertion and deletion. Vector  Vector is a holdover from the earliest days of Java; Vector and Hashtable were the two original collections,A Vector is basically the same as an ArrayList, but Vector methods are syn- chronized for thread safety. You'll normally want to use ArrayList instead of Vector because the synchronized methods add a performance hit you might not need. And if you do need thread safety, there are utility methods in class Collections that can help. Vector is the only class other ...

Java Collections Framework

Part of Collections Framework Collection          Collection Subtypes: The following interfaces (collection types) extends the Collection interface:   1.  List   2.  Set   3. SortedSet   4. NavigableSet   5. Queue   6. Deque  Example : import java . util .*; import java . util . Collection ; public class collectioninterface { public static void main ( String [] args ) { Collection collection = new ArrayList (); collection . add ( "Dev" ); collection . add ( "Manuals" ); System . out . print ( " Elements Of the Array List are " ); System . out . print ( collection + "." ); } }     Set     Set Interface in Java:- The Set interface extends the Collection interface. A Set is a Collection that cannot contain duplicate elements. Not only must these elements be unique, but while they are in the set, each element must not be ...