Packages: Sudhir Talasila Preeti Navale
Packages: Sudhir Talasila Preeti Navale
Sudhir Talasila
Preeti Navale
Introduction
• Packages are nothing more than the way we
organize files into different directories according
to their functionality, usability as well as category
they should belong to .
• The CLASSPATH
– List of directories and/or jar files. The compiler will look in
these directories for any precompiled files it needs.
– The CLASSPATH can be set as an environmental variable or
specified on the command line using –classpath option.
– The CLASSPATH is also used by the Java Virtual Machine
to load classes.
Compile Package Classes
c:\project\elevator>java ElevatorSimulation
Exception in thread "main" java.lang.NoClassDefFoundError:
ElevatorSimulation
– The program runs successfully by running the program from
c:\project directory.
Incorrect CLASSPATH
• Running the program with incorrect CLASSPATH
– Example: If the directory c:\project is not added to the
CLASSPATH, and if you run the program, we will get the
following error message
c:\project>java eElevator.ElevatorSimulation
Exception in thread "main" java.lang.NoClassDefFoundError:
elevator/ElevatorSimulation
Solution
• Add c:\project to the CLASSPATH, and rerun the
program.
• The program is launched successfully without any
error messages.
References
• Object – Oriented Software Development
Using Java 2nd Edition – Xiaoping Jia
• Java Language Specifications - Chapter 7
Packages
http://java.sun.com/docs/books/jls/second_edi
tion/html/packages.doc.html