3

Lately I started to learn Java EE and related technologies and there are some concepts which confuse me. Somewhere I read that whenever one is building a Java EE application then it is sort of mandatory to use a container.

Currently, I am learning Spring framework and trying to build a small application with it to get hands-on. Now in that I am not sure if it is mandatory for me to use a container (say Tomcat) or it depends application which I am building that I need a container or not.

If it depends on the application that one is building, then what are the factors which help to decide whether a container should be used or not?

Siddharth
  • 2,046
  • 5
  • 26
  • 41
  • 1
    If your application is using servlets, you'll need a container to handle the requests. Tomcat is a very popular choice. I'll anticipate your next topic to cover with this: http://stackoverflow.com/questions/5039354/difference-between-an-application-server-and-a-servlet-container – riddle_me_this Jun 24 '15 at 03:02
  • Basically: When you want to use the functionalities which are provided by the specific container ... – stg Jun 24 '15 at 06:40
  • I would be happy to remove this question but it would be nice if the person who down-voted could tell me the reason. Not telling the reason could lead to repeated incorrect questions from my side since I am not aware of the reason. – Siddharth Jun 24 '15 at 13:55
  • Thanks @bphilipnyc for your answer. I pointed me towards the right direction. I will dig more towards that side to clear my understanding. – Siddharth Jun 24 '15 at 13:57
  • Thanks @stg but that was very general :) – Siddharth Jun 24 '15 at 13:58
  • 1
    @Siddharth of course, but what do you expect? :) You could do everything completely on your own, e.g. pooling of instances of service beans or transaction management. If you want the EJB container do it for you, you have to use it of course. But you'd be able to code everything on your own or use completely different approaches provided by some additional frameworks etc ... so, the answer to your question IS that general , imho – stg Jun 24 '15 at 14:38
  • Thanks @stg :-) I got your point. – Siddharth Jun 24 '15 at 14:48
  • Ok, I just posted it as an answer if you'd like to accept it. – riddle_me_this Jun 24 '15 at 14:49

3 Answers3

8

Puuhhh, this is a very big question and there is no simple answer. But I will do my best to explain my own opinion at least:

What are containers?

Containers provide functionality to you. Such a functionality can be to handle web request and dispatch them to servlets - in this case we call them servlet containers (e.g. Tomcat or Jetty).

But containers can also provide other things, e.g. they can provide user authentication, logging or the connection to a database. Most containers (e.g. Tomcat) do multiple of those things (e.g. Tomcat does all I mentioned). Some containers do more then others, e.g. JBoss can do much more than Tomcat.

Trade Off

However, there is a trade off: If you use a simple container (like Tomcat), you need to do a lot of things on you own or by using other Frameworks (like Spring). But if you use a powerful container, you must know the container very well and the chance is high that your application will depend on this concrete container sooner or later.

The point, that using a container is not mandatory. It is a decision. Some people will argue for it, others against it. But depending on the books you read, this decision is already made (e.g. J2EE needs a J2EE container, that's how it works).

The trend (IMHO)

Years ago the trend was to use big and powerful (J2EE) containers which provide as much as possible. IMHO the trend today is to use smaller and light-way solutions. Most developers would prefer to use a Tomcat server instead of a JBoss server today.

Frameworks without containers

While J2EE needs a container, there are other frameworks/technologies which supports the development of web applications without any external container. Such frameworks are Play! or Spark Java.

Note

If you are not familiar with containers and Spring, take care to don't get confused. Most applications you will develop with Spring are web applications which will be deployed to a servlet container. This is very common. But Spring doesn't relay on that. You can also use Spring without such a container, e.g. to develop a desktop application. But if you want to develop a web application, the Java-way is to use a servlet container.

Thomas Uhrig
  • 30,811
  • 12
  • 60
  • 80
3

If your application is using servlets, you'll need a container to handle the requests. Tomcat is a very popular choice.

I'll anticipate your next topic to cover with this discussion of "application server" versus "container."

Community
  • 1
  • 1
riddle_me_this
  • 8,575
  • 10
  • 55
  • 80
-1

There are two containers. One is Web Container (IIS, Apache) to run Web Applications and another is "Application Container" to run Enterprise Applications.

Web Applications = Apps developed using HTML, XML, CSS and JSPs
Enterprise Applications = Apps developed used JAVA, J2E and Serverlets in addition to HTML and XML.

L_J
  • 2,351
  • 10
  • 23
  • 28