2.1 The Elements of Java Programs | 65
and the computer. You now know enough Java syntax to tell the computer to assign values
to variables and to concatenate strings, but the computer won’t give you the results until you
tell it to display them.
Early computers used printers to display their output. Older programming languages had
output statements, such as printor write, that would type the contents of a variable or a con-
stant on the printer. As technology advanced, printers were replaced by display screens, but
output still appeared on the screen as if it was being typed by a printer, line by line. In the
1970s, computer scientists at the Xerox Palo Alto Research Center developed a new approach
to output in which a program could display separate panels on the screen and print or draw
on each panel independently. The panels, which were called windows, opened a new era in
the design of user interfaces for computer programs.
Today, virtually every computer operating system supports a graphical user interface (GUI)
based on windows. Such interfaces make it much easier for people to use programs, but
they require more work on the part of the programmer than did the old-fashioned printer-
style output. Because Java was developed after the GUI became the standard mechanism for
interactive input and output, it includes built-in features that support the programming of
a user interface. Even so, the programming of such a user interface can still be rather com-
plicated, so we defer coverage of this topic until after we’ve explored more of the basics of
programming. If you are curious about what is involved in GUI programming, you may peek
ahead to Chapter 8.
Here we introduce a very simple way of writing messages on the screen that is similar
to the technique used in older languages. To do so, we use a method call statement.
Calling Methods Methods (the operators associated with objects in the abstract
sense) are implemented as subprograms that are called upon to perform some pre-
defined set of actions. A callto a method is another form of executable statement
in Java. We write the call statement simply by specifying the name of the method,
followed by a list of argumentsenclosed in parentheses. The call causes control of
the computer to jump to the instructions in the method, which may use the val-
ues given to it as arguments. When the method has completed its task, control
of the computer returns to the statement following the call.
Here is the syntax template for a call statement:
As you examine the template, note that the arguments in a call are optional, but the
parentheses are required. We often write call statements of the following form:
methodName();
Method-Name ( Argument , Argument... ) ;
Call
Call A statement that causes a
method to be executed; in Java
we call a method by writing its
name, followed by a list of argu-
ments enclosed in parentheses
Argument An expression used
for communicating values to a
method