Java Reference
In-Depth Information
The Java program files that you create must use the extension .java . When you
compile a Java program, the resulting Java bytecodes are stored in a file with the
same name and the extension .class .
Most Java programmers use what are known as Integrated Development
Environments, or IDEs, which provide an all-in-one environment for creating, edit-
ing, compiling, and executing program files. Some of the more popular choices for
introductory computer science classes are Eclipse, jGRASP, DrJava, BlueJ, and
TextPad. Your instructor will tell you what environment you should use.
Try typing the following simple program in your IDE (the line numbers are not
part of the program but are used as an aid):
1 public class Hello {
2 public static void main(String[] args) {
3 System.out.println("Hello, world!");
4 }
5 }
Don't worry about the details of this program right now. We will explore those in
the next section.
Once you have created your program file, move to step 2 and compile it. The com-
mand to compile will be different in each development environment, but the process
is the same (typical commands are “compile” or “build”). If any errors are reported,
go back to the editor, fix them, and try to compile the program again. (We'll discuss
errors in more detail later in this chapter.)
Once you have successfully compiled your program, you are ready to move to step
3, running the program. Again, the command to do this will differ from one environ-
ment to the next, but the process is similar (the typical command is “run”). The diagram
in Figure 1.1 summarizes the steps you would follow in creating a program called
Hello.java.
In some IDEs (most notably Eclipse), the first two steps are combined. In these
environments the process of compiling is more incremental; the compiler will warn
you about errors as you type in code. It is generally not necessary to formally ask
such an environment to compile your program because it is compiling as you type.
When your program is executed, it will typically interact with the user in some
way. The Hello.java program involves an onscreen window known as the console.
Console Window
A special text-only window in which Java programs interact with the user.
The console window is a classic interaction mechanism wherein the computer dis-
plays text on the screen and sometimes waits for the user to type responses. This is
known as console or terminal interaction. The text the computer prints to the console
window is known as the output of the program. Anything typed by the user is known
as the console input.
 
Search WWH ::




Custom Search