UNIX Primer

Home | Primer Home


Running Java Programs

Although we recommend that you use Dr. Java, it is also important that you know how to compile a java program from the command line.

To compile a piece of java code (a file with a .java extension) into a java class file (with a .class extension), you can run the 'javac' command. Once the class file is created, you can execute it by running the 'java' command on it.

Although we won't go into detail about it here, another useful command is 'javadoc', which reads specially formatted comments out of your java files and creates nice-looking web documentation for them. For more information about how this works, check out the javadoc tool home page on Sun's website.

Related Commands:

NameMeaningPurpose
javac Java Compile Compiles a file containing java code to a class file containing java bytecode. Reports any syntax errors or other compilation problems to the user.
Syntax
javac <filename>
Notes
  • Include the filename extension with this command.

NamePurpose
java To run a compiled java class file. Reports runtime errors and uncaught exceptions to the user.
Syntax
java <filename>
Notes
  • Do NOT include the filename extension with this command.

NameMeaningPurpose
javadoc Java Document Generates automatic documentation from specially formatted comments in a given file.
Syntax
javadoc <filename>
Notes
  • Will create documentation for all contained files if you specify a directory name.
  • See the javadoc home page for more details.

Congratulations! You now know enough to 'get by' in UNIX. However, to truly master it, you need to know a lot more. At this point, it is recommended that you at least take a look at the first advanced lesson in this primer, as it contains valuable information for anyone using a UNIX system. Good luck!


Designed by D. Kaminsky
Edited by Diana Palsetia
© University of Pennsylvania, 2008