Google+ Badge

Wednesday, 27 January 2016

Possible reasons for outOfMemory error and run time and compile time errors in java

outOfJava Heap space : Java is allowed for limited usage memory. Java is divided into two regions namely, Permanent generation and Heap Space. The size for these two regions are set by JVM. OutOfMemory occurs when you add more data to heap space when it is full.
Reasons :
  • Memory leaks: When you don't specify the memory by yourself. The JVM uses the Garbage collection (GC), here the unused items are cleared in memory and again made ready in other words it automatically checks for unused items and removes them.Memory leaks occurs when GC fails to recognize the unused items and fails to remove them.Thus the java heap space increases indefinitely.

Compile time error -Occurs when the code does not follow the Java semantics and syntactic rules
  •  a class tires to extend more than one class 
  • overloading or overriding is not correct
  • referring to a out scope variable
  • inner class has the same name with enclosing class name
  • when class is not abstract but the methods in it are abstract
  • a private member of class A is referenced by  another class B
  • when creating an instance of an abstract class
  • when change the value of the final member
  • when two class or instance have same name
  • missing brackets
  • missing semicolons
  • access to private fields in other classes
  • missing classes on the classpath (at compile time)
Runtime error -
  • using variable that are actually null (may cause NullPointerException)
  • using illegal indexes on arrays
  • accessing ressources that are currently unavailable (missing files, ...)
  • missing classes on the classpath (at runtime)