Google

Sep 23, 2011

Enterprise Java interview questions and answers

The following  most popular enterprise Java (i.e. JEE or J2EE) interview questions and answers are frequently asked in job interviews. If you are a more experienced professional and have a good understanding of the high level basics, then try How does JEE 6 differ from JEE 5?


Q. Explain 3-tier or n-tier architecture  used by JEE?
A. This is a very commonly asked question. Be prepared to draw some diagrams on the board. The JEE platform is a multi-tiered system. A tier is a logical or functional partitioning of a system.


Each tier is assigned a unique responsibility in a 3-tier system. Each tier is logically separated and loosely coupled from each other, and may be distributed.

Client tier represents Web browser, a Java or other application, Applet, WAP phone etc. The client tier makes requests to the Web server who will be serving the request by either returning static content if it is present in the Web server or forwards the request to either Servlet or JSP in the application server for either static or dynamic content.

Presentation tier encapsulates the presentation logic required to serve clients. A Servlet or JSP in the presentation tier intercepts client requests, manages logons, sessions, accesses the business services, and finally constructs a response, which gets delivered to client.

Business tier provides the business services. This tier contains the business logic and the business data. All the business logic is centralized into this tier as opposed to 2-tier systems where the business logic is scattered between the front end and the backend. The benefit of having a centralized business tier is that same business logic can support different types of clients like browser, WAP (Wireless Application Protocol) client, other stand-alone applications written in Java, C++, C# etc.

Integration tier is responsible for communicating with external resources such as databases, legacy systems, ERP systems, messaging systems like MQSeries etc. The components in this tier use JDBC, JMS, J2EE Connector Architecture (JCA) and some proprietary middleware to access the resource tier.

Resource tier is the external resource such as a database, ERP system, Mainframe system etc responsible for storing the data. This tier is also known as Data Tier or EIS (Enterprise Information System) Tier.



Note: On a high level J2EE can be construed as a 3-tier system consisting of Client Tier, Middle Tier (or Application Tier) and Data Tier. But logically or functionally J2EE is a multi-tier (or n-tier) platform.


Q. What are the advantages of a 3-tiered or n-tiered application?
A. 3-tier or multi-tier architectures force separation among presentation logic, business logic and database logic. Let us look at some of the key benefits:

  • Manageability: Each tier can be monitored, tuned and upgraded independently and different people can have clearly defined responsibilities.
  • Scalability: More hardware can be added and allows clustering (i.e. horizontal scaling). 
  • Maintainability: Changes and upgrades can be performed without affecting other components.
  • Availability: Clustering and load balancing can provide availability.
  • Extensibility: Additional features can be easily added.

The following diagram gives you a bigger picture of  the logical tiers and the components.




Q. Explain MVC architecture relating to J2EE?
A. This is also a very popular interview question. MVC stands for Model-View-Controller architecture. It divides the functionality of displaying and maintaining of the data to minimize the degree of coupling (i.e. promotes loose coupling) between components. It is often used by applications that need the ability to maintain multiple views like HTML, WML, Swing, XML based Web service etc of the same data. Multiple views and controllers can interface with the same model. Even new types of views and controllers can interface with a model without forcing a change in the model design.


A model represents the core business logic and state. A model commonly maps to data in the database and will also contain core business logic. 

A view renders the contents of a model. A view accesses the data from the model and adds display logic to present the data.

A controller acts as the glue between a model and a view. A controller translates interactions with the view into actions to be performed by the model. User interactions in a Web application appear as GET and POST HTTP requests. The actions performed by a model include activating business processes  or changing the state of the model. Based on the user interactions and the outcome of the model actions, the controller responds by selecting an appropriate view.

Q. What are ear, war and jar files? What are J2EE Deployment Descriptors?
A. The ear, war and jar are standard application deployment archive files. Since they are a standard, any application server (at least in theory) will know how to unpack and deploy them.

An EAR file is a standard JAR file with an “.ear” extension, named from Enterprise ARchive file. A J2EE application with all of its modules is delivered in EAR file. JAR files can’t have other JAR files. But EAR and WAR (Web ARchive) files can have JAR files.

An EAR file contains all the JARs and WARs belonging to an application. JAR files contain the EJB classes and WAR files contain the Web components (JSPs, Servlets and static content like HTML, CSS, GIF etc). The J2EE application client's class files are also stored in a JAR file. EARs, JARs, and WARs all contain one or more XML-based deployment descriptor(s).

Deployment Descriptors

A deployment descriptor is an XML based text file with an “.xml” extension that describes a component's deployment settings. A J2EE application and each of its modules has its own deployment descriptor.




More related questions and answers at

Labels:

9 Comments:

Anonymous Javin @ polymorphism in java said...

Good collection and very detailed answer man, its different than normal question answer site. more appropriate to learn while preparing. by the way I have also shared my experience as Top 20 core java interview questions answers in Banks let me know how do you find it.

5:26 PM, September 25, 2011  
Blogger Macrosoft said...

This java interview questions are helpful for me.

Mainframe Development

7:42 PM, April 16, 2013  
Blogger venkat said...

Thanks Man for providing such a clear description.

1:01 AM, November 15, 2013  
Anonymous Anonymous said...

good

2:18 AM, April 03, 2014  
Blogger Trinesh D said...

Awesome work. Thanks a lot for sharing.

5:06 AM, April 05, 2014  
Anonymous Anonymous said...

excellent explanation, your contribution is highly appreciated, amazed seeing some one publish a technical details in this depth in crisp and understandable way. good presentation of the concept.

12:56 PM, April 17, 2014  
Blogger Websphere Portlet, Help and Administration Help said...

Its really nice explanations, Just one suggestion Please put more clear text diagrams.

12:24 PM, April 22, 2014  
Blogger N Pradeep said...

Good explanation ! really helpful !

4:10 PM, June 11, 2014  
Blogger Arulkumaran Kumaraswamipillai said...

thanks.

4:13 PM, June 11, 2014  

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home