gizgok gizgok - 4 months ago 10
Java Question

What exactly is a container in J2EE and how does it help?

I'm reading J2EE 1.4 spec right now and there are lot of terms that I do not understand do what.
This is from the specs for containers:


Containers provide the runtime support for J2EE application components.
Containers provide a federated view of the underlying J2EE APIs to the application
components. J2EE application components never interact directly with other J2EE
application components. They use the protocols and methods of the container for
interacting with each other and with platform services. Interposing a container
between the application components and the J2EE services allows the container to
transparently inject the services defined by the components’ deployment
descriptors, such as declarative transaction management, security checks, resource
pooling, and state management.


Since I come from web development world, I'm not able to grasp, what exactly does this do and what is the purpose of a container. What is meant by providing run time support? How does it make a J2EE a better system in terms or scalability, architecture?

Answer Source

J2EE/Java EE applications aren't self contained. In order to be executed, they need to be deployed in a container. In other words, the container provides an execution environment on top of the JVM.

Also, applications rely on several APIs like JPA, EJB, servlet, JMS, JNDI, etc. The role of the EE compliant container is to provide a standard implementation of all or some of these APIs. This means you can theoretically run your application on top of any container as long as it relies on standard APIs.

From a technical perspective, a container is just another Java SE application with a main() method. EE applications on the other hand are a collection of services/beans/servlets/etc. The container finds these components and runs them, providing API implementations, monitoring, scalability, reliability and so on.