|
A brief guide to developing Java programs with the JDK
You can download programs from the module web site, or type them in using an editor.
The easiest editor to use is Notepad. You can access it from the START button (bottom left corner of the screen):
START => PROGRAMS => ACCESSORIES => NOTEPAD
When you type a Java program into Notepad, save it with the extension .java; for example, if your program has the class name
myprog
then save it in a file called
myprog.java
You can save your programs on the A: drive, or on the network on drive H:, for example in directory
H:\work\data
The Java compiler javac and virtual machine java should be located on the C: drive, in directory
C:\Program Files\jdk1.3\bin
They are command line programs, and you use them by typing their names at the command line.
To open a command window, proceed as follows:
START => PROGRAMS => COMMAND PROMPT
This should open a window with a prompt in it, probably
C:>
The letter C indicates that you are in the root directory on the C: drive. To change to the H: drive, where your programs are, type
H:
The prompt should have changed to H:>, to indicate that you are now on the H: drive.
To change to the directory on H: where you have placed your program files, use the command
cd (change directory)
as follows:
cd \work\data
The prompt should change to
H:\work\data>
(The prompt always shows you which directory (folder) you are in)
To show a list of all your files in the directory, type
dir
To rename a file called fred.java to barney.java, type
ren fred.java barney.java
to delete a file called fred.java type
del fred.java
You should familiarise yourself with these commands for use at the command prompt.
To use the java utilities javac and java, you must first tell the computer where to find them. You do this by typing
Set PATH = C:\Program Files\jdk1.3\bin
exactly as it appears here. You should only have to do this once, at the start of your session.
If for some reason, javac and java aren't in this directory on your machine, get your tutor to locate them,
and type in the correct path to the directory where they are.
To COMPILE a Java program called fred.java, type
javac fred.java
Remember to close the notepad file when compiling otherwise you will get an error message
If there are errors in the program, they will be listed - go back to the editor and fix them!
If there are no errors, then a file called
fred.class
will have appeared in your directory - the Java byte code version of your program.
To RUN this program, type
java fred
Windows
You will probably be working with several windows open
1) The command window, where you type commands as above
2) A window containing Notepad, for editing your programs.
3) You may wish to have the Windows Explorer program available for navigating/ working with your files (copying them, renaming them etc.)
This means that you may have several windows overlapping. To bring one to the front, simply click anywhere in that window.
To minimise a window temporarily, click the little minus sign in its top right corner. Click its icon at the bottom of the screen to restore it.
To close a window permanently, click the little cross in its top right corner.
To expand a window to occupy the entire screen, click the little square in its top right corner.
This little guide should be enough to get you started; ask your lab tutor about anything you don't understand!
|