Thursday, March 30, 2017

Difference between ClassNotFoundException and NoClassDefFoundError in java

NoClassDefFoundError :-

For hard coded class names at runtime if the corresponding .class  file is not available then we will get RuntimeExcption saying NoClassDefFoundError which is unchecked .  

Ex :-
Test test=new Test();

Ataruntime if test.class frile is not abalible then we will get RuntimeException saying NoclassDefFoundError :Test


ClassNotFounndException :- 

For dynamically provided vlass names at  runtime if the corresponding .class fine not abalible then we will get RuntimeException saying ClassNotFoundException which is checked exception.

Ex :- Object o=Class.forName(args[0]).newInstance();

Java Test,Student


At runtime if Student.class file not available then we will get RuntimeException saying ClassNotFoundException : Student 

No comments:

Post a Comment