Java interview questions and Answers

Last updated on Jan 29, 2022
  • Share
Java interview questions

Java is a computing platform as well as a programming language. You can download it for free. An object-oriented language, Java is a fast, secure and easily extendible language. Java is said to be more dynamic than C or C++ language because of its adaptable design. Unlike many other programming languages, Java is a platform-independent and Architecture-neutral language. Our massive collection of java interview questions will definitely help you find a great job.

Most Frequently Asked Java interview questions

Here in this article, we will be listing frequently asked Java interview questions and Answers with the belief that they will be helpful for you to gain higher marks. Also, to let you know that this article has been written under the guidance of industry professionals and covered all the current competencies.

Q31. What is Interface in Java? Explain
Answer

Similar to class, an interface in Java is a reference type. An interface contains abstract methods, constants, static methods, default methods and nested types.

A class implements an interface and inherits the abstract methods of the same interface. Writing an interface is like writing a class.

Q32. What is Abstract class? Explain
Answer

It is a class that is declared with an abstract keyword. An abstract class can have both abstract and non-abstract methods and needs to be extended. In this class, the method must be implemented and cannot be instantiated.

Q33. What is the difference between HashMap and HashTable in Java?
Answer
  Hashmap Hashtable
1. Nonsynchronized Synchronized
2. Not thread safe Thread-safe
3. Cannot be shared between threads without synchronization code Can be shared with many threads
4. Allows null key and multiple null values Does not allow null key or value
Q34. What is the difference between HashSet and TreeSet in Java?
Answer
  HashSet TreeSet
1. Offers constant time cost Offers log time cost
2. Does not maintain the order of elements By default sorts elements in ascending order.
3. Implemented using a hash table Implemented using Binary Search Tree
Q35. What is Collections in Java?
Answer

A Collection in Java is a group of individual objects that are represented as a single unit. The Collection Framework in Java defines classes and interfaces that represent a group of objects as a single unit.

The two main root interfaces are Collection interface and Map interface.

Q36. Why Java is a platform independent? Explain
Answer

By being platform independent, we mean that the java source code can be run on all OS. The presence of a machine independent code called Byte Code, which once compiled, can be run on any platform, makes Java platform independent.

The compiler feature in Java converts or translates the high-level language into a common format understood by all the machines. The only requirement is the availability of JVM.

Q37. What is the differences between Heap and Stack Memory in Java? Explain
Answer
  Heap space Stack Memory
1. Used to allocate memory Used for execution of the thread
2. Instance variables are created Local variables are created
3. Contains Objects and reference variables Contains methods and local variables
Q38. Explain the difference between abstract classes and interfaces in Java?
Answer
  Interface Abstract class
1. Can only have abstract methods Can have abstract, non-abstract methods
2. Variables are by default final. May contain non-final variables.
3. Only has static and final variables Can have non-final, final, non-static and static variables
Q39. What is servlet? Explain
Answer

This is a Java programming class that runs on Java-enabled server or application server and extends the capabilities of servers that host applications.

A servlet possesses all the features of Java such as platform independence, portability, security and database connectivity.

Q40. What is JIT compiler in Java?
Answer

JIT compiler is a component of JRE that improves the performance of applications.

JIT compiler improve the performance of JVM by compiling bytecode into machine code at runtime. Choosing the right compiler is one of the first and biggest decisions to be made when you are running a Java application.

Development History of Java Programming Language

Sun Microsystems released its first version in 1995 as a core component of its platform. Majority of candidates are asked this information in advanced java interview questions.

Latest Version: The latest version is Java SE 11 (18.9 LTS), which was released in September 2018. This information is critical if you are preparing for Java interview questions.

Advantages of Java
  • Simple and easy to learn
  • Robust and multithreaded
  • Enables high performance
  • Follows WORA (write once, run anywhere) approach
Reviewed and verified by Best Interview Question
Best Interview Question

With our 10+ experience in PHP, MySQL, React, Python & more our technical consulting firm has received the privilege of working with top projects, 100 and still counting. Our team of 25+ is skilled in...