Java Blog

     JEE (Java Enterprise Edition) follows the distributed multi-tiered application approach which means the entire application may not reside at a single location, but distributed. And the applications is divided into various tiers. J2ee application is composed of various components which can be created by the different developers and then assembled together. These components can be installed on different machines across various tiers. And the distribution of application components across the solely different tiers depends upon the functionality it performs.

JEE Architecture Diagrom

J2EE application tiers are as follows

  • Client Tier (Web Browser or any other kinds of clients)
  • Web tier
  • Business Tier
  • Enterprise Information tier (Database or sometimes XMLs or flatfiles)

Various JEE Components

Components are self contained piece of software that are reusable across applications and are configurable external to the source code.
J2EE components are of three types : client component, web component and business component. The client components interact with the user, the web components interact with the web browsers using the HTTP protocol, and the business components interact with the application server and execute the business logic.

Client component of JEE architecture

Client components is of two types : web client and application client.

  • A web client, generally a browser, sends a request to the server and renders the webpage sent back by the server. However, it may not perform any complex tasks such as querying a database or performing any complicated business tasks and hence is also referred to as thin client. The complex tasks are performed on the server. For displaying web pages with applets, the web clients may require Java plug-ins and security policy files for executing the applets.
  • An application client is a standalone application that doesn’t run in browsers. It can access components in the business tier directly. Note that web clients that require access to a servlet running in the Web tier can open an HTTP connection with the servlet.
Web component of JEE architecture

Web components for java are Servlets and JavaServer Pages (JSP). A servlet receives HTTP requests from the client, processes them, and returns the output. It can also generate dynamic responses. Similar to servlets, JSP also create dynamic web pages. JSP pages are converted into servlets and executed within a servlet container. They are used to display the results processed by a servlet.

Business component of JEE architecture

Business components implement the business logic or the functional process logic that defines the business rules and constraints. For example business process such as withdrawing amount from the bank. Business components are of three types : session beans, entity beans, and message-driven beans. Session beans represent a session with a client. Being a transient object, they lose their data on completion of the session. On the other hand, entity beans are persistent objects and so retain data even after the session. They represent a row of data in a database table. Message-driven beans are for receiving the receiving Java Message Service (JMS) messages asynchronously.

Garbage Collection Memory DeAllocation in Java

In Java, an object which is no longer referred by any reference variable will automatically be removed from the memory, this process is known as Garbage Collection. Garbage Collection is automatically done by Java Virtual Machine (JVM), the automatic Garbage Collection of Java de-allocates the dynamic memory when this memory is no more used by the program. Thus the Garabage collection feature of Java relieves the programmer from the overhead of memory de-allocation.(A major difficulty in dynamic memory allocation in C/C++ was that the programmer is responsible for de-allocating the dynamic memory at the right time. Even though experienced programmers can do this very well, beginners and average programmers often miss the statements for de-allocation which leads to memory-leak in many systems.)

How Garbage collection in Java works

If a reference variable is declared within a function, the reference is invalidated soon as the function call ends. Or programmer can explicitly set the reference variable to null to indicate that the referred object is no longer in use. And then Garbage collector will claim the memory allotted for that.

Please note: Primitive data types are not objects and they cannot be assigned null.

What are JEE containers?

There are different kind of JEE containers. Take a look at the following JEE containers.

Application client container
Application client container is the one which is responsible for managing the application client components. Both application client and its container resides at the client machine and are executed on the client end. Example of application container is JVM.

Applet container
Applet container is the container to manage the execution of applets. Examples of an applet container include Web browser and applet viewer.

Enterprise JavaBeans (EJB) container
Enterprise JavaBeans (EJB) container is used to manage the execution of EJB component of the J2EE application. Both the EJBs and its container run on the J2EE server. J2EE server provides the EJB container, and an example of J2EE server is WebLogic.

Web container
Web container is used to manage the execution of the Servlets and the JSP. Both the Web components and its container run on the J2EE server. An example of a web container is Tomcat.

Responsibilities of JEE containers
  • Life cycle Management- Creating and deleting components
  • Persistence- Saving information in the components
  • Naming- Recording the name of a server component and locating it for the client.
  • Deployment- Placing components in the server
  • Messaging- Exchanging information between components.

 

Java Object and Class Difference between Object and Class

Java Object and Class Difference

Difference between Class and object in Java

In Java,  Class is a blue print used to create objects. In other words, a Class is a template that defines the methods (Functions) and Members (variables) to be included in a particular kind of Object.

Here, “Student” is a class. And “Jenna” is an object of the class “Student”. And “John” is another object of the class “Student”. A Class is a template for an object, a user-defined datatype that contains the variables and methods in it.

A class defines the abstract characteristics of a thing (object), including its characteristics (its attributes, fields or properties) and the thing’s behaviors (the things it can do, or methods, operations or features). That is, Class is a blue print used to create objects. In other words, each object is an instance of a class. One class can have multiple number of instances. (There can be Number of instances of the class “Student”, like “Jenna”, “John” etc).

A class is a predefined frame of an object, in which its mentioning what all variables and methods an object (object of that class) can have.