Common J2EE Interview Questions & Answers For Freshers | ACTE
J2EE Interview Questions and Answers

Common J2EE Interview Questions & Answers For Freshers

Last updated on 04th Jul 2020, Blog, Interview Questions

About author

Guna (Sr Project Manager )

He is Possessing 11+ Years Of Experience in J2EE. His Passion lies in Developing Entrepreneurs & Activities. Also, Rendered his intelligence to the Enthusiastic JOB Seekers.

(5.0) | 15212 Ratings 2931

These J2EE Interview Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your interview for the subject of J2EE . As per my experience good interviewers hardly plan to ask any particular question during your interview, normally questions start with some basic concept of the subject and later they continue based on further discussion and what you answer.we are going to cover top 100 J2EE  Interview questions along with their detailed answers. We will be covering J2EE  scenario based interview questions, J2EE  interview questions for freshers as well as J2EE  interview questions and answers for experienced. 

1) What is J2EE?

Ans:

J2EE means Java 2 Enterprise Edition. The functionality of J2EE is developing multitier web-based applications. The J2EE platform consists of a set of services, application programming interfaces (APIs), and protocols.

2) What are the four components of J2EE application?

Ans:

  • Application clients components.
  • Servlet and JSP technology are web components.
  • Business components (JavaBeans).
  • Resource adapter components

3) What are types of J2EE clients?

Ans:

  • Applets
  • Application clients
  • Java Web Start-enabled clients, by Java Web Start technology.
  • Wireless clients, based on MIDP technology.

4) What is considered as a web component? 

Ans:

Java Servlet and Java Server Pages technology components are web components. Servlets are a Java programming language that dynamically receives requests and makes responses. JSP pages execute as servlets but allow a more natural approach to creating static content.

5) What is JSF?

Ans:

JavaServer Faces (JSF) is a user interface (UI) designing framework for Java web applications. JSF provides a set of reusable UI components, a standard for web applications. JSF is based on MVC design patterns. It automatically saves the form data to the server and populates the form date when displayed on the client side.

6) Define Hash table

Ans:

HashTable is just like Hash Map, Collection having a key(Unique), value pairs. Hashtable is a collection Synchronized object. It does not allow duplicate values or null values.

7) What is Hibernate?

Ans:

Hibernate is an open source object-relational mapping and query service. In hibernate we can write HQL instead of SQL which save developers to spend more time on writing the native SQL. Hibernate has a more powerful association, inheritance, polymorphism, composition, and collections. It is a beautiful approach for persisting into the database using the Java objects. Hibernate also allows you to express queries using Java-based criteria.

8 ) What is the limitation of hibernate?

Ans:

  •  Slower in executing the queries than queries are used directly.
  • Only query language support for composite keys.
  • No shared references to value types.

9) What are the advantages of hibernate?

Ans:

  •  Hibernate is portable i mean database independent, Vendor independence.
  •  Standard ORM also supports JPA
  •  Mapping of the Domain object to the relational database.
  •  Hibernate is better than plain JDBC.
  •  JPA provider in JPA based applications.

10) What is ORM?

Ans:

J2EE Interview Questions and Answers

ORM stands for Object-Relational mapping. The objects in a Java class are mapped into the tables of a relational database using the metadata that describes the mapping between the objects and the database. It works by transforming the data from one representation to another.

11) Difference between save and saveorupdate

Ans:

  • save() – This method in Hibernate is used to store an object in the database. It inserts an entry if the record doesn’t exist, otherwise not.
  • saveorupdate () -This method in the hibernate is used for updating the object using an identifier. If the identifier is missing this method calls save(). If the identifier exists, it will call the update method.

12) Difference between load and get method?

Ans:

  • load() can’t find the object from cache or database, an exception is thrown, and the load() method never returns null.
  • get() method returns null if the object can’t be found. The load() method may return a proxy instead of a real persistent instance get() never returns a proxy.

13) How to invoke a stored procedure in hibernate?

Ans:

{ ? = call thisISTheProcedure() }

14) What are the benefits of ORM?

Ans:

  • Productivity
  • Maintainability
  • Performance
  • Vendor independence

15) What are the Core interfaces of the Hibernate framework?

