Posted by: fuckeetow November 25, 2011
Java: Need Help/Suggestion from fellow developers
Login in to Rate this Post:     0       ?        
JavaSE  (Java Standard Edition)

        -> I think you already this edition of Java is for Desktop applications.
       Whatever, if haven't done so, please go through some of the tutorials here: http://docs.oracle.com/javase/tutorial/
      Go through topics under Trails Covering the Basics and also some of the topics (e.g. JDBC, JNDI, Generics, JAXP, JavaBeans, some Reflection)  under Specialized Trails and Lessons. But you don't have bother going through the topics that I didn't mention unless you need to because of your job requirement. Otherwise, it will be a perfect waste of time because since you are a developer I assume you are already aware that JEE is really really vast.
       One important thing to note is JEE itself is buit on top of JavaSE so it's better to learn some techniques to do stuffs in a better way. And if you want to learn those techniques then the book "Effective Java" by Joshua Bloch is the book almost everybody recommends.

JEE (Java Enterprise Edition)

      -> First of all, enterprise applications are a lot more complicated then regular desktop applications. May be that's why they follow layered architecture. As far as I remember, different layers in a layered architecture are - Data layer, Business layer, Presentaton layer.

       Data layer: As the name implies, you are going to put all of your code that is responsible for retriveing and persisting the data from the database in this layer. So, that your Business layer don't get polluted with data access codes.

      Business layer: This is the layer where you put your business (application) code. It's good to make sure, we don't put the view (presentation) related code here.

      Presentation layer: This is where you manipulate the data, you recieved for either data layer or business layer, to turn it into something more suitable and meaningful to be presented to the end user.

      Layered Architecture: This is a kind architectures that an application might follow (whether it's an enterprise application, or just a web application, or even a desktop application). I just want you to know that you can not use Java at all and develop an enterprise application which is layered. So, don't be confused that Layered Architecture is something that lies within JEE, but try to understand that it's a totally different concept and your job is to figure out how it is implemented by JEE.

      Servlet API -> EJB -> JPA (This is how the layered architecture is implemented in JEE)

      Servlet API: This API is used to write codes that handle the request from the end user. A HTTP request is decoded in this layer, service (business) layer is called to invoke the corresponding business code which inturn might invoke the data access code. This request processing cycle is ended by the response being sent back to the end user.
      Here we are using the Servlet API. There is something called Servlet Specification, against which we write our code and which is also followed by the Servlet (web) container. So, we have to make sure that we follow that specification properly for us to expect our sevlet to run properly in a web container.
      This is where the web application frameworks like Struts, JSF, etc comes into play. As you can see, these frameworks are there to help you build your presentation (view) layer, just like Swing in JavaSE, they also follow the MVC Design Pattern just like Swing does.
      e.g. JSF (Java Server Faces) is the standard (or official) framework, which has the Faces-Servlet as the Controller (C in MVC), managed-beans as Models (M in MVC), and facelets (xhtml) or JSPs as Views (V in MVC). Any application that uses JSF, process a request phase by phase. The phases are - Restore View, Apply Request Values, Process Validations, Update Model Values, Invoke Application, and Render Response. This might not be very useful to you, but if you look at the names of those phases then you can see how they are distinct from one another and resposible for tackeling a whole different set of concern. JSF also comes with a huge set of reusable codes. JSF is also called a component-based or event-based web framework.
     As you can see that these frameworks are nothing but a huge library of codes that helps to write a web application in a very managed and meaningful way.

       A Java web application (also called web-module) is packaged into a file with the extension war. WAR (Web Archive) is a package that contains some folders with some specific names layed out in some specific way, some specific files which helps the server (or container) in which it will be deployed. It also contains your application specific stuffs like pages and file (JSP, html, xhtml, css, Javascript), classes (these might be some manged-beans, servlets, filters) basically these are considered as (web) components in general, and some libraries that your application needs.

      So, we can develop a web application for the view (presentation) layer of our enterprise application. Or, it can be an application on it's own independant of any enterprise application in which case we can implement the layered architecture with the web application. Which is done specially for separation of concerns.

      EJB (Enterprise Java Bean):     
         Within JavaEE there is another specification called EJB. Whatever this specification says is followed by the EJB containers, and as a developer we code out EJBs using the relative API, against the same specification to make when we deploy are ejb-module into a ejb-container, it works the way it's supposed to.
         Here, the container is responsible for low-levle functionalities like multithreading, transactions (while accessing data or while dealing with messaging (JMS)), management of our enterprise beans' lifecycle.
         A lot times, if you try to read about EJB you get confused because some times you might be reading about EJB 2.x and sometimes you might reading about EJB 3.x. And the fact is that EJB has changed drastically between those versions. So, from next time instead of getting confused make sure you know what version of the EJB that post applies to.
        E.g. I might say there are two types of EJBs (Session and Message-Driven) and some else might say actually there are three (Session, Message-Driven, and Entity). While that's true for EJB 2.x, that's not true for EJB 3.x. It has already been realized that entity is something that represents a table in the database, so obviously it something that belongs in JPA not in EJB. So, it's a part of JPA API. And even though we can use the JPA within a desktop application without a need for a ejb-container, I think it's still considered a sub-specification under EJB.
       JPA (Java Persistence API):
       It's build on top of JDBC, it's not hard to tell that. But, main purpose is to persistence framework that lets developers deal with RDBMS related code just like they do with regular Java code. This is the idea borrowed from the framework like Hibernate.
       But, since JPA is the standard, it's good to learn JPA then other frameworks like hibernate directly. If you code using JPA you can use other frameworks like hibernate, eclipse-link, toplink, etc as runtime provider.
       If you want to learn about JPA, then would recommend you to start with JDBC and move towards JPA, but do all that in a desktop application. Because, desktop applications are easier and you can lear more JPA.

      Here (http://docs.oracle.com/javaee/6/tutorial/doc/) where you will find some tutorial on every thing you will find in JEE. It's offical JEE tutorial. This is where you should go whenever you have some confusion and you need to know the fact. It's for JEE version 6, but if you google you will also find one for version 1.4. But, version 6 is pretty old so I thinks it's good to follow that.

JavaEE 6 also provides a feature called CDI (Context and Dependancy Injection). This is new in version version 6, and wasn't there in the prior versions (better known as J2EE). This feature helps us decouple our components (or beans) by specifying the dependency to the container which will make sure that dependancy is injected into our component before it brings it into life and starts managing it's lifecycle. Spring is the framework that is really famous when comes to DI. Actually, standard JEE itself borrowed that idea from Spring.

I hope this helps a little.

     
Last edited: 25-Nov-11 11:06 AM
Last edited: 25-Nov-11 11:07 AM
Read Full Discussion Thread for this article