Top 60 Java Interview Questions and Answers


Java is a high-level programming language used to build various apps by developers for laptops, game consoles, mobile phones, and other devices. In other words, it is a strongly-typed, general purpose, and object-oriented coding language. 

The following Java Interview Questions and Answers are compiled for you to make you familiar with the types of questions you may encounter in your interview. These questions are useful for basic to medium and advanced level interviews.

Most Frequently Asked Java Interview Questions

What is meant by Java programming?

Ans: Java is a high-level object-oriented coding language developed & released by Sun Microsystems in 1995. Java runs on multiple platforms like Windows, Mac OS, etc.

Name the platforms supported by Java Programming.

Ans: Java language supports multiple platforms like Windows, Mac OS, and the other editions of UNIX/Linux such as HP-Unix, Redhat Linux, Ubuntu, CentOS, and so on.

Why is Java programming Architectural Neutral?

Ans: Java’s compiler produces an object file format that is architecture-neutral. It makes the arranged code to be executable on several processors including a Java runtime system.

Become a Gerrit Certified With HKR. Gerrit Training now

How does Java enable High Performance?

Ans: The language uses a Just-In-Time (JIT) compiler which is an integral part of JVM to enable high and faster performance. JIT compiler turns Java bytecode to speed up the Java application. This is a type of program that includes certain instructions that must be converted into orders that can be sent directly to the processor.

What do mean by a Local Variable?

Ans: Local variables in Java are defined within the body including methods, constructors, or blocks. You can declare and initialize the variable within the same method only. And it will be removed after completion of that method.

Name the five top features of Java programming.

Ans: The top features of Java include Object Oriented, Robust, Portable, Platform Independent, and Multi-threaded.

Define why Java language is considered dynamic?

Ans: Java programming language is considered more dynamic as it is designed to adapt to an evolving environment. Java programs can move a large amount of run-time data. This data is useful to verify and work out access to objects on run-time. Further, it supports dynamic loading of various classes which are loaded on-demand basis.

Name the two Java IDEs.

Ans: Two popular Java IDEs are- Netbeans and Eclipse.

Mention a few Java keywords.

Ans: There are some useful Java keywords such as import, super, finally, for, abstract, byte, case, etc.

: What is meant by an Instance Variable?

Ans: Instance variables are non-static variables defined inside a class but outside any method or block. Moreover, these variables are instantiated or expressed when the class is loaded.

. Define Java Virtual Machine (JVM) and how to consider it as Java’s platform-independent feature?

Ans: When we compile a Java program, it is not compiled into the platform-specific system but rather into platform-independent byte code. This byte code is allocated over the web and converted by JVM which is a specification and a runtime instance, on whatever platform it runs actually.

: Define what is the class?

Ans: A class in a Java program is a basic building block through which individual objects are built. Moreover, a class can include certain fields and methods that explain the object’s (variable’s) behavior.

Wish to make a career in the world of Java? Start with HKR’S  Java Training ! 

: Mention the types of variables that a class can contain.

Ans: A class in Java can contain Local variables, instance variables, and class variables.

: Describe what is an Object?

Ans: An object is a runtime entity and a member of the Java class. It consists of a state and behavior such as a chair, bike, etc. Moreover, the object includes three different features such as state, behavior, and identity. Further, an object can be physical or logical in nature.

: Define a Class Variable.

Ans: These variables are declared within a class, but outside of any method using the static keyword in the Java program.

: What is a Constructor in a Java program?

Ans: A Constructor is a block of several codes which is equal to the method. It is called when a new object or instance of a class is created. Every class in Java consists of a constructor. If we do not clearly define or write a constructor for a class the java compiler then creates a default constructor for the same class.

: What are the three different steps useful to create an Object for a class?

Ans: The creation of an object includes- declaration, instantiation, and initialization.

: Mention the default value of byte data type in the Java program.

Ans: The default byte datatype value in a Java program is 0 (zero).

: Define Singleton class.

Ans: A Singleton class in Java is a design pattern that makes sure that a class should contain only a single object. It controls the number to one but allows the flexibility to build more objects if the condition alters. Moreover, it is useful when a single instance of a class needs to control the actions in the entire execution.

: Name the default values of float and double datatype.

Ans: The following are the default values of float and double data types:- for float the value is 0.0f and for double data type the value is 0.0d.

Java Certification Training

  • Master Your Craft
  • Lifetime LMS & Faculty Access
  • 24/7 online expert support
  • Real-world & Project Based Learning

: What is the use of byte data type?

Ans: A byte data type is useful to save space in large arrays. This is mainly used in the place of integers. But a byte is 4 times smaller than an integer in reality.

: Define the Static variable.

Ans: The static variables have another name: Class variables that are declared with the static keyword in a class but outside of a method, or a block.

: What is an Access Modifier in Java?

