Running Programs

After you have compiled your source files into bytecode using the javac command, you are ready to execute them. To do so, you need to follow these directions.

Navigate to the directory that stores your top-level package. For the examples in this book, that is a directory called C:\garage\classes. If you are using an IDE, your classes directory might be different. For example, an Eclipse project might store files at C:\eclipse\workspace\garage\classes. In any case, it is the directory that contains your packages, and where you specify the compiler to output code.

Run the java command, passing it the fully qualified name of your class (including all of the package names).

Make sure to use the . separator for packages—not your system ...

Get Java Garage now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.