Programming and Problem Solving with Java

(やまだぃちぅ) #1
2.3 Application Entry, Correction, and Execution | 75

One more thing about blocks and statements: According to the syntax template for a
statement, a field declaration is officially considered to be a statement. A declaration, there-
fore, can appear wherever an executable statement can. In a block, we can mix declarations
and executable statements if desired, but the declaration of any item must come before the
item is used.


{
charch; // Declaration
ch = ‘A’;
System.out.println(ch);
String str; // Declaration
str = “Hello”;
System.out.println(str);
}


In this book, we group the declarations together because we think it is easier to read and,
therefore, better style.


{
// Declarations
char ch;
String str;
// Executable statements
ch = ‘A’;
System.out.println(ch);
str = “Hello”;
System.out.println(str);
}


2.3 Application Entry, Correction, and Execution


Once you have an application written down on paper, you must enter it into the computer
on the keyboard. In this section, we examine the code entry process in general. You should
consult the manual for your particular computer to learn any computer-specific details.


Entering Application Code


The first step in entering code is to get the computer’s attention. With a personal computer,
this usually means turning it on. Workstations connected to a network are usually left run-
ning all the time. You must log onto such a machine to get its attention, which involves en-
tering a user name and a password. The password system protects information that you’ve
stored in the computer from being tampered with or destroyed by someone else.
Once the computer is ready to accept your commands, you tell it that you want to en-
ter code by running the editor. The editor is an application that allows you to create and

Free download pdf