The JavaDoc API descriptions of those classes are pretty detailed when it comes to the circumstances in which these exceptions are thrown. Have you read those, and if so, which parts are unclear to you?
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Yes, it is a compile time or a checked exception. Class names are resolved during compile time and if a class by that name is not found, it throws this exception.
1. There's no such thing as a "compile-time" exception.
I refer to it as that because it helps me remember as checked exceptions are checked for by the compiler at compile time as a part of the contract to make sure they are either handled using try-catch or declared using the throws keyword. To be precise, yes, there is nothing called as a compile time exception. Its either checked or unchecked Exception.
Jeff Verdegan wrote:
Mansukhdeep Thind wrote:2. All exceptions that your code may have to deal with are thrown at runtime, never at compile-time. Including ClassNotFoundException.
Couldn't agree more. All exceptions are thrown at runtime. I shouldn't have used the wordthrown. Apologies for that. What I meant was what I just wrote above. I need to get better at expressing myself though i.e to mean what I say and to say what I mean.
I am not at all sure but the basic difference is - ClassNotFoundException is fired when a Java Class is not found by the compiler and NoClassDefFoundError checks about the Class file. is it?? please comment and correct.
Ishan Pandya wrote:I am not at all sure but the basic difference is - ClassNotFoundException is fired when a Java Class is not found by the compiler and NoClassDefFoundError checks about the Class file. is it?? please comment and correct.
Not, that is not correct. Both occur at runtime (as I already stated). If you want to know the difference, read the documentation.