Ans: Access modifiers are useful to set access levels for classes, methods, variables, and constructors. Further, these modifiers mention the accessibility or scope of a method or a field.

: How do you define a Protected Access Modifier?

Ans: The protected modifiers’ access level is within and outside the package through the child class in Java. In case, if you don’t build the child class, you can access it from outside the package.

: Why is a String class in Java considered immutable?

Ans: The String class in Java is immutable or cannot be altered as once you create a String object it cannot be changed. Also, you can easily share this between many threads, and is viewed as important for multithreaded programming.

: What is the reason that a StringBuffer is called mutable?

Ans: The String class is viewed as immutable as once created, it cannot be altered. If there is a need to make a lot of changes to Strings of characters then StringBuffer is highly useful.

: Define Exception.

Ans: An exception is a problem or error that occurs at the time of execution of a program. These errors/exceptions are grabbed by handlers located along the thread’s method citation stack.

: Explain Inheritance in Java.

Ans: Inheritance is a type of process where one object obtains another object’s properties. By using inheritance, the data is made viable in a hierarchical order.

: What is meant by Abstraction?

Ans: The term refers to the capability to make a class abstract in object-oriented programming. It minimizes the complexity and helps to improve the system’s maintainability.

: Define Encapsulation.

Ans: It is the technique to integrate code and data into a single unit. Here, we can build a completely encapsulated Java class by ensuring all the data members of the class are private. Java Bean is an example of this type of Java class.

: What is a Local variable and the instance variable?

Ans: A local variable is a variable that can be defined inside a method and the scope of that variable is accessible only to its method but not outside the method. An instance variable is a variable which is defined inside a class and outside a method and the scope of that variable is accessible all throughout the class.

: Why pointers not used in Java?

Ans: Pointers increases the complexity of a program and becomes unsafe. Hence the java code is designed with simplicity by avoiding the pointers that will become contradicting. JVM is responsible for implicit memory allocation, thus in order to avoid direct access to memory by the user,  pointers are discouraged in Java.

: Explain the features in Java.

Ans: The features are.

1. The concepts of OOPs that include

  • Object-oriented
  • Inheritance
  • Encapsulation
  • Polymorphism
  • Abstraction

2. Platform Independent – A single program runs on different platforms without any modifications.

3. High Performance – JIT (Just in Time compiler) enables high performance which converts the bytecode into machine language and then JVM starts the execution.

4. Multi-threading – Thread is a flow of execution. JVM creates a thread that is called the main thread. A user can able to create multiple threads by extending the thread class or by implementing the Runnable interface.

: What are the main concepts of OOPs in Java?

Ans: The concepts of OOPs are:

Inheritance: It is a process by which one class acquires the properties of another class.

Encapsulation: It is a mechanism of wrapping the code and data as a single unit.

Abstraction: It is a methodology for hiding the implementation details and proving only the functionality to the users. 

Polymorphism: It is the ability of a variable, function or object to take multiple forms.

: Explain the difference between Public and Private access specifiers.

Difference between Public and Private access specifiers is as follows:

Public access specifier:

When we declare any variable, class or method with ‘public’, then they can be accessed anywhere. There is no scope restriction for public access modifiers. They can be accessed within the same package and also in other packages.

public class Main {

  public String mailid = "anu.123@gmail.com";

  public int age = 26;

}

class Second {

  public static void main(String[] args) {

    Main myObj = new Main(); 

    System.out.println("mailid: " + myObj.mailid);

    System.out.println("Age: " + myObj.age);

  }

}

Output:

mailid: anu.123@gmail.com

Age: 26

Private access specifier:

When we declare a method or variable as ‘private’, we cannot access them outside that class. It can be accessed only within that declared class.

public class Main {

  private String name = "Anu";

  private String surname = "Wills";

  private int age = 26;

  

  public static void main(String[] args) {

    Main myObj = new Main();

    System.out.println("Name: " + myObj.name + " " + myObj.surname);

    System.out.println("Age: " + myObj.age);

  }

}

Output:

Name: Anu Wills

Age: 26

. Explain the difference between Default and Protected access specifiers.

Difference between Default and Protected access specifiers is as follows:

Default access specifier: 

When an access specifier is not specified for a class, data member or method, then by default it will have a ‘default’ access modifier. They can be accessible within the same package. It cannot be accessed in other packages.

class Person {

  String mailid = "anu.123@gmail.com";

  int age = 26;

  public static void main(String[] args) {

    Person myObj = new Person();

    System.out.println("mailid: " + myObj.mailid);

    System.out.println("Age: " + myObj.age);

  }

}

Output:

mailid: anu.123@gmail.com

Age: 26

Protected access specifier:  Whenever we specify a data member or a method with ‘protected’, then they can be accessed within the same class and same package. Classes or interfaces cannot be declared as protected in Java.

class Person {

 protected String name = "Anu";

  protected int age = 26;

}

