Java Interview Questions - J2EE

 
Q. What is J2EE?
A. J2EE is an environment for developing and deploying enterprise applications. The J2EE platform consists of a set of services, application programming interfaces (APIs), and protocols that provide the functionality for developing multitiered, web-based applications.
Q. What is the J2EE module?
A. A J2EE module consists of one or more J2EE components for the same container type and one component deployment descriptor of that type.

Q. What are the components of J2EE application? (Job Interview Favourites)
A. A J2EE component is a self-contained functional software unit that is assembled into a J2EE application with its related classes and files and communicates with other components. The J2EE specification defines the following J2EE components:

--Application clients and applets are client components.
--Java Servlet and JavaServer PagesTM (JSPTM) technology components are web components.
--Enterprise JavaBeansTM (EJBTM) components (enterprise beans) are business components.
--Resource adapter components provided by EIS and tool vendors.

Q. What are the four types of J2EE modules?
A.
1. Application client module
2. Web module
3. Enterprise JavaBeans module
4. Resource adapter module
Q. What does application client module contain?
A. The application client module contains:
--class files,
--an application client deployment descriptor.
Application client modules are packaged as JAR files with a .jar extension.

Q. What does web module contain?
A. The web module contains:

--JSP files,
--class files for servlets,
--GIF and HTML files, and
--a Web deployment descriptor.
Web modules are packaged as JAR files with a .war (Web ARchive) extension.

Q. What does Enterprise JavaBeans module contain?
A. The resource adapt module contains:

--all Java interfaces,
--classes,
--native libraries,
--other documentation,
--a resource adapter deployment descriptor.
Resource adapter modules are packages as JAR files with a .rar (Resource adapter ARchive) extension.

Q. What are the differences between Ear, Jar and War files? Under what circumstances should we use each one?(Job Interview Favourites)
A. There are no structural differences between the files; they are all archived using zip-jar compression. However, they are intended for different purposes.

--Jar files (files with a .jar extension) are intended to hold generic libraries of Java classes, resources, auxiliary files, etc.
--War files (files with a .war extension) are intended to contain complete Web applications. In this context, a Web application is defined as a single group of files, classes, resources, .jar files that can be packaged and accessed as one servlet context.
--Ear files (files with a .ear extension) are intended to contain complete enterprise applications. In this context, an enterprise application is defined as a collection of .jar files, resources, classes, and multiple Web applications.
Each type of file (.jar, .war, .ear) is processed uniquely by application servers, servlet containers, EJB containers, etc.

Q. What is the difference between Session bean and Entity bean?
A. The Session bean and Entity bean are two main parts of EJB container.

Session Bean
--represents a workflow on behalf of a client
--one-to-one logical mapping to a client.
--created and destroyed by a client
--not permanent objects
--lives its EJB container(generally) does not survive system shut down
--two types: stateless and stateful beans

Entity Bean
--represents persistent data and behavior of this data
--can be shared among multiple clients
--persists across multiple invocations
--findable permanent objects
--outlives its EJB container, survives system shutdown
--two types: container managed persistence(CMP) and bean managed persistence(BMP)

Q. What is the difference between URL instance and URLConnection instance?
A. A URL instance represents the location of a resource, and a URLConnection instance represents a link for accessing or communicating with the resource at the location.
Q. What are the two important TCP Socket classes?
A. Socket and ServerSocket. ServerSocket is used for normal two-way socket communication. Socket class allows us to read and write through the sockets. getInputStream() and getOutputStream() are the two methods available in Socket class.
Q. What technologies are included in J2EE?
A. The primary technologies in J2EE are: Enterprise JavaBeansTM (EJBsTM), JavaServer PagesTM (JSPsTM), Java Servlets, the Java Naming and Directory InterfaceTM (JNDITM), the Java Transaction API (JTA), CORBA, and the JDBCTM data access API.
Q. What is the Java Authentication and Authorization Service (JAAS) 1.0?
A. The Java Authentication and Authorization Service (JAAS) provides a way for a J2EE application to authenticate and authorize a specific user or group of users to run it. JAAS is a Java programing language version of the standard Pluggable Authentication Module (PAM) framework that extends the Java 2 platform security architecture to support user-based authorization.
Q. What’s the difference between JNDI lookup(), list(), listBindings(), and search()?
A. lookup() attempts to find the specified object in the given context. I.e., it looks for a single, specific object and either finds it in the current context or it fails. list() attempts to return an enumeration of all of the NameClassPair’s of all of the objects in the current context. I.e., it’s a listing of all of the objects in the current context but only returns the object’s name and the name of the class to which the object belongs. listBindings() attempts to return an enumeration of the Binding’s of all of the objects in the current context. I.e., it’s a listing of all of the objects in the current context with the object’s name, its class name, and a reference to the object itself. search() attempts to return an enumeration of all of the objects matching a given set of search criteria. It can search across multiple contexts (or not). It can return whatever attributes of the objects that you desire. It’s by far the most complex and powerful of these options but is also the most expensive.
Components of JNDI - Naming Interface- The naming interface organizes information hierarchically and maps human-friendly names to addresses or objects that are machine-friendly. It allows access to named objects through multiple namespaces. Directory Interface - JNDI includes a directory service interface that provides access to directory objects, which can contain attributes, thereby providing attribute-based searching and schema support. Service Provider Interface - JNDI comes with the SPI, which supports the protocols provided by third parties.
Q. What is the Max amount of information that can be saved in a Session Object?
A. As such there is no limit on the amount of information that can be saved in a Session Object. Only the RAM available on the server machine is the limitation. The only limit is the Session ID length(Identifier), which should not exceed more than 4K. If the data to be store is very huge, then it’s preferred to save it to a temporary file onto hard disk, rather than saving it in session. Internally if the amount of data being saved in Session exceeds the predefined limit, most of the servers write it to a temporary cache on Hard disk.
 
Disclaimer                        Feedback                      Suggestions