|
Beginner’s Guide to Web Development – Testing the JDK
To make sure your installation of the JDK (Java Development Kit) is correct, some simple tests need to be run. First, you will need to
write a simple Java program. Before you write the program, you will need to create a directory in which to store it. Thus, create a directory
called "classes" on your C drive, or if you installed the JDK under a different drive letter, create the directory on that drive.
The rest of this section will use the "c" drive in the examples. Change "c" to your drive letter if applicable.
Now it is time to write the program. Open your favorite text editor, or for simplicity’s sake, just go to your Start>Run menu
window and type "notepad". This will bring up the notepad text editor. Copy and paste or type the following lines into the text editor.
public class TestClass
{
public static void main (String args[])
{
System.out.println ("hello");
}
}
If you have copied the above, make sure that the text copied over correctly. Sometimes quotation marks and other
special characters do not copy correctly. Next, save this file into your c:\classes directory under the name TestClass.java.
Make sure that you capitalize the ‘T’ and ‘C’ and TestClass and put the .java extension on the class. After completing the above,
you should have the file entitled "TestClass.java" in your c:\classes directory.
Now it is time to see if you can run the file. To do this, you will need to open a DOS prompt. This can be done in different
ways depending on your operating system. See Opening a DOS Window for details. After opening the DOS prompt, a window should
appear entitled "MS-DOS Prompt" or "Command Prompt", depending on your operating system. Type the following in this window:
cd c:\classes
This will change your current directory to the classes directory. Inside this directory is the file you created called TestClass.java.
Before you can run this file, you will need to compile it. The JDK that you downloaded contains a utility that compiles .java files.
This utility is called "javac". To run this utility, type the following:
c:\jdk\bin\javac TestClass.java
This will create a TestClass.class file in your classes directory. This file is the compiled version of the TestClass.java file that
you created. Now it is time to run the class. The JDK also contains a utility to run class files. This utility is called "java".
To invoke this utility, type the following:
c:\jdk\bin\java TestClass
After typing the above, the word "hello" should be printed out in your DOS prompt window. If "hello" appears, your
environment is set up correctly and you are ready to move on.
This concludes testing the JDK. Now it's time to install Tomcat, which is the software we will use to run JavaServer Pages.
|