class Student extends Person {

  private int graduatedin = 2016;

  public static void main(String[] args) {

    Student myObj = new Student();

    System.out.println("Name: " + myObj.name);

    System.out.println("Age: " + myObj.age);

    System.out.println("Graduation Year: " + myObj.graduatedin);

  }

}

Output:
Name: Anu

Age: 26

Graduation Year: 2016

: What is the difference between the break and continue?

Ans: 

Break:

  • It can be used in switch and loop statements such as for, while, do-while.
  • The moment the break is executed it will terminate the switch or loop statements.
  • It immediately terminates the innermost enclosing loop or switch statements.

Example:

for (int i = 0; i < 10; i++)

{

if (i == 5)

{

break;

}

System.out.println(i);

}

Continue: 

  • It can be used only in loops statements.
  • It will not terminate the loop but it causes the loop to jump to the next iteration.
  • A continue within a loop nested with a switch will cause the next loop iteration to execute

Example:

for (int i = 0; i < 10; i++)

{

if(i == 5)

{

continue;

}

System.out.println(i);

}

: What is the final keyword in Java?

Ans: The final keyword is used as a non-access modifier. A final variable is used in different contexts of a class, method and a variable.

  • Final variable: Once if any variable is assigned with a final keyword than that value of that variable cannot be modified and remains unchanging. If in case the final variable is assigned without any value than by using only the class constructor a value can be assigned to it.
  • Final method: When the method is declared as final then it cannot be overridden by the inheriting class.
  • Final class: When a class is declared as a final then it cannot be extended by any sub-class but it can able to extend the other class.

: What is Constructor?

Ans: 

  • A constructor is a method which has the same name as that of a class.
  • When a new object is created in a class than the constructor is invoked by that corresponding class.
  • If a user doesn’t create a constructor implicitly than a default constructor is created.
  • A constructor can be overloaded.
  • If a user creates a parameterized constructor than that user should create another constructor without any parameters explicitly.

: What is the difference between methods and constructors in Java?

Ans: 

Methods:

  • Methods are used to represent the behaviour of an object.
  • Should have the return type.
  • Methods must be invoked explicitly.
  • The compiler doesn’t provide any default method.
  • Method name may be or may not be the same as a class name.

Constructors:

  • Constructors are used in initializing the state of an object.
  • The constructor method will not have any return type.
  • The methods are invoked implicitly.
  • The compiler provides a default constructor when a class doesn’t contain any.
  • The method name of a constructor will be the same as a class name.

: What is the difference between Abstract class and Interface?

Ans: 

Abstract class:

  • Abstract classes have a default constructor that is called when a concrete subclass is instantiated.
  • Contains both Abstract and Non-abstract methods.
  • A class that extends the abstract class doesn’t need the implementation of all methods, only abstract methods are implemented in the concrete sub-class.
  • Abstract class contains instance variables.

Interface: 

  • The interfaces have no constructors and couldn’t be instantiated.
  • Only the abstract methods alone must be declared.
  • The classes which implement the interface should provide the implementation for all methods.
  • Interfaces contain only constants.

: Can you override a private or static method in java?

Ans: No. You cannot override private or static methods. If a similar method is created with the same return type and the same method arguments in child class then it hides the superclass method which is also called as method hiding. Similarly, the private method is not overridable in sub-class which is not accessible there. You can create another private method with the same name in the child class as in this example.

Example:

class Base_class {

private static void display() {

System.out.println("Static or class method from Base class");

}

public void print() {

System.out.println("Non-static or instance method from Base class");

}

class Derived_class extends Base_class {

private static void display() {

System.out.println("Static or class method from Derived class");

}

public void print() {

System.out.println("Non-static or instance method from Derived class");

}

public class test {

public static void main(String args[])

{

Base obj= new Derived_class();

obj.display();

obj.print();

}

}

: What is the difference between Error and Exception?

Ans: An error is an unrecoverable condition that occurs at runtime such as “OutofMemory” error.  These JVM errors cannot be repaired at runtime. Even though such kind of errors is caught in the catch block, the application execution will be halted and becomes unrecoverable. 

The exceptions are the conditions which applied for tracking the bad input to human error while executing a program. For example “FileNotFoundException” is an exception which is thrown to handle if the specified file doesn’t exist. 

: What is the difference between Serialization and Deserialization in Java?

Ans:

Serialization:

  • The Serialization is a process of converting the objects into a byte stream.
  • An object is serialized by writing it an ObjectOutputStream.

Deserialization:

  • The Deserialization is an exact opposite of what a Serialization will process where we can get the objects back from the byte stream.
  • An object is deserialized by reading it from an ObjectInputStream.

: When to use Runnable interface and Thread class in Java?

Ans: When a class is needed for extending some other classes other than a thread then it is recommended to implement the runnable interface because java can extend only one class. If there is no need for extending any class than at the time it is recommended to extend the properties of a thread class.

HKR Trainings Logo

Subscribe to our YouTube channel to get new updates..!

: Explain the difference between HashMap and HashTable.

Ans: 

HashMap:

