Definition of a Java Container

Posted on

Definition of a Java ContainerError is an illegal operation performed by the user which results in the abnormal working of the program. By now, you’ve probably seen a few errors, either when compiling or running your code like Definition of a Java Container. It can be frustrating, but they can also give you a lot of information about exactly how you can fix the problems in your code about java and jakarta-ee. In this post covers the types of errors you’ll see when programming in Java, and how to fix them. Don’t pay any attention to the number of errors. Just read the first error message and work on fixing that error.

Problem :

I’ve readheard many times about java containers such as a servlet container, however, I can’t seem to find a good definition of what a container is in the enterprise java world.

Does anyone know of a good definition of an enterprise java container?

Solution :

The common containers in Java EE are servlet container and the EJB container, and I see these as examples of IoC(Inversion of Control) containers. The crucial aspects are :

  1. Your code does not have any main() or “wait here for a request logic” – the container starts up and configures itself and then eventually initialises your code and delivers requests
  2. Your code may be one of many similar classes (servlets in a servlet container, EJBs in an EJB container) whose instances have life-cycles to be controlled by the container.
  3. Requests are delivered to your servlet or EJB via some protocol defined by the container, using resources (eg. HTTP ports) controlled by the container, and possibly with considerable infrastructure cleverness (look at the HTTP request queues, EJB load balancing etc.)
  4. There’s considerable added value from functions such as transaction control and security management – as the container is calling your code it is well-placed to implement this unintrusively.
  5. The main container functionality is very much IOC, the container calls your code at appropriate times, however the container will also provide useful APIs that your code can call (eg. to get Servlet or EJB Contexts.

Referring more generally to the Container pattern (of which an enterprise Java container could be considered a specialization), the book Server Component Patterns by M.Volter, et al. offers the following:

[A CONTAINER provides] an execution environment that is responsible
for adding the technical concerns to the COMPONENTS…Conceptually, it
wraps the COMPONENTS, thus giving clients the illusion of of
tightly-integrated functional and technical concerns.

Examples of such technical concerns include security, transaction management, logging, etc.

Java EE Containers

Normally, thin-client multitiered applications are hard to write
because they involve many lines of intricate code to handle
transaction and state management, multithreading, resource pooling,
and other complex low-level details. The component-based and
platform-independent Java EE architecture makes Java EE applications
easy to write because business logic is organized into reusable
components. In addition, the Java EE server provides underlying
services in the form of a container for every component type. Because
you do not have to develop these services yourself, you are free to
concentrate on solving the business problem at hand.

The key notion behind a container is inversion of control, where application components inside the container can be loosely coupled with other application components as well as lower-level resources they depend upon. For Java these resources are usually things like database connections, network connections, JNDI, etc.

Different tiers of containers support different specifications for instance a web/servlet container like tomcat does not support some application level specifications like EJB3, therefore tomcat cannot wire together ejb’s for injection into your application.

“Containers are the interface between a component and the low-level platform-specific functionality that supports the component. Before a web component, enterprise bean, or application client component can be executed, it must be assembled into a Java EE module and deployed into its container.”
here is my source :

A container is execution environment that brings dynamism. It creates HTTP response, converts HTTP request to an object and creates and manages servlet life cycle.

Java EE is the collection of the specification that are used to solve enterprise problems like security, scalability, robustness, availability etc.

A container that manages every specification of Java EE is known as Java enterprise container. Eg. glassfish, JBoss etc. (BTW Tomcat is not EE container it is web container)

It is responsible for maintaining the individual components on the server side, which include Java servlets, Java server pages and Java server faces.

Container– in the context of Java development, refers to a part of the server that is responsible for managing the lifecycle of Web applications. The Web applications specify the required lifecycle management with the help of a contract presented in XML format. The Web container cannot be accessed directly by a client. Rather, the server manages the Web container, which in turn manages the Web application code.


Leave a Reply

Your email address will not be published. Required fields are marked *