Classes, Part 2: CS 310 Lecture notes

Object-Oriented Programming with Java Lecture Notes

5 February 2009 • Classes, Part 2


This is a feature, not an error. Development projects, particularly for large systems, may want to separate source and class files in different directories. This observation doesn’t justify not checking the directory into which class files are being written, but it does move us closer to a solution.

The -d javac command-line option writes class files into the directory specified by -d’s argument. In addition to writing the class files, javac will also create any package directories it needs.

$ ls
classes  src

$ ls src
C1.java

$ ls classes

$ cat src/C1.java 
package B;

class C1 { }

$ javac -Xlint -d classes src/C1.java

$ ls classes
B

$ ls classes/B
C1.class

$ 

Of course, that doesn’t explain not checking if -d isn’t being used, but at this point: enough.


This page last modified on 24 January 2006.