  • The methods in HashMap are not synchronized.
  • HashMap will not have thread-safety.
  • The iterator will be used for iterating the values.
  • Allows one null key and multiple null values.
  • Performs high compare to the HashTable.

HashTable:

  • The key methods in HashTable are synchronized.
  • HashTable will have thread-safety.
  • The enumerator will be used for iterating the values.
  • Doesn’t allow anything which is null.
  • Performs low compare to the HashMap.

: What is the difference between HashSet and Treeset?

Ans: 

HashSet:

  • The elements which are inserted into HashSet will be in random order.
  • HashSet can store null objects.
  • Performance is fast.

TreeSet:

  • The elements in a TreeSet will be maintained in sorted order.
  • TreeSet cannot store null objects.
  • Performance is slow.

: What are Collections in java?

Ans: Collections are the framework which is designed to store and manipulate the objects. The collections perform the following operations.

  • Searching
  • Sorting
  • Insertion
    Deletion
  • Manipulation.

A group of objects are known as collections. All the collection classes and interfaces are available in the util package.

: What is the difference between Ordered and Sorted in collections?

Ans: Ordered collections are values which are stored in a collection that is based on the values that are added to the collection. These values can be iterated from the collection in a specific order.

The sorted collection mechanism is applied internally or externally such that the group of objects sorted in a particular collection is based on the properties of objects.

: What is the difference between Array list and Vector in Java?

Ans: 

ArrayList:

  • An Array List is not synchronized.
  • It performs fast as it’s non-synchronised.
  • The size of an array increases by 50% when an element is inserted into an Array List.
  • Array List will not define the size of increment.
  • Array List uses Iterator only for traversing.

Vector:

  • A Vector is synchronized.
  • It performs slow as it’s thread-safe.
  • By default, vector doubles the size of an array.
  • Vector will define the size of increment.
  • Vector uses both Enumerator and Iterator for traversing.

: What is the difference between Array and ArrayList?

Ans: 

Array:

  • Arrays will not contain the values of different data types.
  • Size of an Array is defined during declaration.
  • To add data index is specified in Arrays.
  • Arrays are not parameterized type.
  • Arrays contain primitive data types as well as objects.

ArrayList:

  • ArrayList contains the values of different data types.
  • Size of ArrayList changes dynamically.
  • There is no need for specifying indexes in ArrayList.
  • ArrayLists are parameterized type. 
  • Primitive data types are not allowed in ArrayList but contain only objects.

: What is the difference between Get and Post methods in Servlet?

Ans:

Get method:

  • Limited amount of data can be sent because the data is sent in the header section.
  • The data is exposed to a URL bar and so it is not secured.
  • It can be bookmarked.
  • It is Idempotent.
  • It is used more efficiently than a Post method.

Post method:

  • A large amount of data can be sent because the data is sent in the body section.
  • The data is secured since it is not exposed to a URL bar. 
  • It cannot be bookmarked.
  • It is not Idempotent.
  • It is used with less efficiency. 

: What are the different methods of session management in Servlets?

Ans: Session is a state of a conversation between client and server and consists of multiple requests and responses. As HTTP and Web Server are stateless, the session maintains the unique information as session-id that is passed between client and server in every request and response. The methods of session management in servlets are:

  1. User Authentication
  2. HTML Hidden Field
  3. Cookies
  4. URL Rewriting
  5. Session Management API

: What is a JDBC Driver?

Ans: JDBC is a software component which enables the application to interact with the database. There are mainly four types of JDBC drivers.

  1. JDBC-ODBC bridge driver
  2. Native-API driver (partially java driver)
  3. Network Protocol driver (fully java driver)
  4. Thin driver (fully java driver)

: What are the JDBC statements?

Ans: These are the statements which are used to send SQL commands to the database and also retrieve the data from the database. The methods like execute(), executeUpdate() and executeQuery() are provided by JDBC to interact with the database.

JDBC supports three types of statements.

  1. Statement: It is a general statement which is used to access the database and execute static SQL query at runtime.
  2. PreparedStatement: It is used in providing the input parameters to the query during the execution.
  3. CallableStatement: It is used for accessing the database stored procedures and helps in accepting runtime parameters.

: What are the lifecycle methods for a JSP?

Ans: There are three lifecycle methods in JSP.

