J2EE Interview Questions and Answers

J2EE Interview Questions and Answers

Last updated on 16th Oct 2020, Blog, Interview Question

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) | 16325 Ratings 2125

J2EE stands for Java 2 Platform Enterprise Edition. It is an open and standards-based platform for development, deployment, and management of multi-tier, web-enabled, component-based and server-centric enterprise applications.

There are several Application programming interfaces comprised of J2EE for building such systems.

1)What is J2EE?

Ans:

J2EE means Java 2 Enterprise Edition. The functionality of J2EE is developing multitier web-based applications. The J2EE platform is 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 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 pattern. It automatically saves the form data to the server and populates the form date when display 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:

ORM stands for Object-Relational mapping. The objects in a Java class which is 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 stores 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 identifier. If the identifier is missing this method calls save(). If the identifier exists, it will call 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 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

Subscribe For Free Demo

Error: Contact form not found.

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

Ans:

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

18) How Hibernate is database independent explain?

Ans:

Only changing the full property full database can be replaced.

  • org.hibernate.dialect.Oracle9Dialect and
  • oracle.jdbc.driver.OracleDriver 1
  • 2
  • 3

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

Ans:

  • org.hibernate.dialect.Oracle9Dialect and
  • oracle.jdbc.driver.OracleDriver

20) Define connection pooling?

Ans:

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

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();
  • 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 to the user to express queries in its portable SQL extension, and this is called as 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:

In 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:

Id this is the value

You can access this parameter

Id:

29) What are JSP Directives?

Ans:

  • page Directives <%@page language=”java” %>
  • include 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.

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

Ans:

  • public class MyClass { public static void main(String argv[])
  • {
  • int array[]=new int[]{1,2,3};
  • System.out.println(array [1]);
  • }
  • }
  • Answer: Compiled and shows output : 2
  • public class MyClass { public static void main(String argv[])
  • {
  • int array[]=new int[]{1,2,3};
  • System.out.println(array [1]);
  • }
  • }
  • Answer: 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:

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:

ActionForm is a Java bean that associates one or more ActionMappings. A java bean become FormBean when extend 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:

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: Model 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.

Course Curriculum

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

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

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 is Bean Factory, have you used XMLBean factory?

Ans:

XmlBeanFactory is one of the implementation of bean Factory org.springframework.beans.factory.xml.XmlBeanFactory is used to creat bean instance defined in our

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

Or

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

XmlBeanFactory is one of the implementation of bean Factory org.springframework.beans.factory.xml.XmlBeanFactory is used to creat bean instance defined in our

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

Or

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

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 ?

Ans:

Controller

42) What is default scope in Spring?

Ans:

Singleton.

43) What are advantages of Spring usage?

Ans:

Pojo based programming enables reuse component.

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:

1) InitializingBean

  • public class ExpBean { public void init()
  • {
  • // do some initialization code
  • }
  • }
  • OR
  • public class ExpBean implements InitializingBean
  • {
  • public void afterPropertiesSet()
  • {
  • // do some initialization code
  • }
  • }

2) DisposableBean

  • public class ExpBean
  • {
  • public void cleanup()
  • {
  • // do some destruction code (like releasing pooled connections)
  • }
  • }
  • OR
  • public class ExpBean implements DisposableBean
  • {
  • public void destroy()
  • {
  • // do some destruction code (like releasing pooled connections)
  • }
  • }

1) InitializingBean

  • public class ExpBean
  • {
  • public void init()
  • {
  • // do some initialization code
  • }
  • }
  • OR
  • public class ExpBean implements InitializingBean
  • {
  • public void afterPropertiesSet()
  • {
  • // do some initialization code
  • }
  • }

2) DisposableBean

  • public class ExpBean
  • {
  • public void cleanup()
  • {
  • // do some destruction code (like releasing pooled connections)
  • }
  • }
  • OR
  • public class ExpBean implements DisposableBean
  • {
  • public void destroy()
  • {
  • // do some destruction code (like releasing pooled connections)
  • }
  • }

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

Ans:

Without new, the Factory methods are used to create objects for a class. For example

  • Calender 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

51) What state does a thread enter when it terminates its processing?

Ans:

When a thread terminates its processing, it enters the dead state.

52) How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?

Ans:

Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.

53) Does garbage collection guarantee that a program will not run out of memory?

Ans:

Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection

Course Curriculum

