Skip to main content

Posts

Showing posts with the label JVM

Memory Leak in Java? Does 'static' cause it?

Does 'static' cause Memory Leak in Java? What's memory leak? In simple terms, it's unused but referenced (somehow because the programmer probably unintentionally forgot to remove the references once the use of the object was over) part of the memory. Before we start discussing if 'static' can cause memory leak in Java, let me assure you that whatever you've read about Garbage Collectors in Java, is still valid and it certainly takes care of most (almost all) of the memory allocation/reclaimation of Java objects. But, that alone doesn't remove the possibility of the presence of memory leak in a Java program - just for example, you might not only be using only Java objects in your Java program. Putting it differently, what if you have used some native objects and forgot to reclaim the memory explicitly because that's anyway not going to be taken care by the GC (which takes care of heap memory management only)... right? Now that we agree with the pos...

Does JVM throw Exceptions for Floating-point arithmetic operations?

-- According to 3.8 Floating-Point Arithmetic . The JVM throws no Exception as a result of any floating-point operations. Special values, such as positive and negative infinity or NaN, are returned as the result of suspicious operations such as positive value, negative value and zero division by zero. For example, class Program { public static void main(String[] args) { double d1 = 1.0; double d2 = 0.0; byte b =1; d1 = d1/d2; b = (byte)d1; System.out.print(b); } } The output is -1 and no exception throw. The process involved is: 1.0/0.0 results in Double.POSITIVE_INFINITY; Double.POSITIVE_INFINITY is converted to Integer.MAX_VALUE ('0' followed by 31 '1's) Integer.MAX_VALUE is then cast to byte value, which simply takes the last 8 bits(11111111) and is -1.

Can a Java application have memory leak?

Yes, there could be memory leak in Java applications. Wait a minute, doesn't Java virtual machine have a garbage collector that will collect and free all unreferenced memory automatically? Let's find out in general what memory leaks are, and how they occur in applications. If an application fails to return the not-in-use memory back to the heap, the "lost" memory is called memory leak. Memory leaks occur when the application doesn't free the memory allocated, usually are the objects no longer in use, but the object references are lost. If an object is no longer accessible, there is no way to free its memory. Each time such a leak is re-created, additional memory is used and not freed. Eventually, the process that runs the application will run out of memory and crash. It's true that for other programming languages, such as C/C++, there is not such a thing called garbage collector. The programmer is responsible for freeing the memory when the ...

Why not compile Java for Windows?

Since most Java applets run on PC platform, why not offer a compiled version of Java directly run in Windows without JVM? Users can still use standard Java via JVM, it's just a performance enhancement. That would negate the entire purpose of the java development program. Notice how you asked the question, "...since most...!" That should indicate to you that not all OS's are windows platforms and the purpose of java is to provide a language that can be interpreted(or used) by all OS's. Just because a person can program doesn't mean they will be using a computer that will be of the Intel based family of mpu's. By doing what you suggest would restrict many programmers work to that platform, not to mention the compatibility of browsers and OS's to decypher the programmers intent.  We can still use standard Java through JVM. Because some Java programs are just like windows applications without involving multiple platforms, a compiled version for windows ...

JVM ( Java Virtual Machine )

1.What is JVM? A Java Virtual Machine is a runtime environment required for execution of a Java application.Every Java application runs inside a runtime instance of some concrete implementation of abstract specifications of JVM.It is JVM which is crux of 'platform independent' nature of the language. 2.What is a JVM consisted of? Each time a Java Application is executed then an instance of JVM ,responsible for its running,is created.A JVM instance is described in terms of subsystems, memory areas, data types, and instructions.The block diagram given below,depicts a view of Internal Architecture of JVM : 3.What is a class loader and what is its responsibilities? The Class loader is a subsystem of a JVM which is responsible,predominantly for loading classes and interfaces in the system.Apart from this,a class loader is responsible for the following activities:-Verification of imported types(classes and interfaces)-Allocating memory for class variables and initializing them...