  • public void jspInit() – It is invoked only once which is same as that of init() method used in servlet.
  • public void _jspService(ServletRequest request, ServletResponse response) throws ServletException, IOException – It is invoked at each request which is same as that of service() method used in servlet.
  • public void jspDestroy() – It is invoked only once which is same as that of destroy() method used in servlet.

. How is JSP better than a Servlet Technology?

Ans: JSP is a technology of the server’s side programming with simple content generation. JSP’s are document-centric while Servlets are programs. A JSP page contains the fragments of java programming code which executes and instantiates Java classes. However, they occur inside an HTML template file. It provides the framework for the development of a Web Application.

. What is Synchronization?

Ans: Synchronization is about handling only one thread for accessing a block of code at a time. While multiple threads access the block of code then there are chances for inaccurate results, in the end, to avoid this the synchronization is provided for the sensitive block of code. The keyword “synchronized” means that a thread requires a key to access the synchronized code.

It locks as per object. Each Java object has a lock which has only one key. A thread can access a synchronized method only if the thread can get a key to the objects to lock. Towards this, the “Synchronization” keyword will be used.

Example:

public class ExampleThread implements Runnable{

 public static void main (String[] args){

 Thread t = new Thread ();

 t.start ();

 }

 public void run(){

 synchronized(object){

 {

 }

}

. Name the different modules of Spring framework.

Ans: The modules of spring framework include.

  • Spring Context – for dependency injection.
  • Spring Web Module – for creating web applications.
  • Spring AOP – for aspect-oriented programming.
  • Spring ORM – for ORM tools support such as Hibernate
  • Spring DAO – for database operations using DAO pattern
  • Spring JDBC – for JDBC and DataSource support.
  • Spring MVC – Model-View-Controller implementation for creating web applications, web services etc.

. Explain the role of DispatcherServlet and ContextLoaderListner.

Ans: Dispatcher Servlet is a front controller in Spring MVC application which loads the spring bean configuration file and initializes all beans which are configured. By enabling the annotations it allows scanning the packages to configure any bean annotated with @Component, @Controller, @Repository or @Service annotations.

ContextLoaderListner is a listener that can start and shut the “WebApplicationContext” in spring root. Its main function ties the lifecycle of Application Context to the lifecycle of the ServletContext and automating the creation of ApplicationContext.

Java Certification Training

Weekday / Weekend Batches

About Author

author-image

As a content writer at HKR trainings, I deliver content on various technologies. I hold my graduation degree in Information technology. I am passionate about helping people understand technology-related content through my easily digestible content. My writings include Data Science, Machine Learning, Artificial Intelligence, Python, Salesforce, Servicenow and etc.

Upcoming Java Certification Training Online classes

Batch starts on
28th Jun 2026
Mon – Fri (18 Days)
Weekend
Timings – 10:30 AM IST
Batch starts on
2nd Jul 2026
Mon & Tue (5 Days)
Weekday
Timings – 08:30 AM IST
Batch starts on
6th Jul 2026
Mon & Tue (5 Days)
Weekday
Timings – 08:30 AM IST



Source link

Leave a Reply

Subscribe to Our Newsletter

Get our latest articles delivered straight to your inbox. No spam, we promise.

Recent Reviews


Step forward in your career with J2EE Development. J2EE is an open-source platform to develop, deploy and manage web-enabled, multi-tier, server-centric, and component-based enterprise applications. As a result of its robustness and security, organizations prefer to work in a Java environment. The demand for Java professionals is very high. So, we are here to help you in clearing your J2EE interview easily. Our experts have gathered and prepared a list of frequently asked questions. So why late? Lets set started with J2EE interview questions.

Let’s get started!

Most Frequently Asked J2EE Interview Questions 

J2EE basic-level Interview Questions:

What is J2EE?

J2EE refers to Java 2 Enterprise Edition. It is used to develop and deploy web-based multi-tier enterprise applications. The J2EE platform combines a range of services, protocols, and application programming interfaces. The J2EE platform includes the capabilities needed to deliver a comprehensive, secure, stable, and fast Java platform at the enterprise level.

Become a Java Certified professional by learning this HKR JavaTraining

What are the components available in J2EE applications?

The components of the J2EE applications consist of:

  • Web-tier components
  • Business-tier components
  • Client-tier components
  • Enterprise Information System software

What do you understand by J2EE client types?

Following are J2EE client types:

  • Application clients
  • Applets
  • Wireless clients, according to Mobile Information Device Profile (MIDP).
  • Java Web Start-enabled clients, through the Java Web, Start technology.

What is ORM?

ORM refers to Object-Relational mapping. Objects in a Java class that are mapped to tables in a relational database utilizing the metadata which describes the mapping of objects to the database. It acts by converting data from one representation to the other.

What is JSF?

JSF refers to JavaServer Faces. It is a user interface that designs a framework for Java web applications. It provides a set of user interface components that can be reused, a standard for web applications. JSF uses the MVC design pattern. It stores the form data on the server automatically and specifies the date of the form when it is displayed on the client side.

What is the servlet?

Servlets is one of the server-side components which delivers a powerful mechanism for server-side program development. Servlets is a platform-independent server. Servlets are designed with different protocols in mind; The most common one is HTTP protocols. The servlets uses the classes of java packages javax.servlet.http.HttpSession, javax.servlet.http.HttpServletRequest, javax.servlet, javax.servlet.http.HttpServletResponse. All the servlets are required to implement the Servlet interface that defines the methods of the lifecycle.

Java Certification Training

  • Master Your Craft
  • Lifetime LMS & Faculty Access
  • 24/7 online expert support
  • Real-world & Project Based Learning

 

What is a web component?

Java Server Pages technology and Java Servlet components are the web components. Servlet is a component that receives the request sends responses dynamically. JSP pages run like servlets but provide a more natural way to create static content.

What is Hibernate?

Hibernate is an object-relational mapping tool. In hibernate, HQL is used rather than SQL, which saves developers from spending more time on writing native SQL. It has a great association, polymorphism, inheritance, collection, and compositions. This is a great way to persist in the database using Java objects. Hibernate enables you the ability to express queries based on Java criteria.

What is Hashtable?

Hashtable is the same as HashMap, with the exception that Hashtable is synchronized. Hashtable is a synchronized objects cluster in which duplicate values and null values are not permitted.

Java Certification Training

  • Master Your Craft
  • Lifetime LMS & Faculty Access
  • 24/7 online expert support
  • Real-world & Project Based Learning

) What is a J2EE container?

The interface between the low-level platform and a component with specific features which supports the component is referred to as a container. The application server will maintain control and deliver relevant services through a framework or an interface calls as a container.

J2EE intermediate-level Interview Questions:

) What are structs?

The Struts framework is an MVC architecture that designs large-scale applications. It consists of JSP, Java Servlets, Custom tags, and messages. According to the published standards and the proven design templates, struts help you create a scalable development environment for your application.

) Explain ActionErrors, ActionForm and ActionMapping.

ActionError: ActionErrors is an object that wraps up all the available validation errors. If errors are not found, returns either null or an ActionErrors object with no error message recorded. The default implementation tries to switch to HTTP. Maintaining request parameter mapping and request and return all validation errors if the validation fails; a null or an empty set.

ActionForm: It is a Java bean which brings together one or multiple ActionMappings. A java bean becomes FormBean when extending org.apache.struts.action.ActionForm. The ActionForm object is populated automatically on the server-side with the data entered by the customer from the user interface. ActionForm keeps the session state for the web app.

ActionMapping: When mapping actions, we mention the action class for a specific URL, i.e., the path and various target views, i.e., redirect to which the response to the request will be sent. The ActionMapping is the information which the ActionServlet is aware of regarding mapping a specific request to an instance in a specific Action class. The mapping is passed to the method execute() in the Action class, allowing direct access to that information.

) Explain about MVC on structs?

