This post is basically to deliver you best and top core  java question which are basically asked during recruitment by the various company. Hope freshers find it useful and it will be helpful for them.core-java

The reader is encouraged to try the programming questions himself/herself before checking the answers.

Java Interview Question-1. What is output of following program? byte[] a = {1,2,3};
byte [] b = (byte[]) a.clone(); print(a==b)
Answer: False
Java Interview Question-2. Can you have a virtual function in java?
Answer: Yes, all non-static functions are virtual
Java Interview Question-3. Can a lock be acquired on a class?
Answer: Yes, by using synchronized static method
Java Interview Question-4. What pattern will you use to improve the following code if
(object instanceof a) dosomethiga if (object instanceof b) dosomethigb
Answer: We can use visitor pattern

Java Interview Question-5. How to provide secure web services?
Answer: We can use HTTPS protocol

Java Interview Question-6. What is wsdl used for?
Answer: wsdl is used to describe the structure of client request and server response

Java Interview Question-7. Is java call by value or call by reference
Answer: Java uses reference for object, value for primitive

Java Interview Question-8. What is the output of the below code and explain?
public static void main(String[] args) {
Employee e = new Employee();
int i = 99;
testO(e, i);
System.out.println(e.getEname()); System.out.println(i); 99
public static void testO(Employee e, int i) {
i = 100;
Answer: AAAA (Call by reference), 99(Call by value)
Java Interview Question-9. What is the difference between Web Server and Application
Answer: Web Server can host web applications only. Application server can host both web
and non-web applications supporting protocols other than HTTP e.g. RMI, RPC, etc.


Java Interview Question-10. Write a sample code to print the below pattern where n is
number of rows.
* *
* * *
* * * *
for(int i=1; i<=n; i++) {
for(j=0; j<i;j++) {

Java Interview Question-11. Write the code for above pattern using java recursion
Answer: public static void printStar(int n) {
if(n <= 1) { System.out.print(“*”);}
else {
for(int i=0;i< n;i++) {

Java Interview Question-12. What is transient variable?
Answer: Transient variable can’t be serialized.

Java Interview Question-13. Is Iterator a Class or Interface? What is its use?
Answer: Iterator is an interface to iterate through the elements of a collection.

Java Interview Question-14. What is similarities/difference between an Abstract class and
Answer: Differences are as following:
• A class can implement as many interfaces as it wants but it can extend only one
abstract class
• Interfaces can define public methods and constants only. Abstract class can have
protected, static, etc. methods
• We cannot instantiate either abstract class or interface

Java Interview Question-15. Describe the principles of OOPS.
Answer: Encapsulation, Inheritance and Polymorphism are 3 main principles of OOPS
Encapsulation provides a way to hide data and methods.
Inheritance provides a way to reuse existing parent classes by its child classes.
Polymorphism provides a way to overload and override existing methods

Java Interview Question-16. What all access specifiers are available in Java?
Answer: Following access specifiers are available in Java
• Public
• Protected
• Private
• Default


Leave a Reply