Best Java Interview Questions And Answers

Preparing for the interview is of ultimate importance for both hiring managers and candidates. Hiring managers need to prepare advanced Java interview questions in order to fully evaluate the technical knowledge of a candidate. On the other hand, candidates need to also repeat the basic information prior to the interview in order to fully showcase their potential. 

To simplify the life for both parties we decided to prepare a list of Java interview questions and answers that could fully uncover the skills level of a candidate.

Junior Java Developer Interview Questions

01

What is Java platform independence?

Java platform independence means that this programming language can run on different platforms or OS without any changes, which becomes possible with bytecode. The original code of Java is converted into bytecode to adapt it for a specific machine. Bytecode is transmitted to Java Virtual Machine (or simply JYM) that is located in the RAM of any OS. JYM detects the bytecodes and transforms them into the native machine code.

02

What is an RDBMS?

RDBMS stands for Relational Data Base Management System, which is based on the relational model of the database system. It includes numerous tables that have their own primary key and are used to store the data using columns and rows. Typical examples of the RDBMS are systems like SQL, MS SQL Server, IBM DB2, ORACLE, My-SQL, Microsoft Access, and others.

03

What are the basic access specifiers for Java classes?

Access specifiers (also known as access modifiers) are the specific keywords used before a class name to determine the access scope. They’re mostly used for defining the visibility of classes, variables, interfaces, constructors, methods, etc. In Java, there are 4 types of access modifiers: 

  • Private - variables that can be accessed only from the same class they belong to;
  • Public - methods and variables that can be accessed by any other classes in the project;
  • Protected - variables that can be accessed within the same set of classes and subclasses of any other packages;
  • Default - methods and variables that can be accessed only from the same package (not from the native one).

04

What are loops in Java and what are the 3 types of loops?

Java loop repeats a sequence of instructions until a particular condition is met. There are three types of loops in Java: for, while, and do-while.

05

What is the difference between fail-fast and fail-safe iterators?

Fail-fast iterators perform directly on the collection, which means they fail as soon as the definition of the collection has been changed during iteration. 

Unlike the previous ones, fail-safe iterators function directly on a collection’s copy, thus they do not throw any exception if the collection has been changed during iteration.

06

What is the MVC design pattern?

MVC (also known as Model-View-Controller) is an app design tool that divides the application into 3 parts: 

  • Model - stands for the app data
  • View - data representation on a screen
  • Controller - operates the list of processes and responds to the actions, that sometimes can change the model

07

What is Core Java?

Core Java is a general term used by Sun Microsystems to define a basic edition of Java (J2SE), used for the other editions created. Core Java is mainly used for building desktop and server-based apps, mostly because of its benefits as the fast and a highly-secure scripting language.

08

What are the 4 types of Java platforms?

Being a particular environment for the Java programming language, there are 4 different platform types for Java:

  • Java SE or Java Standard Edition
  • Java EE or Java Enterprise Edition
  • Java ME or Java Micro Edition
  • Java FX

09

What is the difference between transient and volatile variables in Java?

The main difference between transient vs volatile variables is that transient variables are utilized to prevent serialization while volatile variables are utilized to provide alternative synchronization in Java. 

10

What’s the difference between a ClassNotFoundException and NoClassDefFoundError?

ClassNotFoundException is an exception that occurs when the class file for a requested class can’t be found on the classpath.

NoClassDefFoundError is an error that occurs when the class file existed at runtime but can’t be turned into a Class definition for some reason. 

Mid Java Developer Interview Questions

01

What’s the difference between ‘sleep ( )’ and ‘wait ( )’ methods in Java?

‘sleep ( )’ is a blocking operation that keeps either hold on the monitor or the lock on the shared object for a set amount of milliseconds and is commonly used for polling or certain results tracking at a set time. 

‘wait ( )’ pauses the thread for the set amount of time or enables it after receiving approval from the other thread without locking the shared object or holding on to the monitor. 

02

When ‘finally’ block is executed in Java?

The ‘finally’ block is mostly applied for putting the important codes like the clean-up code, for example when the file or connection needs closing. The ‘finally’ block is executed when an exception is thrown from a ‘try’ block that does not have a ‘catch’ block. It is executed even in cases when an exception is thrown or propagated to the calling code block.

03

What is the Java ClassLoader?

ClassLoader is the "deepest" mechanism in Java, which allows you to intervene practically into the core of the Java Virtual Machine (JVM) while remaining within the framework of Java programming. ClassLoader provides loading the classes from the local file system, remote file system, or web. 

There are 3 types of ClassLoader in Java:

  • Bootstrap ClassLoader: Responsible for loading standard Java API files rt.jar from folder
  • Extensions ClassLoader: Manages loading jar files from the folder. 
  • System Class Loader: Operates loading jar files from the specific path in the CLASSPATH environment

04

Can you use == on enum?

Yes, as the enums represent a set of constants like unchangeable variables or final variables, which ensure that you’ll have only one case of the constants used in the JVM. They have close instance controls which allow using == for the instances comparison. Furthermore, the ‘==’ operator provides compile-time and run-time safety.

