Lecture 10B
AppletSubdirectory
Jar Files
File Organization
Packages
Access
3rd Party
Packages
Exercises

Lectures

1A: Introduction
1B: Java Intro
2A: BuildingBlocks
2B: Objects
3A: More Objects
3B: Exceptions
       & Threads
4A: Waves
4B: Nuclear &
       Particle
5A: AWT
5B: More AWT
      & Graphics
6A:Detectors &
      Simulation
6B: LHC/Atlas &
     RandomSims    
7A: Swing
7B: Java2D
8A: Java Apps
8B: Dialogs &
    MoreClasses
9A: Java I/O
9B: Utilities,
        Unicode
10A: More
    Threading
10B: File
    Handling
11A: Array,Print,
    Images
11B: SimplePhysics
    Simulation
12A: Tips &
    Techniques
12B: More Tips &
    Techniques
13A: Satellite
    
Simulations
13B: Intro to Java
    Networking
14A: Java Servers
14B: HTTP Server
15A: ServerClient
15B: ServerClient
   Expt.Simulation
16A: Course
          Review
16B: ExerciseTest
        Discussion

    Contacts
    Description
    Exercises
    Index
    Outline
    Q&A
    Resources
    StudentInfoForm
    Student Pages
    What's New

 

Home : Lectures : Lecture10B : Java File Organization
Java File Organization

Java file organization follows these guidelines:

  • CLASSPATH environment variable, needed by javac to find the java classes, points to the class library directory that holds the class archive file.

     set CLASSPATH c:\java\lib\CLASSES.ZIP - 1.0, 1.1
     set CLASSPATH c:\java\jre\lib\rt.jar - 1.2 (default)

  • Classes are usually grouped into Packages, where package names reflect the directory location of the class files:

     myJava.functions -> myJava\functions\*.class


  • File names reflect the directory/package where they reside.

     java.applet.Applet -> java\applet\Applet.class
     myJava.functions.Bessel -> myJava\functions\Bessel.class


  • File name + CLASSPATH gives the path to the file:

     set CLASSPATH c:\java\jre\lib\rt.jar;c:\programs;

    which will locate Bessel.class in

     c:\programs\myJava\functions\Bessel.class

  • Classes can be explicitly named in the code:

     public class myNewBessel extends myJava.functions.Bessel{..

  • Or the import statement indicates into which package/directory the compiler should look for a file

     import myJava.functions.*;
     public class myNewBessel extends Bessel{..

Note: For 1.2 it is no longer necessary to set CLASSPATH for the runtime library. By default, it will be found relative to the directory of the binary files (e.g. c:\java\bin), which is set in the PATH environment variable.

Similarly, in 1.2 if you set the CLASSPATH, it does not need to include the runtime library, e.g. if your use

 set CLASSPATH c:\programs

javac would still look first in c:\java\jre\lib\rt.jar for the runtime files before looking in c:\programs for files not found there.

The classpath can also be set in the command line:

 > java -classpath c:\programs myBesselProgram

Note: the archive files, ZIP or JAR, maintains the file structure. One can think of a JAR file as a file directory within a file.

We can, for example, look at the contents of the rt.jar file that holds most of the core Java classes.

Here we use the jar tool to display some of the files.

Note that the files are listed with their directory structure included. For example, the java/applet/* files correspond to the java.applet package.

 

Home Lectures Resources Index Contacts Students


Physics Simulations with JavaTM
KTH, Kurskod: 5A1418
Curator: Clark S. Lindsey