Learn J2EE Certification Course and Get Hired by TOP MNCs

Weekday / Weekend BatchesSee Batch Details

54) What is an object’s lock and which object’s have locks?

Ans:

An object’s lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object’s lock. All objects and classes have locks. A class’s lock is acquired on the class’s Class object.

55) What is casting?

Ans:

There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference

56) What restrictions are placed on method overriding?

Ans:

Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method.

57) How does a try statement determine which catch clause should be used to handle an exception?

Ans:

When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exception is executed. The remaining catch clauses are ignored.

58) Describe what happens when an object is created in Java ?

Ans:

1. Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data.

2. The instance variables of the objects are initialized to their default values.

3. The constructor for the most derived class is invoked. The first thing a constructor does is call the constructor for its superclasses. This process continues until the constructor for java.lang.Object is called,

as java.lang.Object is the base class for all objects in java.

4. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last.

59) What is the difference between StringBuffer and String class ?

Ans:

A string buffer implements a mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls. The String class represents character strings. All string literals in Java programs, such as “abc” are constant and implemented as instances of this class; their values cannot be changed after they are created.

60) Describe, in general, how java’s garbage collector works ?

Ans:

The Java runtime environment deletes objects when it determines that they are no longer being used. This process is known as garbage collection. The Java runtime environment supports a garbage collector that periodically frees the memory used by

objects that are no longer needed. The Java garbage collector is a mark-sweep garbage collector that scans Java’s dynamic memory areas for objects, marking those that are referenced. After all possible paths to objects are investigated, those objects that are not marked (i.e. are not referenced) are known to be garbage and are collected.

61) What is RMI ?

Ans:

RMI stands for Remote Method Invocation. Traditional approaches to executing code on other machines across a network have been confusing as well as tedious and error-prone to implement. The nicest way to think about this problem is that some object happens to live on another machine, and that you can send a message to the remote object and get a result as if the object lived on your local machine. This simplification is exactly what Java Remote Method Invocation (RMI) allows you to do.

62) What is JDBC? Describe the steps needed to execute a SQL query using JDBC?

Ans:

The JDBC is a pure Java API used to execute SQL statements. It provides a set of classes and interfaces that can be used by developers to write database applications.

The steps needed to execute a SQL query using JDBC:

  • Open a connection to the database.
  • Execute a SQL statement.
  • Process th results.
  • Close the connection to the database.

63) Are constructors inherited? Can a subclass call the parent’s class constructor? When?

Ans:

You cannot inherit a constructor. That is, you cannot create a instance of a subclass using a constructor of one of it’s superclasses. One of the main reasons is because you probably don’t want to override the superclasses constructor, which would be possible if they were inherited. By giving the developer the ability to override a superclasses constructor you would erode the encapsulation abilities of the language.

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

64) What is JSON ?

Ans:

JSON is “JavaScript Object Notation”, primarily used for client-server or server-server communication. Its a much lighter and readable alternative to XML. JSON is language independent and is easily parse-able in all programming languages.

65) What is the role of JSON.stringify ?

Ans:

  • JSON.stringify()

turns an object into a JSON text and stores that JSON text in a string.

So If we stringfy above notation , it will become

  • {“name”:”xyz”,”gender”:”male”;”age”:30}

66) When were Enums introduced in Java ?

Ans:

Enums were introduced with java 5.

67) Which function is used to convert a JSON text into an object ?

Ans:

eval

68) Which data types are supported by JSON ?

Ans:

  • Number
  • String
  • Boolean
  • Array
  • Object
  • null

69) What are the benefits of JSON over XML ?

Ans:

Lighter and faster than XML as on-the-wire data format

Object Representation – Information is presented in object notations and hence better understandable. Easy to parse and conversion to objects for information consumption.

Support multiple data types – JSON supports string, number, array, boolean whereas XML data are all string.

70) What are the methods of Object Class ?

Ans:

clone() – Creates and returns a copy of this object.

equals() – Indicates whether some other object is “equal to” this one.

finalize() – Called by the garbage collector on an object when garbage collection determines that there are no more references to the object

getClass() – Returns the runtime class of an object.

hashCode() – Returns a hash code value for the object.

toString() – Returns a string representation of the object.

notify(), notifyAll(), and wait() – Play a part in synchronizing the activities of independently running threads in a program.

Are you looking training with Right Jobs?

Contact Us

Popular Courses