Page 52 - Introduction to Programming with Java: A Problem Solving Approach
P. 52
18 Chapter 1 Introduction to Computers and Programming
As shown in Figure 1.7, move your mouse cursor over the Create New Folder icon near the top- right corner of the Save As dialog box. Click the icon. That should cause a new directory to appear in thedirectorytree.ThenameofthenewdirectoryisNew Folderbydefault.TheNew Foldername should be selected/highlighted. Enter myJavaPgms, and as you do so, myJavaPgms should overlay the New Foldername.ClicktheOpenbuttoninthebottom-rightcornerofthedialogbox.Thatshouldcause the new myJavaPgms directory to appear in the Save in: box.
Enter "Hello.java" in the File name: box at the bottom of the dialog box. You must enter "Hello.java" exactly as shown below:
Don’t forget the quotes, the uppercase H, and the lowercase subsequent letters. Click the Save button in the bottom-right corner of the dialog box. That should cause the Save As dialog box to disappear, and the top of the Notepad window should now say Hello.java. Shut down Notepad by clicking on the X in the top-right corner of the Notepad window.
Installing a Java Compiler and the JVM
In the previous subsection, you entered the Hello World program and saved it to a file. Yeah! Normally,
the next step would be to compile the file. Remember what compiling is? That’s when a compiler trans-
lates a source code file into a bytecode file. For our Hello World program, the compiler will translate your
Hello.java source code file into a Hello.class bytecode file. If you’re working in a school’s com- Apago PDF Enhancer
puter lab, chances are pretty good that your computer already has a Java compiler installed on it. If your computer does not have a Java compiler installed on it, you’ll need to install it now in order to complete the hands-on portion of this section.
Normally, if someone is interested in installing the Java compiler (to compile Java programs), they are also interested in installing the JVM (to run Java programs). To make the installation easier, Sun bundles the Java compiler together with the JVM. Sun calls the bundled software the Java Development Kit, or JDK for short.
To install the JDK on your computer, you should follow the installation instructions on the book’s Web site. Go to http://www.mhhe.com/dean and click on the JDK Installation Instructions link. Read the in- structions and install the JDK accordingly. In particular, follow the instructions that describe how to set the PATH variable permanently.
Compiling a Java Program
We’ll next describe how you can compile a program using a command prompt window (also called a con- sole). A command prompt window allows you to enter operating system instructions where the instructions are in the form of words. The words are referred to as commands. For example, on a computer that runs the Windows operating system, the command for deleting a file is del (for delete). On a computer that runs the UNIX or Linux operating system, the command for deleting a file is rm (for remove).
To open a command prompt window on a computer that runs the Windows operating system, click the Start button at the bottom-left corner of your Windows desktop. That should cause a menu to appear. On the menu, click the Run... option. That should cause a Run dialog box to appear. In the Run dialog box’s