Page 133 - Introduction to Programming with Java: A Problem Solving Approach
P. 133
Integer.parseInt converts the read-in string to an int value, and Double.parseDouble con- verts the read-in string to a double value. Integer and Double are wrapper classes. parseInt and parseDouble are wrapper class methods. We’ll describe wrapper classes and their methods in Chapter 5.
I/O for the Remainder of the Book
For the GUI track sections and for the GUI chapters at the end of the book, we’ll of course use GUI win- dows for I/O. But for the remainder of the book, we’ll use console windows. We use console windows for the remainder of the book because that leads to simpler programs. Simpler programs are important so we can cut through clutter and focus on newly introduced material. But if you’ve decided that you love all things GUI and you can’t get enough of it, feel free to convert all our console-window programs to GUI-window programs. To do so, replace all of our output code with showMessageDialog calls, and replace all of our input code with showInputDialog calls.
Summary
• Comments are used for improving a program’s readability/understandability.
• The System.out.println method prints a message and then moves the screen’s cursor to the next
line. The System.out.print method prints a message and leaves the cursor on the same line as the
printed message.
• Variables can hold only one type of data item and that type is defined with a variable declaration
statement.
• An assignment statement uses the = operator, and it puts a value into a variable.
• An initialization statement is a combination of a declaration statement and an assignment statement. It
declares a variable’s type and also gives the variable an initial value.
• Variables that hold whole numbers should normally be declared with the int data type or the long
data type.
• Variables that hold floating-point numbers should normally be declared with the double data type.
If you’re sure that a variable is limited to small floating-point numbers, it’s OK to use the float data
type.
• Named constants use the final modifier.
• There are two types of integer division. One type finds the quotient (using the / operator). The other
type finds the remainder (using the % operator).
• Expressions are evaluated using a set of well-defined operator precedence rules.
• The cast operator allows you to return a different-data-type version of a given value.
• Use an escape sequence (with a backslash) to print hard-to-print characters such as the tab character.
• A reference variable stores a memory address that points to an object. An object is a collection of re-
lated data wrapped in a protective shell.
• The String class provides methods that can be used for string processing.
• The Scanner class provides methods that can be used for input.
Review Questions
§3.2 “I Have a Dream” Program
1. What does this chapter’s Dream.java program do?
2. What are the filename extensions for Java source code and bytecode, respectively?
Apago PDF Enhancer
Review Questions 99