Singleton is a design pattern meant to provide one and only one instance of an
object. Other objects can get a reference to this instance through a static
method (class constructor is kept private). Why do we need one? Sometimes it
is necessary, and often sufficient, to create a single instance of a given
class. This has advantages in memory management, and for Java, in garbage
collection. Moreover, restricting the number of instances may be necessary or
desirable for technological or business reasons--for example, we may only want
a single instance of a pool of database connections.
2)What is a compilation unit?
The smallest unit of source code that can be compiled, i.e. a .java
file.
3)Is string a wrapper class?
String is a class, but not a wrapper class. Wrapper classes like (Integer)
exist for each primitive type. They can be used to convert a primitive data
value into an object, and vice-versa.
4)Why java does not have multiple
inheritance?
The Java design team strove to make Java:
Simple, object oriented, and familiar
Robust and secure
Architecture neutral and portable
High performance
Interpreted, threaded, and dynamic
The reasons for omitting multiple
inheritance from the Java language mostly stem from the "simple, object
oriented, and familiar" goal. As a simple language, Java's creators wanted a
language that most developers could grasp without extensive training. To that
end, they worked to make the language as similar to C++ as possible (familiar)
without carrying over C++'s unnecessary complexity (simple).
In the designers' opinion, multiple
inheritance causes more problems and confusion than it solves. So they cut
multiple inheritance from the language (just as they cut operator
overloading). The designers' extensive C++ experience taught them that
multiple inheritance just wasn't worth the headache.
5)Why java is not a 100% oops?
Many people say this because Java uses
primitive types such as int, char, double. But then all the rest are objects.
Confusing question..
6)What is a resource bundle?
In its simplest form, a resource bundle is represented by a text file
containing keys and a text value for each key.
7)What
is transient variable?
Transient variable can't be serialize. For example if a variable is declared as
transient in a Serializable class and the class is written to an ObjectStream,
the value of the variable can't be written to the stream instead when the class
is retrieved from the ObjectStream the value of the variable becomes
null.
8)What
is Collection API?
The Collection API is a set of classes and interfaces that support operation on
collections of objects. These classes and interfaces are more flexible, more
powerful, and more regular than the vectors, arrays, and hashtables if
effectively replaces. Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap. Example of interfaces: Collection, Set, List and Map.
9)Is
Iterator a Class or Interface? What is its use?
Iterator is an interface which is used to step through the elements of a
Collection.
10)What
is similarities/difference between an Abstract class and Interface?
Differences are as follows:
Interfaces provide a form of multiple inheritance. A class can extend only
one other class.
Interfaces are limited to public methods and constants with no
implementation. Abstract classes can have a partial implementation,
protected parts, static methods, etc.
A Class may implement several interfaces. But in case of abstract class, a
class may extend only one abstract class.
Interfaces are slow as it requires extra indirection to to find
corresponding method in in the actual class. Abstract classes are
fast.
Similarities:
Neither Abstract classes or Interface can be instantiated.