Tuesday, 31 December 2013

Java Errors: ClassNotFoundError, NoClassDefFoundError, UnsupportedClassVersionError, LinkageError, ClassFormatError

As per JVM's parent-delegation class loading model a class can be loaded by either a bootstrap class loader or user defined class loader. During class loading the virtual machine can throw following errors and for the given reasons:
  • NoClassDefFoundError
    • If bootstrap class loader is directly invoked by the virtual machine and it is unable to load the binary data for the requested type.
  • ClassNotFoundError
    • If a user-defined class loader delegates to the bootstrap class loader or to a user-defined class loader which is then unable to load the binary data for the requested type, then the ClassNotFoundError is thrown. 

  • ClassFormatError
    •  If the class is located or produced but not in a proper structure
    • If the class does not contain a superclass and is not class Object.
  •  UnsupportedClassVersionError
    • If the binary data is produced but is not part of a recognized version.
  • LinkageError
    • If class name already appears in the current class loader's name space.