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 onesrcand the otherclass.Insrcyou will place the source code you write, and the compiled versions of this will go inclass. - 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 ofjava. - Open the Command window, and change the working directory to be
Example/src. Remember, you do this usingcd.Typingcd ..moves up one level, and typingcd Namemoves you down one level, into the subdirectoryName. At any point, the commanddir(lsin 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
javacis the compile command. The-dspecifies the directory in which the compiled code will go. The part../classspecifies that this directory should be theclassdirectory (it moves the working directory fromsrc, up one level, then down intoclass). Finally,*.javasays you want everything insrcwhose file type isjavato 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 typingcd ../class - Now run your program by typing
java Something, whereSomethingis the class you defined havingmainin 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
srcby typingcd ../src.
Last modified: Oct 13, 2011




