18 January 2007 Note: Here are the instructions I wrote up a few years ago, and have slightly modified to reflect java 1.5. I haven't tested them out recently yet, though, so your mileage may vary.
In order to compile and run Java on Windows, one must either download an Integrated Development Environment (IDE) which allows you to develop programs in Java, or download the free Java Development Kit (JDK) from Sun.
If you use an IDE, you will have to read instructions that come with the IDE on how to write, compile, and run code.
If you install Sun's JDK, here are a few hints on how to use it.
Install the JDK in the default location at the top level of the C: drive for best results. Make a folder in your 'My Documents' folder called CSC170, and make a folder inside that for each assignment. In each assignment folder, copy or create a compile.bat and a run.bat file in order to invoke the compiler and the Java Virtual machine respectively. The contents of the compile.bat file should be:
c:\jdk1.5.0\bin\javac -classpath .;c:\jdk1.5.0\jre\lib\rt.jar MyJavaSource.java @pauseThe contents of the run.bat file should be:c:\jdk1.5.0\bin\java -classpath .;c:\jdk1.5.0\jre\lib\rt.jar MyJavaSource @pauseThis will allow you to compile and run your programs without ever having to manually invoke the DOS command line window. When you double click on the .bat file, it automatically brings up a DOS window and executes the command in the current folder. The DOS window also remains present after it has finished so that you can read that your compile succeeded, your compilation errors, or view the running of your program. In order to copy text from the DOS window, you should use the selection button on the button bar (it looks like the dotted outline of a rectangle), select the text you wish to copy, and then hit the 'enter' key. You may then paste this text into a text editor of your choice. Notepad seems to be perfectly adequate for this purpose. I have also found that by right-clicking in my assignment folder, and creating a new text document from the pop-up menu that appears, and then immediately renaming it to SomeJavaClass.java I avoid the .txt naming problem that can frequently occur with Notepad.Here's a picture of my test folder with .bat files after doing a compile:
![]()
Here's a picture of my DOS window after running my test program. I've circled the selection button in light blue:
![]()
Please note that the .bat files are each a single command to execute either the compiler or the Java Virtual Machine. The
c:\jdk1.5.0\bin\javacpart of the command is the name of the tool to be used, in this case the compiler ('javac' means java compiler). The-classpath .;c:\jdk1.5.0\jre\lib\rt.jarpart of the command tells the tool that it should look in the current directory (the single dot) and the rt.jar file in the JRE's library directory in order to find source files and already existing classes. The final part of the command is the name of the file to which to apply this tool. In the above example it isMyJavaSource.java, but you should change this to the name of the file which you are compiling. When you are creating a run.bat file, you should name the class, not the file, and so in this case the run.bat file saysMyJavaSource(without the .java at the end).