Skip to main content

Posts

Showing posts from April, 2017

Everything About ClassNotFoundException Vs NoClassDefFoundError

We know Java is an Object Oriented Programming Language and almost everything is an object in Java and in order to create an object we need a class. While executing our program whenever JVM find a class, First JVM will try to load that class into memory if it has not done it already. For Example, If JVM is executing below the line of code, before creating the object of Employee class JVM will load this class into memory using a ClassLoader. Employee emp = new Employee(); In above example, JVM will load the Employee class because it is present in the execution path and JVM want to create an object of this class. But we can also ask JVM to just load a class through its string name using Class.forName() or ClassLoader.findSystemClass() or ClassLoader.loadClass() methods. For Example below the line of code will only load the Employee class into memory and do nothing else. Class.forName("Employee"); Both ClassNotFoundException  and  NoClassDefFoundError occur when a particular c