Two class days
System.out.println—what's the difference?
printlnbegins a new line after what it prints
printlncan have 0 or 1 parameters
- p. 66: Syntax of variable declaration - What does the syntax diagram mean? - Examples? - Reserved words:
final - Listing 2.5: PianoKeys.java - Assignment (
=): - p. 69: syntax - Listing 2.6: Geometry.java - Java is a strongly typed language: each variable must be declared with a type, and can only store values of compatible types. - Declaring constants with
byte= 8 bits signed
short= 16 bits signed
int= 32 bits signed
long= 64 bits signed
float= 32 bits
double= 64 bits
char= character (Unicode?), 16 bits
boolean= logical, 1 bit (at least conceptually)
Page 72: Syntax of a decimal integer literal
Besides primitive types, Java also has reference types (objects).
-(unary, as signs)
%left to right
-(binary, meaning add and subtract) left to right
9.0 / 5.0instead of
9 / 5?
(long) 21 (double) 21 (float) 2.1
Narrowing conversions (to a smaller data type, may lose information) and widening conversions (to a larger data type, usually do not lose information—when might they ever?)
In the second half of this chapter, the content changes from core Java language features to some of the important Java libraries. In addition, we will begin using classes that somebody has already defined. We will look in greater depth at using classes and objects in Chapter 3, and at writing our own classes in Chapter 4. For the time being, we will write only simple classes with a
main method and nothing else.
abc 123 45.67
Scanner in0 = new Scanner(System.in); // stdin Scanner in1 = new Scanner("1 2 3 4"); // "reads" from the string Scanner in2 = new Scanner("friends.data"); // ditto Scanner in3 = new Scanner(new File("friends.data")); // file input
Some colors have names:
paintmethod is run automatically whenever the applet needs to be displayed.
runmethod; but at this stage, we are just using the method inherited from
paintmethod uses methods of the class
java.awt.Graphics(also called a graphics context). We may think of a Graphics object as something that can be drawn or painted on; a "page" for drawing; a graphical output device.
java.awt.Graphics(see Figure 2.12 on p. 99):