Core Java Interview Questions for Beginners, Junior, and Senior Developers

Java Interview Questions
Created by CakeResume

Developed by James Gosling at Sun Microsystem in 1995, Java is a class-based, object-oriented programming language that aims to minimize implementation dependencies. Java was designed as a general-purpose, high-level language that can be used to develop.

  • Desktop Application – Platform independence is one of the reasons why the language is used for many desktop applications.
  • Mobile Application – Java is a robust and secure language that is widely used for mobile applications, especially in Android development.
  • Web and Application Servers – Since Java can be run on various operating systems, it makes an ultimate candidate for application servers.
  • Embedded Systems – Java’s high performance and portability are ideal for the low-level programming in embedded systems.

And the list goes on.

Java technology is ubiquitous. So much so that it is still one of the most in-demand languages in the industry today despite the other emerging languages like Python or JavaScript. Just like any other technical interviews, preparing for Java interview questions is essential for those who are trying to break into the field or looking for better opportunities.

Basic Java Interview Questions

For the many developers that are preparing for basic jJava interview questions, we have collected some common questions that candidates might be asked during the technical interviews and example answers. But before we move on to the Java interview questions, there are a few tips that candidates can pay attention to.

As a beginner or a junior developer, the candidate might be asked questions that deal with the fundamentals of Java during a technical interviews, such as:

  • Object-Oriented Programming
  • Platform Independent
  • Architectural Neutral
  • Multithreaded
  • Dynamic

In addition to the fundamentals, there might be some Java programming questions to test your technical literacy. Lastly, candidates might be expected to answer some technical Java interview questions with respect to computer science topics, such as local and global variables, and the difference between stack and heap memories.

Java Interview Questions for the Freshers

Here are ten basic Java interview questions and answers that can give you some basic ideas and direction for your preparation for technical interviews and Java programming questions:

1. Why is Java a platform-independent language?

Compilers like javac will convert the source code into bytecode with extension, .class, and then it will be executed by the Java launcher tool with an instance of Java virtual machine (JVM). Since JVM is available across almost all major OS systems, the language is then considered platform independent.

2. Is Java a pure object-oriented language? 

Although Java suffices certain properties of an object-oriented language, such as encapsulation, inheritance, polymorphism, and abstraction, the fact that Java still incorporate primitive data types like int, float, bool, char, etc., disqualifies the language of being a pure object-oriented language.

3. What is a class and what is an object?

A class is a blueprint or prototype from which individual objects are created. In a class you can find a set of objects that contains the state and behavior that the instance of such an object will follow.

4. Define what inheritance is in OOP.

The feature of inheritance allows one class to inherit state and behavior from another class. The dynamics within an inheritance consist of the two following elements:

a. Superclass – The parent class whose features can be inherited by an unlimited number of subclasses.
b. Subclass – The child subclass will inherit features from a superclass.

5. Can you briefly describe the difference between heap and stack memory in Java?

There are a few differences between the heap and stack memory in Java, in addition to the basic computer science concepts behind these two. Some of the differences include:

a. Access – In Java, stack memory cannot be accessed by other threads, while the objects stored in the heap are globally accessible.
b. Management – The stack frees memory in the last in first out manner (LIFO), while the heap management is determined by the generation associated with each object.
c. Size – The size of the stack memory is significantly less in comparison to the heap.

6. What is the difference between an instance variable and a local variable

A local variable exists in a method, constructor, or a block locally, whereas an instance is bound to the object itself.

7. What is the output of the following program?

class Question {

