Tuesday, January 31, 2012

Java is dead? 9 million devs disagree

Java is dead? 9 million devs disagree
Java is not dead, in fact, it's got more than enough energy to kick your app in the butt. Pure Java, used properly, is an awesome language, even more so than Klingon. It will continue to improve and will not go away anytime soon. The effort should not be on replacing pure Java, but using it together with other JVM languages where it makes sense.


--
Amit Ranjan
Java developer
.............................
P please consider the environment before printing e-mail-- SAVE PAPER!

Tuesday, December 13, 2011

Memory Management in Java : Garbage Collector

Java Garbage Collector is responsible to sweep all the garbage objects remains in memory and leave only those objects which are still referenced on the memory stack. For this, JVM uses 'Mark-Sweep-Compact' three phase techniques. Here JVM give three passes to memory objects to destroy the garbage objects. The process is 

  • In first pass, GC traverses on the Memory Stack and mark all the objects which are referenced from Memory Stack through any scope data structure. 
  • In second pass, GC claims the space of all unmarked objects to release their memory. Before claiming the objects for collection, the demon thread, Garbage Collector, call 'finalize' method of the object in order to give it a chance to do the resource cleanup. Here if any object resurrect it again, i.e. do some activity which put its memory reference back to Memory Stack, garbage collector won't collect its memory and leave this. However in this process, GC maintains a state for the objects for which 'finalize' method has already been called once. In next garbage collection cycle, it does not call the 'finalize' method on this object. 
  • In third pass, garbage collector compact the memory space which was released by second pass and hence made the released memory available for JVM. 

This way, GC manages the memory. The process followed to manage the memory is not light in its processing, as three phases process takes a lot of time to execute and hence is a heavy process. Due to this, JVM does not call the GC very often, but it calls it only when it really feels that memory is low and program may need more memory soon. So even if you are calling System.gc(), it does not mean that JVM will call the GC. However it is just like a request to JVM to consider calling the GC. But JVM has its internal logic to decide when to call the GC. 

 

'Finalize' method is used for resource cleaning process by most of the applications. You can use this method to release any resource like ObjectOutputStream, any handle to an OS file etc. But be very careful while relying on this method. Reason is that JVM does not guarantee to call the finalize method. Consider a condition, when program never face a memory pressure and hence JVM never finds the need to call the GC.  



--
Amit Ranjan
Java developer
............................

Thursday, December 8, 2011

How much memory the java objects consume?

For an empty class:

public class TestClass {

}

size of the TestClass Object is 2 * Reference = 2*4 = 8 bytes.

For a class with primitive – int:

public class TestClass {
int i=0;
}

size = 2 * reference + size of int = 2*4 + 4 = 12 = 16 bytes (word aligned)

For a class with primitive – long:
public class TestClass {
long i=0;
}

size = 2 * reference + size of long= 2*4 + 8 = 16 bytes.

similarly for float and double , the size is 16 bytes.

Taking the wrapper classes,

public class TestClass {
Integer i= new Integer(0);
}
size = 2 * reference for TestClass Object + 2*Reference for Integer
object + size of int

= 2*4 + 2*4 + 4 = 32 bytes (word aligned)

Similarly the sizes for the objects with the Long, Float and Double
fields are32 bytes.

Instead of using the 'new' key word for the Integer instantiation, if
we use Integer i=1; then the results are different.

public class TestClass {
Integer i=0;
}

size = 5152 bytes.

The reason being Integer i=0; is inferred as Integer i= Integer.value(0);

A cache is initialized with all the possible int values varying from
-128 to 127. The 'i' is initialized with the value zero from the
cache.

If you take the String instantiation,

public class TestClass {
String s=new String("i");
}

it consumes about 40 bytes of memory where as,

public class TestClass {
String s="i";
}

consumes about 16 bytes of memory. It took less bytes since "i" is
from the string pool.

Saturday, December 3, 2011

confirm job search alerts subscription: urgent fresher junior java developer (0-1 yrs.) jobs

Hi! You asked us to send you daily email alerts for these jobs:
» urgent fresher junior java developer (0-1 yrs.) jobs «

To finish creating this alert, please click on the following link:
» confirm alert! «

If you are unable to open the link above, try copying and pasting the following link into your browser:
http://www.simplyhired.co.in/a/job-alerts/confirm/918654/569733148

You will also receive our Job Search Made Simple newsletter filled with tips to help you along every step of your job search. If you would like to unsubscribe from the newsletter, an opt-out link will be provided in your first issue. This will not affect the status of this email alert, so make sure to confirm it above.

If you did not make this request, please ignore and delete this email.

Thanks!
The Simply Hired Team

Wednesday, November 30, 2011

Multiprogramming, Multicomputing, Multiprocessing and Multitasking

Multiprogramming: program may be any set of commands submitted for execution by a user or operator. In multiprogramming, concurrent running (sharing of the processor) is achieved when the operating system identifies the interruption of one program and gets chance to transfer process control to another program.

Multicomputing: A computer made up of several computers. The term generally refers to an architecture in which each processor has its own memory rather than multiple processors with a shared memory. Something similar to parallel computing.
Distributed computing deals with hardware and software systems containing more than one processing element or storage element, concurrent processes, or multiple programs, running under a loosely or tightly controlled regime.

Multitasking: The ability to execute more than one task at the same time, a task being a program. The terms multitasking and multiprocessing are often used interchangeably, although multiprocessing implies that more than one CPU is involved.

In multitasking, only one CPU is involved, but it switches from one program to another so quickly that it gives the appearance of executing all of the programs at the same time.

There are two basic types of multitasking: preemptive and cooperative. In preemptive multitasking, the operating system parcels out CPU time slices to each program. In cooperative multitasking, each program can control the CPU for as long as it needs it. If a program is not using the CPU, however, it can allow another program to use it temporarily

--
Amit Ranjan
Java developer
.............................
P please consider the environment before printing e-mail-- SAVE PAPER!