Java Reference
In-Depth Information
2.1
Introduction
2.2
Your First Program in Java: Printing a
Line of Text
2.3
Modifying Your First Java Program
2.4
Displaying Text with
printf
2.5
Another Application: Adding
Integers
2.5.1
import
Declarations
2.5.2 Declaring Class
Addition
2.5.3 Declaring and Creating a
Scanner
to
Obtain User Input from the Keyboard
2.5.4 Declaring Variables to Store Integers
2.5.5 Prompting the User for Input
2.5.6 Obtaining an
int
as Input from the
User
2.5.7 Prompting for and Inputting a Second
int
2.5.8 Using Variables in a Calculation
2.5.9 Displaying the Result of the
Calculation
2.5.10 Java API Documentation
2.6
Memory Concepts
2.7
Arithmetic
2.8
Decision Making: Equality and
Relational Operators
2.9
Wrap-Up
Summary | Self-Review Exercises | Answers to Self-Review Exercises | Exercises | Making a Difference
This chapter introduces Java application programming. We begin with examples of pro-
grams that display (output) messages on the screen. We then present a program that ob-
tains (inputs) two numbers from a user, calculates their sum and displays the result. You'll
learn how to instruct the computer to perform arithmetic calculations and save their re-
sults for later use. The last example demonstrates how to make decisions. The application
compares two numbers, then displays messages that show the comparison results. You'll
use the JDK command-line tools to compile and run this chapter's programs. If you prefer
to use an integrated development environment (IDE), we've also posted Dive Into
®
videos
A Java
application
is a computer program that executes when you use the
java
command
to launch the Java Virtual Machine (JVM). Later in this section we'll discuss how to com-
pile and run a Java application. First we consider a simple application that displays a line
of text. Figure 2.1 shows the program followed by a box that displays its output.
1
// Fig. 2.1: Welcome1.java
2
// Text-printing program.
3
4
public class
Welcome1
5
{
6
// main method begins execution of Java application
7
public static void
main(String[] args)
8
{
9
System.out.println(
"Welcome to Java Programming!"
);
10
}
// end method main
11
}
// end class Welcome1
Fig. 2.1
|
Text-printing program. (Part 1 of 2.)