|
|
The Java 2 Software Development Kit Many of you will use the Java Software Development Kit from Sun Microsystems, Inc. to compile and execute your Java programs. From this page you can download and install the Java 2 SDK (v 1.3) for a Windows 95/98/NT/2000 environment, as well as learn how to use it. Other information about the Java SDK can be found at www.javasoft.com. Download and Install the Java 2 SDK Student's note: you should only be performing this installation to set up a Java development environment on your own personal computer. Your school's system administrator will install it on any of your school's lab computers. Consult your instructor if you have questions about this process. Clicking on the following link will allow you to download a setup program that will help you install the Java SDK. Store the setup program (which is called j2sdk1_3_0-win.exe) somewhere where you can find it later, such as your desktop. Download the Java 2 SDK for Windows If you have any problems downloading the setup program, you can alternatively retrieve it from the following Sun Microsystems site: The setup program is approximately 30 MB in size, so the download may take a few minutes, depending on your connection. After completing the installation process, you can remove this setup program from your computer. Note: if you have an earlier version of the Java SDK installed on your computer, you should remove it before installing the new one to avoid any complications. You should also exit any programs currently running before installing the Java SDK. Once you have downloaded the setup program, you are ready to install the Java SDK on your computer. Find the setup program and double click on its icon to execute it. Then follow the screen directions. We encourage you to accept the default options, unless you have a good reason to deviate from them. You will step through various screens that ask you to accept licensing agreements and confirm other settings. Eventually the setup program will store all of the necessary files on your computer. In the last step, you are prompted to reboot your computer before the installation will take effect, but you may want to wait until you set the PATH variable before rebooting.
To make it easy to use the tools of the Java SDK, you'll want to modify your PATH system variable to include the directory where you have installed them. The PATH variable is a list of directories where your system looks for commands when you try to execute them. If you don't add the location of the SDK to your PATH, you'll have to specify where it is every time you want to use it. For a computer running Windows 95 or Windows 98, you modify the PATH variable by editing the autoexec.bat file. You can edit this file by clicking Start, then Run, then enter sysedit (for Windows 95) or msconfig (for Windows 98). Choose the window displaying the autoexec.bat file. Edit the PATH statement to include the bin directory for the Java SDK. For a computer running Windows NT or Windows 2000, you modify the PATH variable using the System entry on the Control Panel. Pick the Advanced tab and press the Environment Variables button. If you chose the default location when installing the Java SDK, you'll add the following to your PATH: C:\jdk1.3\bin Therefore, your final PATH may look something like this: C:\windows;C:\windows\command;C:\jdk1.3\bin You may have to reboot your system to complete the installation and set the path.
As described in the Chapter 1 of your textbook, you need an editor to enter your program (source code) initially and make modifications to it, a compiler to turn a Java source code program into Java bytecode, and an interpreter to execute the bytecode. These steps are shown graphically below:
The compiler and interpreter, among other tools, are part of the Java Software Development Kit. There is no editor provided with the Java SDK. Your instructor may tell you to use a particular editor. Or you could use NotePad or WordPad, which are already available on most computers running Windows. Or you could use one of several editors that can be found on the web. After typing in a program using an editor, you must save the program in a file name with a .java extension. The file name should have the same name as the class that is stored in the file. For example, if your class is called MyProgram, it should be stored in a file called MyProgram.java. Once you've prepared and stored your program, you can attempt to compile and execute it. The Java SDK is a set of command-line tools, meaning that you simply bring up a DOS window and enter particular commands to use the tools. The compiler is called javac (which stands for java compiler), and the interpreter is simply called java. In the DOS window, move to the directory in which you have stored your program. Let's assume you've stored your programs in a directory called programs at the top level of the C: drive. To move into this folder, you use the cd command, which stands for change directory: C:\> cd programs Then you can compile the program using the javac command: C:\programs\> javac MyProgram.java Note that you include the .java extension on the file when you compile it. If the compiler detects errors, they will be listed at this point and no bytecode will be created. You'll have to go back to the editor and fix the errors, save the program again, then return to the DOS window and recompile. If you have a clean compile (no errors generated), then the compiler creates a bytecode version of the class, storing it in a file with the same file name with a .class extension. So a clean compile of MyProgram.java will result in a new file called MyProgram.class.You can verify the existance of the bytecode file by executing a dir command. Note: do not attempt to edit or view a bytecode file, which is in a binary format and is not human readable. To execute the program, submit the bytecode to the interpreter. Do not include the .class extension when using the interpreter. For example: C:\programs\> java MyProgram At this point, you may have run-time errors or logical errors (see Chapter 1), in which case you'll have to go back to the editor and fix the program. Always test your programs thoroughly to try to find any problems that exist. If you have other questions about using the Java SDK, ask your instructor.
|
|
Send questions and comments to john.lewis@villanova.edu
|