05

What is composition in Java?

Composition in Java stands for code reusing. Basically, the composition is used as a part-of or ‘has-a’ relationship that helps to ensure the code reusability in the program. In other words, that’s a technique that assists in describing the reference between two or more classes. The composition between two entities is marked as done when an object contains a composed object, and the last one can exist within another entity.

06

What is a static import?

A static import is a method used in the Java development process, which allows various members (like fields and methods), scoped within their container classes as public static, to be employed in Java code without indicating the exact class in which the field has been defined. This method enhances the code readability and gets direct access to the static members.

07

What is method overloading in Java?

Method overloading in Java stands for a feature that enables a class to have more than one method with the same name if their argument lists are different. It has some similar points to the constructor overloading. There are 3 different ways in which you can overload a method:

  • by number of parameters
  • by the data type of parameters
  • by the sequence of the data type of parameters

08

What is method overriding in Java?

Method overriding in Java stands for a feature that allows a subclass or child class to complete a specific implementation of a method that has been done by one of its superclasses or parent classes. One of the benefits of this method is that it assists in defining a specific class type behavior so that a subclass can use a parent class method based on its type.

09

What does the Final Keyword in Java mean?

The final keyword defines the entity which can be assigned only once and can’t be modified in the future. Once it’s been set, it can’t change its value anymore, for instance in the functions. The entity defined by the final keyword can be a variable, a class, a method, etc.

10

What are OOPs concepts in Java?

The OOPs concepts stand for Object-Oriented Programming in Java and cover the following elements: class, object, encapsulation, inheritance, polymorphism, and abstraction. All these assist in ensuring the application’s reusability, security, and flexibility, and allows developers to create the working methods and variables, then reuse them all or part of them without compromising the system security.

Senior Java Developer Interview Questions

01

Does Java have a static class?

You can’t build the advanced class static but you can enhance its performance in the next steps:

  • #1 Declare the class final to prevent the class extension and make it static
  • #2 Set up the private constructor
  • #3 Configure the members and functions of the class static as well

02

What does the GetMethod of HashMap do in Java?

HashMap is constructed using the hash table data structure. Basically, it employs the ‘hashCode ( )’ method to compute hash code to find the bucket location on the underlying array and the ‘equals ( )’ method to detect the object in the same bucket in case of a collision.

03

What is the Difference between JDK and JRE?

Java Runtime Environment (also known as JRE) stands for a Java Virtual Machine (or JVM), the programming environment where the Java programs are being executed. It also covers the browser plugins for the advanced applet execution.

Java Development Kit (also known as JDK) is a much more complex, full-stack Software Development Kit for Java programming language which includes the JRE, various compilers, and a list of tools (for instance, JavaDoc or Java Debugger). JDK is targeted at developing, compiling, and executing different Java apps.

04

What is the meaning of Spring beans?

The Spring beans are the objects that form the keystone of your application and are controlled by the Spring IoC container. A so-called “bean” is an object that is instantiated, assembled, and managed in any possible option by a Spring IoC container. The Spring beans are formed with the configuration metadata that is supplied to the container. 

For instance, you can always meet their definitions in the XML form: 

<bean/>

05

What is the Application Context definition?

In general, the application context has a similar definition to the bean factory. It loads bean definitions, wires beans together, and dispenses them if required. Also, it provides a generic way to load file resources, specific events to the beans defined as listeners, as well as means for resolving text messages using various languages.

06

What is JDBC?

JDBC (also known as Java Database Connectivity) stands for the Java API, responsible for the connection to a database, queries, and commands issuing as well as receiving the result sets processed by the database. Basically, it enables developers to switch between the databases without having to underlie the specific features of a particular database.

07

What is Controller in the Spring framework?

The controllers of the Spring MVC framework enable access to the app behavior programmers typically define via the service interface. They analyze the user’s query and convert it into the specific model user can perceive by the view component. The controllers in Spring are implemented only in the abstract way, thus allowing developers to create a wide range of different controllers.

08

Which Swing methods are thread-safe?

‘Repaint ( )’, ‘revalidate ( )’ and ‘invalidate ( )’ methods are the only ones that can be safely used in Java Swing. They do not need to execute in the AWT thread (the specific event dispatch thread). And vice versa, the other Java Swing methods can easily affect the state of a component and must execute in the event dispatch thread.

09

What is the purpose of system.gc() and runtime.gc() methods?

Both methods serve as a hint to the JVM to start a garbage collection. However, it’s up to the JVM to start the collection right away or later.

10

What is the function of the Continuous Integration (CI) server?

CI is a DevOps software development practice that is used to merge the code changes made by different developers in the central repository in order to run automated builds and tests. CI should build code multiple times a day in order to timely detect any issue and identify its cause.

home-05

Hiring Java developers?

We have the people you are looking for!

Get in touch
Looking for vetted Java developers to join your team?

There are hundreds of battle-proven software development experts in our Talent Network.

Are you a Java developer looking for amazing projects? Join as a Talent