MVC refers to Model View Controller.

Model: In many applications, the model represents the system’s internal state in the form of one or more JavaBeans. 

View: The view is usually built with JavaServer Pages technology. The controller concentrates on receiving customer requests and generating the next stage of the user interface to a suitable View component. 

Controller: The Controller’s main component in the framework is an ActionServlet class servlet. The definition of an ActionMappings set sets up this servlet.

) What are the differences between .ear, .jar, and .war files.

.jar files: These files have the .jar extension. The .jar files include accessories files such as property files, libraries, and resources.

.war files: These files have the .war extension. The .war file includes HTML,  javascript, JSP, and other files required for web application development.

.ear files: The .ear file includes the application’s EJB modules.

) What is the difference between Save() and Saveorupdate()?

Save(): The purpose of this method in Hibernate is to store an object in the database. It will insert an entry if there is a record, otherwise, it does not.

Saveorupdate():  The purpose of this method in Hibernate is to update the objects with the identifier. If the identifiers are not present, this method will call save(). If the identifier is available, then it will call the update method.

) What is the difference between the load and get method?

load() cannot find the object in the database or cache, an exception is issued, and the load() method will never return null. If the object is not found, the get() method will return null. The load() method can return a proxy in place of a persistent instance, get() does not return a proxy

) What is Spring?

Spring is an open-source lightweight framework for developing enterprise applications which solves the complexity of developing enterprise applications also provides a consistent framework for developing J2EE applications that is primarily based on the inversion of control or dependency injection design model.

) What is authorization?

Authorization is the process of determining access to a method or resource. It is based on determining the security role of the primary for an authentication request. A security role may be described as a logical grouping of users that is defined by the person assembling the application. A deployer matches the security roles for the security identities. Security identities can be groups or principles in the operational environment.

) What is an authorization constraint?

An authorization rule that determines who is allowed to access the collection of web resources is called an authorization constraint.

HKR Trainings Logo

Subscribe to our YouTube channel to get new updates..!

) What is EJB?

EJB refers to Enterprise Java Beans. This is the server-side component that runs in the EJB container and wraps the business logic of the enterprise application.

