Where is my Java class?
Archive - Originally posted on "The Horse's Mouth" - 2009-09-24 08:33:36 - Graham EllisException in thread "main" java.lang.NoClassDefFoundError: Gerald
OK - so where did Java look, and where should it have looked?
Java looks for classes in each of the locations in the CLASSPATH environment variable in turn - each of those locations being either a directory or a .jar file which contains a directory structure.
Within Java classes, import statements may be added which will have Java look in those extra locations relative to each member of the CLASSPATH. Take a look at this diagram:

With three elements on the CLASSPATH, and four imports in a class, further classes will be loaded from 3 * (4 + 1) = 15 different places [Don't forget that there's always an implicit import *; to load from current package!]. It's little wonder, then, that if you get your CLASSPATH and imports wrong that you'll be left asking "where did it load THAT form" or "why couldn't it find THAT?"
There's a further layer - as shown in the diagram - that classes and class members may be generally visible (i.e. public)or they may also be restricted - to protected, to package (the default and never stated) or private ... so that another reason that your class can't be loaded can be that it's there ... but the JVM's not allowed to use it.
While we're on packages and classes:

In essence, a "package" is a directory of code and a "class" is a file of code. The example shows some of the classes and packages that are provided with the standard Java Runtime Environment (JRE). They're all in the java package (extended ones in the enterprise edition are in javax), which has subpackages such as lang (general language stuff), io (input / output) and util (utilities). Withing java.lang you have a whole lot of classes such as String - or its full name java.lang.String ... in this case, Strings handling unicode character strings.