The following table shows the major differences between the Static Class Loading and Dynamic Class Loading in Java.
Static Class Loading | Dynamic Class Loading | |
1 | The process of loading a class using java’s new operator is called static class loading. | The process of invoking the functions of a class loader at run time is called dynamic class loading. |
2 | Static class loading is applicable when the name of the class which is to be loaded is known to the JVM, and the class name can be placed in the class file. | Dynamic class loading occurs when piece of code requests the JVM to load a class by using the class name as String, during execution. The most common way is to use the Class.forName()method. |
3 | A NoClassDefFoundExceptionis thrown if a class is referenced with Java’s new operator. | A ClassNoFoundException is thrown when an application tries to load in class through its string name using the Class.forName() method. |
4 | Example: class simpleClass { public static void main(String args[]) { Animal a = new Animal(); } } | Example: class simpleClass { public static void main(String args[]) { String name = “java.util.Date”; Class.forName(name); } } |
Related Articles:
Difference between Array and ArrayList in Java
Difference between Abstract Class and Interface in Java
Difference between String and StringBuffer/StringBuilder in Java
Difference between HashMap and HashTable in Java
Difference between Csharp and Java
Difference between ArrayList and Vector in Java
Difference between Method Overloading and Method Overriding in Java
Difference between ‘is-a’ relationship and ‘has-a’ relationship in Java
Difference between C++ and Java
Difference between Array and ArrayList in Java
Difference between Abstract Class and Interface in Java
Difference between String and StringBuffer/StringBuilder in Java
Difference between HashMap and HashTable in Java
Difference between Csharp and Java
Difference between ArrayList and Vector in Java
Difference between Method Overloading and Method Overriding in Java
Difference between ‘is-a’ relationship and ‘has-a’ relationship in Java
Difference between C++ and Java