J2EE Interview Questions for Experienced:

) What is a connector?

The connector is a standard container extension mechanism that delivers connectivity to enterprise information systems. It is unique to an enterprise information system and includes application development tools and a resource adapter for the connectivity of enterprise information systems. The resource adapter is connected to a container by supporting system-level contracts that are defined in the Connector architecture.

) Explain JMS, JTA, and JNDI.

JTA: JTA stands for Java Transaction API. Its purpose is to coordinate and manage transactions across the company’s information system.

JNDI: JNDI stands for Java Naming Directory Interface. This is used to access directory services information.

JMS: JMS stands for Java Messaging Service. Its purpose is to receive and send messages using messaging systems.

) What are EDI and EAI?

EDI: EDI stands for Electronic Data Interchange. It is used to exchange data via the value-added network (VAN) that acts as a means of transmission. The installation of EDI is costly and needs customization by exchanging clients. EDI is also based on X12 standards for exchanging documents.

EAI: EAI stands for Enterprise Application Integration. This makes one or multiple applications into one application and needs that data to be transferred to the suitable system at the correct time. For example, during the integration of accounts and sales systems, it is required for sales to send a sales order for accounting for generating an invoice. In addition, accounting has to send a sales invoice to update the data for the sales professionals. This system automatically manages the transaction through the application and removes human mistakes.

) Explain about J2EE tiers.

J2EE includes the following tier:

Client tier: It stands for the browser from which the server gets the requests. In this tier, the interfaces used are the java application, the HTML browser, a non-java application, or an applet.

Middle Tier: This includes an integration tier, a presentation tier, and a business tier. Within the integration tier, the database objects are created. The UI is created at the presentation tier with the help of JSP. The business logic is written at the business tier with the help of EJB.

Backend: It consists of the Enterprise Information System that is used for storing data.

) What is DCOM?

DCOM refers to Distributed Component Object Model. It employs the Object Remote Procedure Call protocol to handle remote objects. The Object Remote Procedure Call is based on Remote Procedure Call and interacts with the runtime services. DCOM supports more than one interface, and components can be built in different programming languages like C, Java, Visual Basics, etc. DCOM is largely used in the Windows platforms.

) What is JRMP?

JRMP refers to the Java Remote Method protocol. This is the way Remote Method Invocation passes java objects as arguments. As Java depends on the serialization of objects which bring together objects in streams, RMI depends on the JRMP protocol to transfer the objects from one Java Virtual Machine to other.

) What is a Secure Socket Layer?

The technology used for communication between the Web browser and the Web server is referred to as the Secure Socket Layer. Specifically, SSL is a protocol which describes the way algorithms should be used for encryption. The technology creates an encrypted link between the two parties, and this link makes it possible to secure the transmission of sensitive information like credit or debit card information, login credentials, and social security numbers.

) What do you mean by id URL?

URL refers to Uniform Resource Locator. It is the textual reference standard for writing arbitrary information on the World Wide Web. The URL is generally structured as – 

protocol://host/local info

protocol – The protocol allows you to retrieve the object (example: HTTP, FTP)

host – The target host’s Internet name.

local info – A String is sent to the protocol handler on the remote host. In most of the cases, this is a filename with an extension.

) What is the JSP directive?

JSP is the process by which metadata information is provided to web containers regarding the JSP file. This metadata is used by the web container during the translation and compilation stages of the JSP lifecycle.

There are three different kinds of JSP directives:

  • Include directive
  • Page directive
  • Taglib directive

) Explain connection pooling?

Connection pooling is an easy concept that is popular for reusing existing connections. This means that if the object connections are well defined and connected already, they may be reused each time there is a need rather than generating a new one.

) What is a J2EE Module?

It is a piece of software that is made up of one/more J2EE components for that similar container type and a deployment descriptor of that type. Into a J2EE application, modules may be assembled or deployed quickly. 

) What is included in the application client module?

An application module includes the class file and a client deployment descriptor. It will be packaged as a JAR file with the extension .jar.

) What is the web module made up of?

The Web module is made up of 

  • JSP files(Java Server pages) 
  • Graphics Interchange format(GIF) file
  • Hypertext Markup Language(HTML) file
  • Servlets class files 
  • Web deployment descriptor

These files will be packaged as JAR files with the extension .war(Web Archive)

) What is the Enterprise Java Bean module made up of?

The Enterprise Java Bean module is made up of the class files for enterprise beans and the EJB deployment descriptor. These files will be packaged as JAR files with the extension .jar.

) What is the resource adapter module made up of?

The resource adaptor module is made up of Java interfaces, native libraries, classes, resource adaptor deployment description and other documentation. These files will be packaged as JAR files with the extension .rar(resource adapter archive).

) What is meant by an Applet?

It is a component of  J2EE that is commonly executed on the web browser. This  can be executed on a wide range of other devices or applications that accept the applet programming model.

) What do you mean by an applet container?

