0 votes
in Java by

What is the difference between ClassNotFoundException and NoClassDefFoundError? As We know that there are following similarities, that's by i am little bit confused.

  • ClassNotFoundException and NoClassDefFoundError  classes are used at run-time.
  • ClassNotFoundException and NoClassDefFoundError are used by java classpath.

1 Answer

0 votes
by (4.4k points)

There are following difference between ClassNotFoundException and NoClassDefFoundError:-
1) A ClassNotFoundException is thrown when Java went looking for a particular class by name and could not load successfully it. A NoClassDefFoundError is thrown when Java went looking for a class that was linked into some existing code, but couldn't find it for one reason or another and something has gone Badly Wrong.

2) ClassNotFoundException:- It occurs when class loader could not find the required class in class path.
NoClassDefFoundError:- This is thrown when at compile time the required classes are present, but at run time the classes are changed or removed or class's static initializes threw exceptions.

3) ClassNotFoundException: thrown when an application tries to load in a class through its name, but no definition for the class with the specified name could be found.

NoClassDefFoundError: thrown if the Java Virtual Machine tries to load in the definition of a class and no definition of the class could be found.

Share:- Whatsapp Facebook Facebook

Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.