Java Interview Questions and Answers

Java Interview Questions and Answers


1. What is the most important feature of Java?

Java is a platform independent language.

2. What do you mean by platform independence?

Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (Linux,Solaris,etc).

3. What is a JVM?

JVM is Java Virtual Machine which is a run time environment for the compiled java class files.

4. Are JVM’s platform independent?

JVM’s are not platform independent. JVM’s are platform specific run time implementation provided by the vendor.

5. What is the difference between a JDK and a JVM?

JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.

6. What is a pointer and does Java support pointers?

Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn’t support the usage of pointers.

7. What is the difference between final, finally and finalize() in Java?

final – A final variable acts as a constant, a final class is immutable and a final method cannot be ovrriden while doing inheritance.

finally – handles exception. The finally block is optional and provides a mechanism to clean up regardless of what happens within the try block (except System.exit(0) call). Use the finally block to close files or to release other system resources like database connections, statements etc.

finalize() – method belongs to Object class. The method that is invoked while doing the garbage collection of the object. It could be used for allowing it to clean up its state. Good use cases will be to free connection pools , de allocate resources etc.

8. What is difference between Hash Map and Hash Table ?

Both collections implements Map. Both collections store value as key-value pairs. The key differences between the two are

Hash map is not synchronized in nature but hash table is.
Another difference is that iterator in the Hash Map is fail-safe while the enumerator for the Hash table isn’t.
Fail-safe -if the Hash table is structurally modified at any time after the iterator is created, in any way except through the iterator’s own remove method, the iterator will throw a Concurrent Modification Exception?
Hash Map permits null values and only one null key, while Hash table doesn’t allow key or value as null.

9. What is difference between abstract class and interface ?

A class is called abstract when it contains at least one abstract method. It can also contain n numbers of concrete method.Interface can contain only abstract( non implemented) methods.
The abstract class can have public,private,protect or default variables and also constants. In interface the variable is by default public final. In nutshell the interface does not have any variables it only has constants.
A class can extend only one abstract class but a class can implement multiple interfaces.
If an interface is implemented its compulsory to implement all of its methods but if an abstract class is extended its not compulsory to implement all methods.
The issue with an interface is, if you want to add a new feature (method) in its contract, then you MUST implement those method in all of the classes which implement that interface. However, in the case of an abstract class, the method can be simply implemented in the abstract class and the same can be called by its subclass.

10. What is the difference between equals() and == ?

== operator is used to compare the references of the objects.
public bollean equals(Object o) is the method provided by the Object class. The default implementation uses == operator to compare two objects. But since the method can be overriden like for String class. equals() method can be used to compare the values of two objects.

11. Can you override a private or static method in Java?

you can not override a private or static method in Java, if you create a similar method with same return type and same method arguments in child class then it will hide the super class method, this is known as method hiding. Similarly, 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.

12. Does Java support multiple inheritances?

Java does support multiple inheritances of Type by allowing an interface to extend other interfaces, what Java doesn’t support is multiple inheritances of implementation.
Core Java interview questions:
What are the important features of Java 8 release?
What do you mean by platform independence of Java?
What is JVM and is it platform independent?
What is the difference between JDK and JVM?
What is the difference between JVM and JRE?
Which class is the superclass of all classes?
Why Java doesn’t support multiple inheritance?
Why Java is not pure Object Oriented language?
What is difference between path and classpath variables?
What is the importance of main method in Java?
What is overloading and overriding in java?
Can we overload main method?
Can we have multiple public classes in a java source file?
What is Java Package and which package is imported by default?
What are access modifiers?
What is final keyword?
What is static keyword?
What is finally and finalize in java?
Can we declare a class as static?
What is static import?
What is try-with-resources in java?
What is multi-catch block in java?
What is static block?
What is an interface?
What is an abstract class?
What is the difference between abstract class and interface?
Can an interface implement or extend another interface?
What is Marker interface?
What are Wrapper classes?
What is Enum in Java?
What is Java Annotations?
What is Java Reflection API? Why it’s so important to have?
What is composition in java?
What is the benefit of Composition over Inheritance?
How to sort a collection of custom Objects in Java?
What is inner class in java?
What is anonymous inner class?
What is Class loader in Java?
What are different types of class loaders?
What is ternary operator in java?
What does super keyword do?
What is break and continue statement?
What is this keyword?
What is default constructor?
Can we have try without catch block?
What is Garbage Collection?
What is Serialization and Deserialization?
How to run a JAR file through command prompt?
What is the use of System class?
What is instance of keyword?
Can we use String with switch case?
Java is Pass by Value or Pass by Reference?
What is difference between Heap and Stack Memory?
Java Compiler is stored in JDK, JRE or JVM?
What will be the output of following programs?