“Applet container” refers to a container that supports the applet programming model.

) What is meant by a thin Client?

A thin client is a lightweight application interface that will not allow functions like complex business rules execution, database  queries or connection to legacy applications.

) What is meant by deployment descriptor?

The Deployment descriptor is according to Extensible MarkUp Language(XML) that has a .xml extension. It can be used to define the deployment options for a component. J2EE applications and modules have their own deployment descriptors.

) What do you mean by a web container in J2EE?

A web container in J2EE refers to an interface between the low level platform and a component with defined functionality which is intended  to support the functionality.

) What will be the file extension that is used for the Hibernate configuration file and hibernate configuration file?

The file name for the hibernate mapping will be written like filename.hbm.xml.

The file name for the hibernate configuration will be written like filename.hbm.xml.

) How should a Hibernate mapping file in the hibernate configuration file be added?

You can add it quickly using the following code:

 

) What are the core components of a Multi-tier architecture?

Following are the core components of the Multi tier architecture:

  • Presentation Tier: The presentation is displayed using the front-end component included in this tier.
  • Resource Layer: The database is accessed through the back-end component included in this tier.
  • Business Layer: The business logic of the system is provided by the component included in this tier.

) What do you mean by a backing bean?

Backing bean refers to a Javabeans component that relates to JavaServer Pages and contains JavaServer Faces components. Backing bean outlines the characteristics for the page components as well as methods that process them.

This processing will consist of validation, event handling, processing related to navigation.

) What do you mean by build file?

An XML file with one or more asant targets is referred to as a build file. A target is a list of assignments that a user hopes to complete. A user can specify which target should be executed when asant is started. If no target exists, the  project’s default target is carried out.

Java Certification Training

Weekday / Weekend Batches

) What do you mean by CDATA?

A CDATA is an XML tag that is predefined for character data that denotes “don’t interpret these characters.” It is comparable to parsed character data (PCDATA), in which the usual XML syntax is followed. CDATA sections will be used to display XML syntax examples.

) What is the difference between JDK and JIT?

A cross-platform software development environment called JDK (Java Development Kit) provides diverse collections of libraries and tools needed to develop applets and  Java programmes. It even comprises JRE, which offers tools and libraries that accept the bytecode execution. JDK is required for creating and executing Java programmes. In contrast, JIT stands for Just In Time Compiler, a module that exists inside the JVM (i.e., inside JRE). In order to reduce the time for compilation, and improving speed, JIT compilers are used to compile some of the portions of bytecode that carry out similarly to machine code at the same time.

) What are the primary interfaces of the Hibernate framework?

  • Sessionfactory interface
  • Transaction interface
  • Session Interface
  • Query and Criteria Interface
  • Configuration interface

) How do PATH and CLASSPATH differ from each other in relation to J2EE?

  • The two most important environmental variables utilised by Java platforms are PATH and CLASSPATH.
  • PATH refers to the JDK binaries or native libraries such as java.exe. while, the CLASSPATH variable refers to the Java binaries, like JAR files that include bytecode.
  • Regardless of whether Java is installed on the system or not, PATH is a system-level variable. Where as JVM uses CLASSPATH, which is entirely Java-specific, to load the classes needed by running Java programmes.

) What are the phases of servlet life cycle?

Following are the phases of Servlet lifecycle:

  • Classloading phase: Servlet’s class file (*.class) will be loaded by web container.
  • Instantiation phase: The servlet gets instantiated by calling the default no-arg constructor.
  • Initialize phase: init() method will be called only once in the servlet lifetime. Servlet configuration will be assigned to the servlet.  
  • Request Handling phase: The servlet spends most of its time in this phase. Services to various requests will be provided by calling service().
  • Removal phase: before the Servlet destruction, the destroy() function will be called.  The garbage collection will be carried out later.

Conclusion:

All the above are some of the frequently asked J2EE interview questions gathered by our J2EE Experts. We hope you found these questions helpful. Learning these questions will help you in clearing your interview. If you are searching for any other questions related to J2EE, feel free to comment. We would revert with the answer.

About Author

author-image

As a content writer at HKR trainings, I deliver content on various technologies. I hold my graduation degree in Information technology. I am passionate about helping people understand technology-related content through my easily digestible content. My writings include Data Science, Machine Learning, Artificial Intelligence, Python, Salesforce, Servicenow and etc.

Upcoming Java Certification Training Online classes

Batch starts on
28th Jun 2026
Mon – Fri (18 Days)
Weekend
Timings – 10:30 AM IST
Batch starts on
2nd Jul 2026
Mon & Tue (5 Days)
Weekday
Timings – 08:30 AM IST
Batch starts on
6th Jul 2026
Mon & Tue (5 Days)
Weekday
Timings – 08:30 AM IST



Source link