Top 80 Core Java Interview Questions and Answers 2019 NareshIT
Top 80 Core Java Interview Questions and Answers 2019 NareshIT
New keyword is useful for providing memory for non-static data, it is individual, where as static keyword is useful for providing memory static data by
default by JVM, it is common for all.
a = 200;
}
No.
Once we initialize the nal variable, we can’t reinitialize the variable again either with same value or di erent value.
Constructor is useful for initialize the non-static variables meanwhile of object creation.
Preparer is useful for providing default values for static variables in static loading phase.
Initializer is useful for replacing default values with original values of static variables in static initialization phase.
Mean while of creating object, if we want to copy the data from existed object to new creating object within the di erent memory location then we
should use copy constructor.
If we want perform di erent operations in di erent object creations mode then we should prefer constructor overloading.
This () method is useful for making communication between one constructor to another constructor within the same class.
Super () method is useful for making communication between one constructor to another constructor between super and sub classes.
12.What is singleton?
Answer:
To make our logic/functionalities to common for all we should use non-static block, whereas constructor is useful for providing di erent
functionalities for di erent object.
No, we are unable to use, the reason are by default non-static nal reference variables.
If we are unable to create object for a class, but still if we want to execute some logic and if we are not giving to subclasses to change our logic then
we should prefer static methods.
Yes, we can write multiple default methods and java.lang.Object class methods also (abstract format only).
The following things are very much mandatory for calling any method. Those are
Access modi er
Modi er (static/non-static)
Return type
Method name
Parameters(number of, type of , place of parameters)
Throws keyword(Exceptions)
27.What is encapsulation?
Answer: The process of providing security for our data, if the end user is authorized then we should provides permissions to security data is called
encapsuaiton.
Answer: The logic which is given by the java software or already existed, if that logic is not suitable for project requirement then we should write
same method with di erent logic within the super and sub classes is called method overriding.
34.How many memories are given by the JVM meanwhile of subclass object creation?
Answer: JVM will provide only one memory for subclass but super class non-static data will come stored in sub class memory.
If we are not aware about type of value and memory but still if we want hold then we should prefer upcasting.
The process of executing the method by JVM at runtime, which is binds by the compiler at compilation time, is called dynamic polymorphism.
The process of executing the method from subclass by JVM at runtime, which is not binds by the compiler at compilation time, is called dynamic
polymorphism.
40.What is immutable object and examples?
Answer: The process of unable to change the state of the object is called immutable object.
In the rst statement, JVM only creates one object in String constant pool.
In the second statement, JVM will create two objects, one is in heap area and another one is in String constant pool area.
50.What is package?
Answer: The process of encapsulating the similar type of classes, interfaces and enum in a single unit is called package.
printStackTrace()
toString()
getMessage()
58.What is serialization?
Answer: The process of sending data from java application to le in the form of entire object is called serialization.
59.What is externalization?
Answer: The process of sending the data from java application to le in the form of some part of object is called externalization.
Catch block always executing meanwhile of exception raise in the try block.
Try block always throwing exception objects, which are directly or indirectly subclass of Throwable class.
So catch block parameter type required both Object class functionalities and Throwable class functionalities.
If we are writing
catch(Object o){
Parameter ‘o’ only have Object class functionalities but does not Throwable functionalities.
That’s why we can’t write Object type parameter in catch block.
Syatem.exit(0)
63.What is cloning?
Answer: The process of creating new object with the support of existed object data is called cloning.
66.What is collection?
Answer: It is one well de ne mechanism, to group homogeneous, heterogeneous, duplicate and unique objects into a single container is called
collection.
67.What is the di erence between Vector and ArrayList?
Answer: By default vector is synchronized class, so its object never allows to multiple threads to processing, whereas ArrayList will allows to multiple
thread to processing its object. The load factor of Vector is current capacity*2, whereas ArrayList load factor is current capacity * 3/2.
76.Can we use peek() and pop() on empty stack and what is the di erence between them?
Answer: Pop() will give top most element with deletion from Stack whereas peek() will give top most element without deletion from Stack.
Both the methods will throw exception like java.util.EmptyStackException if elements are not existed.
import java.util.Stack;
class A{
public static void main(String[] ss){
Stack s = new Stack();
//System.out.println(s.pop());
System.out.println(s.peek());
}
}
First Name *
Last Name *
Email *
Phone *