Chapter 2: Data and Expressions

Version 3.21

Two class days

Handouts:

(First Day)

(Sec. 2.1) Character string literals

(Sec. 2.2) Variables and assignment

- p. 66: Syntax of variable declaration - What does the syntax diagram mean? - Examples? - Reserved words: int, double, char, 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 final

(Sec. 2.3) Primitive types

Page 72: Syntax of a decimal integer literal

Besides primitive types, Java also has reference types (objects).

(2.4) Expressions

(2.5) Data conversion

Transition

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.


(Second Day)

(2.6) Interactive programs: the Scanner class

(2.7) Graphics

(2.8-2.9) Applets and Drawing Shapes


Discussion


  1. Version log:
    • Version 3.2, 2012 Jan 17. Updated exercises for 7th edition.
    • Version 3.1.1, 2011 Jan 25. Corrected link to Lossy.java.
    • Version 3.1, 2011 Jan 22. Converted to markdown; ...
    • Version 3, 2010 Jan 18. Converted to RST.
    • Version 2, 2009 Jan 21. Revised for 6th edition.