JAVA Interview
JAVA Interview
Because of Primitive data types namely: Boolean, byte, char, int, float, double, long, short
we have wrapper classes which actually “wrap” the primitive data type into an object of that class.
Q) Why pointers are not used in Java? Mostly asked in java interview questions and Answers in MNC
to check your basic knowledge of java and programming languages and logics behind them.
Because :
2) Increases the complexity of the program and since Java is known for its simplicity of code, adding
the concept of pointers will be contradicting.
3) Since JVM is responsible for implicit memory allocation, thus in order to avoid direct access to
memory by the user, pointers are discouraged in Java
1) String pool requires string to be immutable otherwise shared reference can be changed from
anywhere.
2) security because string is shared on different area like file system, networking connection,
database connection , having immutable string allows you to be secure and safe because no one can
change reference of string once it gets created.
A Marker interface can be defined as the interface having no data member and member functions. In
simpler terms, an empty interface is called the Marker interface.
As I have told you in previous videos : method overriding is a good topic to ask trick questions in Java.
2) you cannot override a private method in sub class because it's not accessible there, what you do is
create another private method with the same name in the child class.
3) For static methods if you create a similar method with same return type and same method
arguments in child class then it will hide the superclass method, this is known as method hiding.
Q) Does “finally” always execute in Java?
“System.exit()” function
system crash
Called by the garbage collector on an object when garbagecollection determines that there are no
more references to the object.
public int hashCode(): Returns a hash code value for the object.
Q) What is singleton class in Java and how can we make a class singleton?