I am happy to be here in Gencor which provided me with technical professional and skillful aspects of auto cad, thank you.

Kush Prakash - West Bengal University of Technology

I completed CCNA traning and certification preparation before appearing for ccna global examination 200-120 from gencor.

Amit Kumar - Lovely Professional University

The trainer has good knowledge of the subject.

Saurabh Kumar Suman - Shaheed Bhagat Singh State Technical Campus, Ferozepur

This institute is the best institute in web designing. Trainer sir is good in knowledge and best trained and  provided web designing knowledge to me.

Abhishek Kumar - Guru Gobind Singh Polytechnic College, Talwandi Sabo, (Bhathinda) Punjab

The trainer is good, so I think everything is good. 

Rabindra Kumar Yadav - Samalkha Group of Institutions

The Gencor classes is good for getting the knowledge. The trainer has good communication with students. I completed CAD training in Mechanical from here.

Akash Kumar - Jawaharlal Nehru Technological University, Hyderabad

I gained a lot here in the Gencor and I believe that it will help to enhance my knowledge and personalty further in my life.

Prem Kumar - BIT Sindri

Institute Completed my training as per  Syllabus provided on time. 

Akshay Kumar - The Institution of Civil Engineers, Delhi

Gencor institute is the best institute which completed my course on Civil CAD on time.

Amit Kumar - Reg No - 001/15348 - Civil CAD

The overall system of teaching is favorable and good as I expected and helped a lot in increasing my knowledge.

Sunny Kumar

I appreciate the course by the institute and efforts put in to complete it within the prescribed time limits.

Mohammad Asad Eqbal

The trainer has good knowledge of autocad, so I am happy to complete the training of AutoCAD from here.

Hemant Raj - Reg No.: 001/15307 - Civil CAD

The Trainer is nice one. He teaches well. The institute is good. I have faith on the Institute.

Vikash Kr Mandal - Reg No.: 001/15308 - Mechanical CAD

The institute is very good one and object oriented, focused on setting  up career for engineering students. The trainer is having enough knowledge to guide students.Teaching method is very much appreciated and interactive.

Indranil Mazumdar - Reg No.: 001/15312 - Civil CAD

All class I did here was very good. Faculty provide every detail about syllabus & Course. I am thankful of you.

Sumank Saurav - Reg No.: 001/15321 - Mechanical CAD

Trainer is the best guide for autocad and institute is also best for autocad

Vikash Kumar Sharma - Reg No.: 001/15322 - Mechanical CAD

This is professional institute , It has given the full knowledge of the subject, It is best best providing knowledge.

Dinu Kumar - Reg No.: 001/15328 - AutoCAD ME

This institute given me knowledge about Autocad and I appreciate that . I must recommend other to learn CAD from here.  

Abhishek Kr Singh (Reg No . 001/15332)

I am Gracy Pradhan , completed my  Linux training on RHCE from GenCor. Training is fully practical based and full syllabus coverage prescribed RED Hat Inc. . This training is surely going to provide me help in placement by college.

Gracy Pradhan - Ram Krishna Dharmarth Foundation University

I completed my Autocad Civil Training with Project and certification from GenCor InfoEdge – India, Trainer is The best in providing training .

Sonu Kumar

Best Training for telecommunication on Cisco CCNA. I got placed in 3i infotech Patna.

Scan the code