Yes but it's not at all clear what the difference is, is it?
Actually on further investigation it turns out that NoClassDefFoundError is thrown if the apparent name of the class according to its filename isn't the same as the binary name compiled into it.
See ClassLoader.defineClass().
> ClassNotFoundException is thrown if you directly use
> a class which can't be found.
I think this must create compile time error wihich is "can not find the symbol", is not it ?
> NoClassDefFoundError is thrown if you directly use a
> class which directly or indirectly uses another class
> which can't be found.
This also can create compile time error
> No. We are discussing exceptions and errors which
> arise at run-time out of code which obviously must
> have compiled correctly at some point. Otherwise we
> couldn't be running it.
I know what you are discussing about.
I mean that : For instance you are using the instance of Frame class without importing java.awt package. So according to your claim(opinion), this create a run time error called ClassNotFoundException or NoClassDefFoundError. However, I claim that this can create compile time error absolutely called "can not find symbol". So I mean that be careful while doing generilizations.
Regards,
Mert
ClassNotFoundException: is thrown when classloader tries to load a class with class name as string and could not be found. Its dyanamic loading of a class.
NoClassDefFoundError: is thrown if the Java Virtual Machine or a ClassLoader instance tries to load the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
The important difference it that one's a checked Exception, the other is a run time error.
ClassNotFoundException is thrown in circumstances where it's likely to be due to a configuration file error or even someone typing in the wrong name.
NoClassDefFound is thrown only if your program is flawed or wrongly installed.
ClassNotFoundException is likely to be something your program can recover from. The other is not.
> I know what you are discussing about.
> I mean that : For instance you are using the instance
> of Frame class without importing java.awt package. So
> according to your claim(opinion), this create a run
> time error called ClassNotFoundException or
> NoClassDefFoundError.
That wasn't not my 'claim (opinion)' at all, of course, as the quoted text makes perfectly clear. It was just a straw man and it was irrelevant.
> So I mean that be careful while doing generilizations.
So, I mean, be careful when you attribute claims to other people that they haven't made.
And let's try to stick to the point, shall we?