Page 50 - Introduction to Programming with Java: A Problem Solving Approach
P. 50
16 Chapter 1 Introduction to Computers and Programming
And those hidden characters create problems for Java programs. If you attempt to enter a program into a computer using a word processor, your program won’t compile successfully and it certainly won’t run.
Different types of computers have different plain text editors. For example, computers that use Win- dows have a plain text editor called Notepad. Computers that use UNIX or Linux have a plain text editor called vi. Computers that use Mac OS X have a plain text editor called TextEdit. Note: Windows, UNIX, Linux, and Mac OS X are operating systems. An operating system is a collection of programs whose pur- pose is to help run the computer system. In running the computer system, the operating system manages the transfer of information between computer components.
For the rest of this section, we’ll describe how you can enter, compile, and run a program using free, bare-bones tools. You’ll use a plain text editor for entering your program, and you’ll use simple software tools from Sun for compiling and running your program. If you have no interest in using such bare-bones tools, and you prefer instead to stick exclusively with an IDE, then refer to the IDE tutorials on the book’s Web site and feel free to skip the rest of this section. If you’re unsure what to do, we encourage you to try out the bare-bones tools. They’re free and they don’t require as much memory as the IDEs. They serve as a standard baseline that you should be able to use on almost all computers.
Entering a Program into a Computer
We’ll now describe how you can enter a program into a computer using Notepad, the plain text editor that comes with all versions of Microsoft Windows.
Move your mouse cursor on top of the Start button at the bottom-left corner of your Windows desktop.
Click the Start button. (When we ask you to “click” an item, we want you to move your mouse on top of
the item and press the left mouse button.) That should cause a menu to appear. On the menu, move your
Apago PDF Enhancer
mouse on top of the Programs option. That should cause another menu to appear. On that menu, move your mouse on top of the Accessories option. That should cause another menu to appear. On that menu, click on the Notepad option. That should cause the Notepad text editor to appear.
In the newly opened Notepad text editor, enter the source code for your first program. More specifically, click somewhere in the middle of the Notepad window and then enter the seven lines of text that are shown in Figure 1.6. When you enter the text, be sure to type the letters with uppercase and lowercase exactly as shown. For example, enter Hello with an uppercase H and lowercase e, l, l, and o. Use spaces, not tabs, for indentations. Your entered text comprises the source code for what is known as the Hello World program. The Hello World program is the traditional first program for all programming students. It simply prints a hello message. In Chapter 3, we’ll describe the meaning behind the words in the Hello World source code. In this chapter, we’re more interested in hands-on experience, and we show you how to enter, compile, and run the Hello World program.
After entering the source code into the Notepad window, you’ll need to save your work by storing it in a file. To save your source code in a file, click the File menu in the top-left corner of the Notepad window. That should cause a menu to appear. On the menu, select the Save As option. That should cause a Save As dialog box to appear. A dialog box is a small window that performs one task. For this dialog box, the task is to save a file.
Note the File name: box at the bottom of the dialog box. That’s where you’ll enter the name of your file. But first, you should create a directory to store your file in. A directory, also called a folder, is an orga-
4 nizationalentitythatcontainsagroupoffilesandotherdirectories. Moveyourmousecursoroverthedown
4 In the Windows and Macintosh worlds, people tend to use the term “folder.” In the UNIX and Linux worlds, people tend to use the term “directory.” As you’ll see in Chapter 15, Sun uses the term “directory” as part of the Java programming language. We like to follow Sun, and we therefore use the term “directory” rather than “folder.”