Where and how can you use a private constructor?

Private constructor is used if you do not want other classes to instantiate the object and to prevent subclassing. The instantiation is done by a public static method (i.e. a static factory method) within the same class. Used in the singleton design pattern. Used in the factory method design pattern e.g. java.util.Collections class Used in utility classes e.g. StringUtils etc.

What are access modifiers?

Modifier Used with Description public Outer classes, interfaces, constructors, Inner classes, methods and field variables A class or interface may be accessed from outside the package. Constructors, inner classes, methods and field variables may be accessed wherever their class is accessed. protected Constructors, inner classes, methods, and field variables. Accessed by other classes in the same package or any subclasses of the class in which they are referred (i.e. same package or different package). private Constructors, inner classes, methods and field variables, Accessed only within the class in which they are declared No modifier : (Package by default). Outer classes, … Click here to continue…..

What is the difference between a stack and a queue?

Queue Stack First item to be inserted is the first one to be removed. Allows access to only last item inserted. This mechanism is called First In First Out (FIFO). An item is inserted or removed from one end called the “top” of the stack. This is called Last In First Out (LIFO) mechanism. Placing an item in the queue is called “enqueue or insertion” and removing an item from a queue is called “dequeue or deletion”. Pre J2SE 5.0, you should write your own Queue class with enqueue() and dequeue() methods using an ArrayList or a LinkedList class. J2SE … Click here to continue…..