Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
Where is my Java class?

Exception 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:

How Java classes are located

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:

java classes and packages

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.
(written 2009-09-24)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
J708 - Java - Packages
  [2865] Relationships between Java classes - inheritance, packaging and others - (2010-07-10)
  [2114] Which Version of Java am I running? - (2009-04-02)
  [754] tar, jar, war, ear, sar files - (2006-06-10)

J709 - Java - Class Access
  [3142] Private and Public - and things between - (2011-01-22)
  [3047] What is a universal superclass? Java / Perl / Python / Other OO languages - (2010-11-13)
  [2535] When should I use Java, Perl, PHP, or Python? - (2009-12-13)
  [874] Who can use which access door? - (2006-09-21)


Back to
Viv.java uses unchecked or unsafe operations - explanation and cure
Previous and next
or
Horse's mouth home
Forward to
Exceptions in Java - why and how
Some other Articles
What is a JVM, a JRE, a JDK - components of the core Java Environment
Looking inside Java classes - javap and javadoc
Sorting Collections of Objects in Java
Exceptions in Java - why and how
Where is my Java class?
Viv.java uses unchecked or unsafe operations - explanation and cure
Java Programming Fundamentals
Automating access to a page obscured behind a holding page
Variable names like i and j - why?
Hello World - a good traditional start to a Java course
4298 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2419_Whe ... lass-.html • PAGE BUILT: Thu Sep 18 15:30:25 2014 • BUILD SYSTEM: WomanWithCat