Department of Mathematics and Computer Science

Using JDK - Summary

  • Create a folder (directory) for the project. I'll call it Example, in what follows.
  • Inside Example, create two subfolders (subdirectories), call one src and the other class. In src you will place the source code you write, and the compiled versions of this will go in class.
  • Use an editor, WordPad, NotePad, or some other one, type your class definitions, and save them in src. Make sure you save them as text (txt) files, and make sure they have a file type of java.
  • Open the Command window, and change the working directory to be Example/src. Remember, you do this using cd. Typing cd .. moves up one level, and typing cd Name moves you down one level, into the subdirectory Name. At any point, the command dir (ls in Linux) will show the contents of the current working directory.
  • When the working directory is Example/src, compile what you typed. For this, enter
  • javac -d ../class *.java
  • The command javac is the compile command. The -d specifies the directory in which the compiled code will go. The part ../class specifies that this directory should be the class directory (it moves the working directory from src, up one level, then down into class). Finally, *.java says you want everything in src whose file type is java to be compiled.
  • If there are errors during the compile stage, go back to your editor and correct them.
  • If there are no errors, change the working directory to class, by typing cd ../class
  • Now run your program by typing java Something, where Something is the class you defined having main in it.
  • If there are errors at runtime, return to your source code, correct them, and recompile. Corrections are entered using your editor. To recompile, you must first change the working directory back to src by typing cd ../src.

Last modified: Oct 13, 2011

Text Only Version of Site | Make This Website Talk