M/F 2:30-3:20   
in G01 Gates Hall

CS 1130: Transition to OO Programming

Spring 2016

Part 3. Types and Expressions Part 5. Objects and Classes

Module 1, Part 4

Variables, Declarations, and Assignments

This part 4 introduces you to variables, the Java declaration (of a variable), and the assignment statement. We also talk about strong versus weak typing — Java is strongly typed, while Matlab, C, and Python are weakly typed.


Contents

1. The variable and its declaration

Web Lecture

Reading: Lecture Notes (Lecture Slides)
Gries/Gries, Section 1.2, pp. 26-29.

Comments: Java's concept of variable is similar to that in most other languages: a named box with a value in it. In Java, a variable must be declared before it is used, and it has a type.


2. The assignment statement

Web Lecture

Reading: Lecture Notes (Lecture Notes)
Gries/Gries, Section 1.2, pp. 26-29.

Comments: Execution of an assignment statement stores a value in a variable. Learn also about the initializing declaration and narrower and wider types.


3. Promoting and casting

Reading: Lecture Notes
PLive lectures 6-2.3..4
Gries/Gries, Section 1.3.1, pp. 19-20

Comments: In several circumstances, Java will automatically promote a value to a wider type. In addition, you, the programmer can explicitly cast a value from one type to another. This lecture explains how and why this is done.


4. char as an integral type.

Reading: ProgramLive lectures 6-5-2..4
Gries/Gries, Sec. 6.5, pp. 224-225

Comments: You are not responsible for this material, but reading it will help you understand how characters are represented.


5. Conditional expression

Reading: Lecture Notes

Comments: The conditional expression evaluates one of two subexpressions based on a condition (a boolean expression). You will find it useful in the first assignment.


6. Safety and strong typing

Reading: Lecture Notes

Comments: This little essay will give you some understanding of why strong typing is used in DrJava.


7. Self-help exercises

Reading: Gries/Gries, Section 1.2.1, pp. 29-30.

Comments: It is important that you fully understand declarations and the assignment statement. These exercises will help you in this endeavor.