Garbage Collection or Memory DeAllocation in Java

1 Comment

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?

1 Comment

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.