Computer Science 268: Introduction to Computer Programming (Java)
Study Guide
Unit 5
Read Chapter 5 of the textbook: Programming in the Large II: Objects and Classes
This chapter introduces the essential topics of object-oriented programming; the object and the class. You have already worked with classes and objects in this course by using the classes provided by Java (i.e., System.out.println()). This chapter covers writing and using classes that we will write.
Section 5.1 Objects, Instance Methods, and Instance Variables
This section introduces and discusses the fundamentals of objects. Introducing objects, classes and instances, as well as some essential elements of the class; the get and set methods. Finally, arrays of objects are discussed.
Read and review this section carefully.
- 5.1.1 Objects, Classes, and Instances
- 5.1.2 Fundamentals of Objects
- 5.1.3 Getters and Setters
- 5.1.4 Arrays and Objects
Section 5.2 Constructors and Object Initialization
This section covers some essential features of classes, including initialization of instance variables, constructors and how memory is managed through “garbage collection.”
Read and review this section carefully.
- 5.2.1 Initializing Instance Variables
- 5.2.2 Constructors
- 5.2.3 Garbage Collection
Section 5.3 Programming with Objects
This section continues the introduction of objects by examining built-in classes and the class Object. It goes on to discuss and provide tips on how to write and use a class, and then discusses object-oriented analysis and design.
Read and review this section carefully.
- 5.3.1 Some Built-in Classes
- 5.3.2 The class “Object”
- 5.3.3 Writing and Using a Class
- 5.3.4 Object-oriented Analysis and Design
Section 5.4 Programming Example: Card, Hand, Deck
This section focuses on one example-based card-playing game. It discusses the design of the game and the necessary classes required to support the game. Read and review it carefully.
Although every programming textbook seems to include some type of card-playing program, you can find other, perhaps more interesting, examples on the Internet. Use the Landing to exchange and discuss other examples you find.
- 5.4.1 Designing the classes
- 5.4.2 The Card Class
- 5.4.3 Example: A Simple Card Game
Section 5.5 Inheritance, Polymorphism, and Abstract Classes
This section covers inheritance, polymorphism and abstract classes.
Read and review this section carefully.
- 5.5.1 Extending Existing Classes
- 5.5.2 Inheritance and Class Hierarchy
- 5.5.3 Example: Vehicles
- 5.5.4 Polymorphism
- 5.5.5 Abstract Classes
Section 5.6 this and super
This section introduces and discusses a few very important Java class keywords, this and super. These keywords are used over and over in object-oriented Java programming, as they form a convenient and clear shorthand for routine tasks.
Read and review this section carefully.
Section 5.7 Interfaces
This section revisits the interface, providing more detail and examples. Interfaces are common and important in Java, as Java does not support multiple inheritance. Interfaces provide one way to approximate this behaviour.
Read and review this section carefully.
- 5.7.1 Defining and Implementing Interfaces
- 5.7.2 Default Methods
- 5.7.3 Interfaces as Types
Section 5.8 Nested Classes
This section covers nested, inner and anonymous inner classes. All are important constructs in creating and using classes in Java programs. Section 5.8.4 revisits lambda expressions, which are beyond the scope of this course.
Read and review sections 5.8.1 through 5.8.3 carefully. Section 5.8.4 is beyond the scope of this course.
- 5.8.1 Static Nested Classes
- 5.8.2 Inner Classes
- 5.8.3 Anonymous Inner Classes
- 5.8.4 Local Classes and Lambda Expressions
It is a good practice to attempt the programming exercises in the textbook, to put the topics you have learned into concrete Java code. This, in turn, allows you to reflect on the material you have read. Skip any exercises relating to topics in Chapter 5 that are not covered in the course.
Resist the temptation to download the programming exercises from the textbook and simply run them. The greatest benefit in learning to program in a new language occurs when you type all the example code yourself.
Typing the code, even for simple examples, engages your brain in the process of writing code, compiling code, running code, and diagnosing and resolving problems that may arise. It is the latter skill—problem solving—that can become the most powerful tool in learning to program.
It is a good practice to review the chapter quizzes in the textbook, as the questions allow you to reflect on the material you have read.