   public static void main (String args[]) {

   System.out.printIn(5*5 + “CakeResume”);



Ans: “25CakeResume”

8. What is the purpose of the static keyword? 

It is used to share the same variable or access of a given class for memory management. The keyword suggests that the method is accessible without instantiating the class.

9. What does JRE stand for in Java? And what is it?­

It stands for Java Runtime environment in which the bytecode is executed. It implements JVM and provides class libraries and other files for it at runtime.

10.  Is system.out.printIn(“CakeResume”) valid syntax? 

No, it is not, because Java is a case-sensitive language, and thus it is wrong to write the code, system, with a lowercase.

Core Java Interview Questions for the Experienced

For more seasoned developers, although you should be more experienced in areas such as data structure and algorithms, there are still fairly tough Java interview questions that you should prepare for. Therefore, we have collected fifteen core Java interview questions for experienced developers of different seniority.   

Java Interview Questions for 3 Years of Experience

For developers with 3 years of experience, your Java interview questions will most likely focus more on your understanding of the Java fundamentals such as concepts in OOP, namely, abstraction, encapsulation, polymorphism, and inheritance. In addition to that, there might be Java programming questions where you are expected to code if not to explain them.

1. What is the difference between checked and unchecked answers? 

Exception handling is an important concept and a common topic in Java interview questions, there are two distinct differences between the two:

a. It is mandatory to handle checked exceptions at compile-time and runtime for unchecked exceptions.
b. Unchecked exceptions are RuntimeException whereas checked exceptions are a direct subclass of exceptions

2. Can you reverse a string in Java by finishing the following code?  

class Question {

   public static void main (String[] args) {

     String str = “CakeResume”, istr=“”;

Char chr;

               // Your Answer

System.out.printIn(“Reversed String:  ”  + istr);




for (int i =0; i < str.length(); i++) {

chr = str.charAt(i);

istr = chr + istr;


3. Please briefly explain the difference between StringBuffer and String. 

A String is an immutable class while StringBuffer is a mutable one.

4. Can static methods be overridden in Java? 

The answer is no. Static methods cannot be overridden because static methods are only looked up statically at compile-time. Since overriding is related to run-time polymorphism, it is not possible to override a static method in a dynamic context which is runtime.

5. Can you name a few usages of this keyword? 

This is another core Java interview question that is commonly asked in a technical interview. Here are some reasons why this keyword might be used:

a. To refer to current class instance variables
b. To invoke the current class constructor
c. To return the current class instance

Java Interview Questions for 5 Years of Experience

As a developer at a more senior level, you should have some ideas on what kind of Java interview questions you might encounter. In addition to the fundamentals, there might be some more questions about design patterns. You must be cognizant of some involuted facts in Java, and the coding interview questions in Java will be more intricate as well.

1. Can you briefly describe the difference between HashMap and HashTable?

This Java interview question on the data structure is common to encounter during the interview.  Here are some main differences:

a. Hashtable is synchronized, thread-safe, and can be shared with multiple threads, while hashmap is non-synchronized, and can only be shared with multiple threads with proper synchronization code.
b. Hashtable does not allow any null key or value, while hashmap allows one null key and many null values.

2. What is busy spinning? 

Busy spinning is a wait strategy where a single thread waits for some condition that depends on some other thread sequentially, where the waiting thread will loop until the condition is met.

3. Can you name any design patterns? 

The concept of design pattern will be important for your preparation of Java interview questions. Therefore, we recommend you look into different design methods out there. Here are two of the common ones:

a. Singleton Pattern – A single global instance of an object is created by the user, so the instance is then provided with public access.
b. Factory Pattern – The pattern is used when there is a superclass with multiple subclasses.

4. Can you briefly state the purpose and the technique in the use of the code below? 

class Multithread implements Runnable {

public void run() {

try {

     System.out.printIn(“thrd” + Thread.currentThread().getId());


catch (Exception e) {





class Multithread {

   public static void main (String[] args) {

      int n = 3;

      for (int i = 0; i < n; i++) {

            Thread object = new Thread(new Multithread);





Ans: Multithreading using a runnable interface

5. Why should the object used as the key be immutable? 

The key should be immutable so that hashCode() method will always return the same value.

Java Interview Questions for 10 Years of Experience

With this level of seniority, you can expect your Java interview questions to emphasize the in-depth technicality of the language more; the interviewer might focus on the technologies that you have worked with or simply tricky questions.

1. Provide a reason as to why Java does not support multiple inheritances?

Granted, other languages like C++ do support multiple inheritances, while Java doesn’t as Java’s design simply avoids ambiguity and complexity in casting.

2. Why is a character array better than a string for storing passwords? 

If you store passwords as strings, such strings will always be present in the String pool for reusability. The longer they are stored in the memory, the higher the security risk will be. Since strings are immutable in Java, there will always be a copy of the string. On the other hand, character arrays can be set to blank or zero which reduces the risk of having the password stolen.

3. Provide a reason as to why operator overloading is not supported in Java. 

The implementation of such a design will compromise the efficiency of JVM and add a layer of complexity to the compiler, which will then result in less optimization.

4. What design pattern have you experienced before? 

The answer to this core Java interview question will directly speak to your experience and technical capacity. We recommend you study different design patterns before the interview if not actually practice with them. Here are some of our suggestions for your answer:

a. Decorator Pattern (Structural Pattern)
b. Abstract Factory (Creational Pattern)
c. Chain of Responsibility (Behavior Pattern)

5. Does a spring bean provide thread-safety? 

The Spring bean scope is a singleton, so it is not thread-safe by default. However, thread-safety can still be achieved by altering the scope for a specific request, prototype, or session.

With CakeResume, you can easily create a resume online, free download your resume in PDF, and utilize ATS-compliant templates to create a resume. Land your dream job, create your resume online (free download) now!

--- Originally written by Jun Mao ---

Resume Builder

Build your resume only in minutes!