Ans:

  •  Session Interface
  • SessionFactory Interface
  • Configuration Interface
  • Transaction Interface
  • Query and Criteria Interface

16) What is the file extension used for hibernate mapping file?

Ans:

The name of the file should be like this: filename.hbm.xml

17) What is the file name of the hibernate configuration file?

Ans:

The name of the file should be like this: hibernate.cfg.xml

18) How Hibernate is database independent explained?

Ans:

Only changing the full property full database can be replaced.

  • <property name=”hibernate.dialect”>org.hibernate.dialect.Oracle9Dialect</property>

and 

  • <property name=”hibernate.connection.driver_class”>oracle.jdbc.driver.OracleDriver</property>

19) How to add Hibernate mapping file in hibernate configuration file?

Ans:

By <mapping resource=” filename.hbm.xml”/>

20) Define connection pooling?

Ans:

Connection pooling is a mechanism to reuse the connection which contains the number of already created object connections. So whenever it is necessary for an object, this mechanism is used to get objects without creating it.

    Subscribe For Free Demo

    21) What is the Hibernate proxy?

    Ans:

    An object proxy is just a way to avoid retrieving an object until you need it. Hibernate 2 does not proxy objects by default.

    22) What do you create a SessionFactory?

    Ans:

    • Configuration cfg = new Configuration();
    • cfg.addResource(“dir/hibernate.hbm.xml”);
    • cfg.setProperties( System.getProperties() );
    • SessionFactory sessions = cfg.buildSessionFactory();

    23)  What is HQL?

    Ans:

    HQL stands for Hibernate Query Language. Hibernate allows the user to express queries in its portable SQL extension, and this is called HQL. It also allows the user to express in native SQL.

    24) What are the Collection types in Hibernate?

    Ans:

    Set, List, Array, Map, Bag are collection type in Hibernate.

    25) What is a thin client?

    Ans:

    A thin client is a program interface to the application that does not have any operations like the query of databases, execute complex business rules, or connect to legacy applications.

    26) Differentiate between .ear,  .jar and .war files.

    Ans:

    • jar files: These files are with the .jar extension. The .jar files contain the libraries, resources and accessories files like property files.
    • war files: These files are with the .war extension. The .war file contains JSP, HTML, javascript and other files necessary for the development of web applications.
    • ear files: The .ear file contains the EJB modules of the application.

    27) What is the JSP tag?

    Ans:

    JSP tags can be divided into four different types.

    • Directives
    • Declarations
    • Scriplets
    • Expressions

    28) How to access web.xml init parameters from JSP page?

    Ans:

    For example, if you have:

    <context-param> <param-name>Id</param-name> <param-value>this is the value</param-value></context-param>

    You can access this parameter

    Id: <h:outputText value=”#{initParam[‘Id’]}”/>

    29) What are JSP Directives?

    Ans:

    • page Directives <%@page language=”java” %>
    • Directives: <%@ include file=”/header.jsp” %>
    • taglib Directives <%@ taglib uri=”tlds/taglib.tld” prefix=”html” %>

    30) What is the EAR file?

    Ans:

    An EAR file is a JAR file with an .ear extension. A J2EE application with all of its modules is delivered in an EAR file.

    Course Curriculum

    Enroll in J2EE Training to Build Your Skills & Advance Your Career

    • Instructor-led Sessions
    • Real-life Case Studies
    • Assignments
    Explore Curriculum

    31) What will happen when you compile and run the following code?

    • public class MyClass {
    • public static void main(String argv[]){
    • int array[]=new int[]{1,2,3};
    • System.out.println(array [1]);
    • }
    • }

    Ans:

    Compiled and shows output : 2

    32) What are Struts?

    Ans:

    Struts framework is a Model-View-Controller(MVC) architecture for designing large-scale applications. It is a combination of Java Servlets, JSP, Custom tags, and message. Struts help you to create an extensible development environment for your application, based on published standards and proven design patterns. Model in many applications represents the internal state of the system as a set of one or more JavaBeans.The View is most often constructed using JavaServer Pages (JSP) technology.The Controller is focused on receiving requests from the client and producing the next phase of the user interface to an appropriate View component. The primary component of the Controller in the framework is a servlet of class ActionServlet. This servlet is configured by defining a set of ActionMappings.

    33.What is ActionErrors?

    Ans:

    Ans: ActionErrors object that encapsulates any validation errors that have been found. If no errors are found, return null or an ActionErrors object with no recorded error messages.The default implementation attempts to forward to the HTTP version of this method. Holding request parameters  mapping and request  and returns set of validation errors, if validation failed; an empty set or null

    34) What is ActionForm?

    Ans:

    Ans: ActionForm is a Java bean that associates one or more ActionMappings. A java bean becomes FormBean when extending org.apache.struts.action.ActionForm class. ActionForm object is automatically populated on the server side which data has been entered by the client from UI. ActionForm maintains the session state for a web application.

    35) What is action mapping?

    Ans:

    Ans: In action mapping, we specify action class for particular URL ie path and different target view ie forwards on to which request response will be forwarded.The ActionMapping represents the information that the ActionServlet knows about the mapping of a particular request to an instance of a particular Action class.The mapping is passed to the execute() method of the Action class, enabling access to this information directly.

    36) What is the MVC on struts?

    Ans:

    • MVC stands Model-View-Controller.
    • Model: Models in many applications represent the internal state of the system as a set of one or more JavaBeans.
    • View: The View is most often constructed using JavaServer Pages (JSP) technology.
    • Controller: The Controller is focused on receiving requests from the client and producing the next phase of the user interface to an appropriate View component. The primary component of the Controller in the framework is a servlet of class ActionServlet. This servlet is configured by defining a set of ActionMappings.

    37) What are different modules in spring?

    Ans:

    There are seven core modules in spring

    • The Core container module
    • O/R mapping module (Object/Relational)
    • DAO module
    • Application context module
    • Aspect Oriented Programming
    • Web module
    • MVC module

    38) What Bean Factory, have you used XMLBean factory

    Ans:

    XmlBeanFactory is one of the implementations of bean Factory org.springframework.beans.factory.xml.XmlBeanFactory is used to create bean instances defined in our xml file.

    • BeanFactory factory = new XmlBeanFactory(new FileInputStream(“beans.xml”));

    Or

    • ClassPathResource resource = new ClassPathResource(“beans.xml”);
    • XmlBeanFactory factory = new XmlBeanFactory(resource);

    39) What is Spring?

    Ans:

    Spring is a lightweight open source framework for the development of enterprise application that resolves the complexity of enterprise application development is also providing a cohesive framework for J2EE application development which is primarily based on IOC (inversion of control) or DI (dependency injection) design pattern.

    40) What is the functionality of ActionServlet and RequestProcessor?

    Ans:

    • Receiving the HttpServletRequest
    • Populating JavaBean from the request parameters
    • Displaying response on the web page Issues
    • Content type issues handling
    • Provide extension points

    41) ActionServlet, RequestProcessor, and Action classes are the components of

    Ans:

    Controller

    42) What is the default scope in Spring?

    Ans:

    Singleton.

    43) What are the advantages of Spring usage?

    Ans:

    • Pojo based programming enables reuse of components.
    • Improve productivity and subsequently reduce development cost.
    • Dependency Injection can be used to improve testability.
    • Spring required enterprise services without a need for the expensive application server.
    • It reduces coupling in code and improves maintainability.

    44)What are the Benefits  Spring Framework?

    Ans:

    • Lightweight container
    • Spring can effectively organize your middle tier objects
    • Initialization of properties is easy. No need to read from a properties file
    • application code is much easier to unit test
    • Objects are created Lazily, Singleton – configuration
    • Spring’s configuration management services can be used in any architectural layer, in whatever runtime environment

    45) Lifecycle interfaces in spring?

    Ans:

    InitializingBean

    • <bean id=”expInitBean” init-method=”init”/>
    • public class ExpBean {
    • public void init() {
    • // do some initialization code
    • }
    • }

    OR

    • <bean id=” expInitBean “/>
    • public class ExpBean implements InitializingBean {
    • public void afterPropertiesSet() {
    • // do some initialization code
    • }
    • }

    DisposableBean

    • <bean id=”expInitBean” destroy-method=”cleanup”/>
    • public class ExpBean {
    • public void cleanup() {
    • // do some destruction code (like releasing pooled connections)
    • }
    • }

    OR

    • <bean id=”expInitBean”/>
    • public class ExpBean implements DisposableBean {
    • public void destroy() {
    • // do some destruction code (like releasing pooled connections)
    • }
    • }

    46) How to Create an Object without using the keyword “new” in java?

    Ans:

    • Without new, the Factory methods are used to create objects for a class. For example
    • Calendar c=Calender.getInstance();
    • Here Calender is a class, and the method getInstance() is a Factory method which can create an object for Calendar class.

    47) What is a servlet?

    Ans:

    Servlets is a server-side component that provides a powerful mechanism for developing server side programs. Servlets is a server, as well as platform-independent and Servlets, are designed for various protocols. Most commonly used HTTP protocols. Servlets use the classes in the java packages javax.servlet, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.http.HttpSession;. All servlets must implement the Servlet interface, which defines life-cycle methods.

    48) Servlet is pure java object or not?

    Ans:

    Yes, pure java object.

    49) What are the phases of the servlet life cycle?

    Ans:

    The life cycle of a servlet consists of the following phases:

    • Servlet class loading
    • Servlet instantiation
    •  the init method
    • Request handling (call the service method)
    • Removal from service (call the destroy method)

    50) What must be implemented by all Servlets?

    Ans:

    The Servlet Interface must be implemented by all servlets

    Course Curriculum

    Learn J2EE Certification Course and Get Hired by TOP MNCs

    Weekday / Weekend BatchesSee Batch Details

    51) What are the components of J2EE applications?

    Ans:

    The components of J2EE applications include:

    • Client-tier components: Run-on the client machine.
    • Web tier components: Run-on the J2EE server.
    • Business tier components: Run-on the J2EE server.
    • Enterprise Information System software (EIS software): Runs on the EIS server.

    52) What are the J2EE client types?

    Ans:

    J2EE client types are

    • Applets
    • Application clients
    • Java Web Start enabled clients, by Java Web Start technology.
    • Wireless clients, based on the Mobile Information Device Profile (MIDP) technology.

    53) What is a J2EE container?

    Ans:

    The interface between a component and the low-level platform with specific functionality that supports the component is called a container. The application server maintains control and provides relevant services through an interface or framework calls as a container.

    54) What are defined as web components?

    Ans:

    Java Servlets and Java server pages technology components are identified as web components. Servlets dynamically receive requests and make responses. JSP server pages also behave as Java Servlets but facilitate the creation of more static content.

    55) Describe the MVC on struts?

    Ans:

    MVC stands for Model View Controller. Each section in the Model View Controller can be described as follows:

    • Model: Model represents the internal state of the system as a set of single or many Java Beans.
    • View: Most often the view is constructed using Java Server Pages (JSP) technology.
    • Controller: The controller is the process that focuses on receiving client requests and produces the next level of a user interface according to the request. The primary component of the controller in the framework is the “ActionServlet” servlet class.

    56) Define JSF?

    Ans:

    JSF stands for Java Server Faces. It is the user interface (UI) designing framework for Java Web application developments. There is a set of reusable UI components associated with JSF. Also, JSF is based on Model-View-Controller (MVC) design concepts and patterns. The automated data saving process from form to server and display at the client side is also handled by JSF.

    57) What is Hashtable?

    Ans:

    Hashtable is a collection synchronized object. It allows null values but not the duplicate values. Hashtable is like a HashMap.

    58) Define Hibernate?

    Ans:

    • Hibernate is an open-source object-relational mapping and query service which facilitates writing Hibernate Query Language (HQL) scripts instead of Structured Query Language (SQL) scripts.
    • It is a faster and easy process than writing native SQL. Hibernate has more powerful object-oriented contents like associations, inheritance, and polymorphism. Also, it has powerful compositions and collections. Hibernate allows making queries using a Java-based approach.

    59) What are the identified limitations of hibernate?

    Ans:

    • Slower in action: In execution of HQL queries take more time than it executes directly.
    • Only composite key support is available and it prevents advanced query options.
    • No shared value type references are available.

    60) What are the identified advantages of hibernate?

    Ans:

    Advantages are:

    • Database and vendor independence application.
    • Standard Object-relational mapping support.
    • Domain object mapping for a relational database.
    • Better performance than Java Database Connectivity.
    • Java Persistence API based applications.

    61) Describe ORM?

    Ans:

    Object-Relational mapping (ORM) can be described as follows:

    The mapped objects in a Java class to the tables of the relational database using metadata describes the database and object mapping. The working method is to transform data from one representation to another.

    62) What are the advantages of Object-Relational Mapping (ORM)?

    Ans:

    Advantages are:

    • Productivity: Reduced time for data access coding with the help of automatic code creation based on the defined data model.
    • Maintainability: All code generated from ORM are well tested. Only the developer is required to create the correct functionality
    • Performance: The code generated from ORM completely manages the data access needs of the application. No need to create any data access code. Also, the code is optimized to speed up the data access process.
    • Vendor independence: The code generated from ORM does not depend on the vendor. This is to increase the portability of the application.

    63) What is the use of method save()?

    Ans:

    In hibernate, this method is used to store an object into the database. There is a check for duplicate records before inserting it.

    64) What is the use of method saveorupdate()?

    Ans:

    In hibernate, method saveorupdate() is used to update an object using the identifier. When the value for the identifier is NULL then the method is directed to call save().

    65) What is the difference between load() and get()?

    Ans:

    • When the object is not available in either cache or database, the load() method throws an exception. No null values are returned from the load() method.
    • When the object is not available in either cache or database, get() returns null.

    66) What is meant by connection pooling?

    Ans:

    Connection pooling is a mechanism to reuse the existing connections. The pooling mechanism maintains a number of already created object connections and when there is a demand, the mechanism directly uses the existing connection without creating a new one.

    67) Define the Collection types in Hibernate?

    Ans:

    One-to-many reference is defined as a collection. There are five main collection types associated with J2EE. They are: Set type, List type, Array type, Map type, Bag type

    68) Define a thin client?

    Ans:

    A program interface that does not have any operations like database queries, complex business rules or any connection to the third-party application is called a thin client.

    69) Describe the file types *.ear, * .jar and *.war?

    Ans:

    • *.jar files – Property file containing libraries, resources, and accessories are included with the *.jar file extension.
    • *.war files – The files that are required for the development of web application (HTML, java scripts, JSP) are included with a *.war file extension.
    • *.ear files – The files for Enterprise Java Beans modules for the application are saved as *.ear files.

    70) How spring is related to J2EE?

    Ans:

    Spring is an open-source application that reduces the complexity of enterprise application development. Spring is based on an inversion of control or dependency injection design patterns.

    Java Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

    71) What are the advantages of using spring for application development?

    Ans:

    • Plain Old Java Object (POJO) based development facilitates the re-use of existing components.
    • Possible to reduce development cost by improving the productivity of the application development.
    • Improve the testability of application with dependency injection.
    • Improve maintainability with reduced code coupling.
    • No need to have an application server and work on enterprise service.

    72) Discuss the benefit of the Spring Framework?

    Ans:

    Benefits are as follows:

    • Possibility to organize middle-tier objects in an efficient way.
    • Easy initialization for properties.
    • Easily testable components.
    • Lightweight container.
    • Possibilities to use configuration management service of spring in any runtime environment with whatever architectural layer.

    73) Describe servlet?

    Ans:

    The Server-side component that provides a powerful mechanism to create server-side programs is called a servlet. There are servlets available with a design for various protocols. Servlet is also server and platform-independent. The most commonly used protocol for the servlet is Hypertext Transfer Protocol (HTTP). Also, a servlet is a pure java object.

    74) Describe the phases of the servlet life cycle?

    Ans:

    The phases of servlet life cycle are:

    • Classloading phase – Web container loads the servlet class file (*.class).
    • Instantiation phase – By calling default no-arg constructor, the servlet class gets Instantiated.
    • Initialize phase – The method Init () called in this phase in only one time of the lifetime of a servlet. Servlet configuration is assigned to the servlet.
    • Request Handling phase – In this phase, only servlets spends most of the time. Servlet provides the services to various requests by calling Service ().
    • Removal phase – The destroy () function is called before servlet destruction. Garbage collection occurs later.

    75) What are the different types of JSP tags?

    Ans:

    There are 4 different types of tags associated with JSP. They are mentioned below:

    • Directives
    • Declarations
    • Scriptlets
    • Expressions

    76) Describe the action form?

    Ans:

    • A Java bean that is associated with single or multiple action mapping is called an action form. Action form objects are automatically populated at the server end when data has been entered from the client side through a user interface (UI).
    • Session states of a web application are maintained by action forms.

    77) Describe the Secure Socket Layer (SSL)?

    Ans:

    • The technology that is used to communicate between the web server and the web browser is called Secure Socket Layer (SSL). More specifically, SSL is a protocol that describes how algorithms are to be used in encryption.
    • The technology establishes an encrypted link between two parties and this link is allowed to secure transmission of sensitive information such as login credentials, credit/debit card information and social security numbers.

    78) What is id URL?

    Ans:

    URL stands for Uniform Resource Locator and it is the textual reference writing standard to an arbitrary piece of data in the World Wide Web (www). The general structure of the URL is as follows:

    protocol://host/local info

    • protocol – Protocol is for fetching the object (example: HTTP, FTP)
    • host – Internet name of the targeted host.
    • local info – String is passed to the protocol handler on the remote host. In many cases, it is a file name with an extension.

    79) What is URN?

    Ans:

    URN stands for the Uniform Resource Name. It is a unique identifier that identifies an entity. But the information on where the entity is located is not available.

    80) What are the steps associated with the servlet life cycle?

    Ans:

    The following steps are associated with the servlet life cycle:

    • Loading of the servlet class.
    • Instantiation of Servlet.
    • Execution of the init method.
    • Request handling phase. In this phase, service methods are called.
    • Removal from the service phase. In this phase, the destroy method is called.

    81) Is Servlet a pure java object or not?

    Ans:

    Yes, Servlet is a pure java object.

    82) What is EJB?

    Ans:

    EJB stands for Enterprise Java Beans. It is the server-side component that executes in an EJB container and encapsulates the business logic for the enterprise application.

    83) What are the system services of the EJB container?

    Ans:

    EJB Container provides the following system services:

    • Persistence
    • Security
    • Transaction
    • Connection pooling
    • Component lifecycle management
    • Threading

    84) What are the design principles for EJB?

    Ans:

    Design principle includes:

    • The behavior of the EJB application is specified by interfaces.
    • EJB applications are loosely coupled and tired.
    • Implementation is hidden from the client-side.
    • The EJB container supports the application developer.
    • The API to the application is in session tier.
    • The API to the data sources is in the entity tier.

    85) What are the advantages of EJB components?

    Ans:

    Advantages are:

    • There is support for the integration of components from different vendors.
    • Possibility to authorize the EJB component’s detailed knowledge of the environment.
    • Possibility to assemble applications from separate component sources.
    • Interaction with its clients is entirely specified in terms of Java interfaces.
    • Portability support.
    • It does not maintain resources.

    86) What are the Basic and subtypes of Enterprise Java Beans (EJB)?

    Ans:

    Two main types and subtypes of EJB are as follows:

    • Session Beans
      • Stateful session beans
      • Stateless session beans
    • Entity Beans
      • Bean Managed Persistence (BMP)
      • Container-Managed Persistence (CMP)
      • Message Driven Beans

    87) What is the description of the expression element?

    Ans:

    The expressions used for writing dynamic content back to the client browser are called expression elements.

    88) What are the two types of comments supported by JSP?

    Ans:

    Two types of comments supported by JSP are:

    • HTML comment:
    J2EE Interview Questions and Answers
    • JSP comment.:
    J2EE Interview Questions and Answers

    89) What is called the JSP directive?

    Ans:

    JSP directive is the mechanism to provide metadata information to web containers about the JSP file. In the translation and compilation phases of the JSP life cycle, this Metadata is used by the web container.

    90) What are the different types of JSP directive?

    Ans:

    There are 3 different types of JSP directives available. These are:

    • Page directive
    • Include directive
    • Taglib directive

    Are you looking training with Right Jobs?

    Contact Us
    Get Training Quote for Free