Blakes 21 Days Chapter 1 Document


Day 1, Getting Started with Java

  WEEK 1 - The Java Language  
     
1 Getting Started with Java 9
2 The ABCs of Programming 37
3 Working with Objects 67
4 Lists, Logic, and Loops 95
5 Creating Classes and Methods 125
6 Pachages, Interfaces, and Other Class Features 157
7 Exceptions and Threads 191

There are pages numbered from 1 to 6 that are before Day 1

Day 1 - Getting Started with Java

The Java Language

History of the Language

Introduction to Java

Selecting a Development Tool

Object-Oriented Programming

Objects and Classes

Attributes and Behavior

Attributes of a Class of Objects

Behavior of a Class of Objects

Creating a Class

    Top
    020 To begin your first class, run NetBeans and start a new prgram.
  1. Choose the menu command File, New File. The New File dialog appears.
  2. In the Categories pane, choose Java.
  3. In the File Types pane, choose Empty Java File and click Next. The Empty Java File dialog opens.
  4. In the Class Name text field, enter MarsRobot. The file you're creating is shown in the Created File field, which can't be edited. This file has the name MarsRobot.java.
  5. Click Finish.

Listing 1.1 - The Fill Text of MarsRobot.java

The Explanation

Running the Program

Listing 1.2 The Full Text of MarsApplication.java

137

Figure 1.1 - The output of the MarsApplication class. - goes here

135

From my NetBeans

141

The Explanation

Organizing Classes and Class Behavior

Inheritance - is a mechanism that enables one class to inhert the behavior and attributes of another class

Figure 1.2 - A class hierarchy. - goes here

138

Creating a Class Hierarchy

Figure 1.3 - The basic Robot hierarchy. - goes here

139

Figure 1.4 - Two-legged and four-legged walking robots. - goes here

139a

Inheritance in Action

Figure 1.5 - How methods are located in a class hierarchy. - goes here

139b

Figure 1.6 - Overriding methods. - goes here

139c

Interfaces - is a collection of methods that indicate a class has some behavior in addition to what it inherits from its superclasses

Packages - enable groups of classes to be referrenced more easily in other classes



Summary

Q & A

Quiz

Questions

  1. What is another word for class?
    1. Object
    2. Template
    3. Instance
  2. When you create a subclass, what must you define about that class?
    1. Nothing. Everything is defined already.
    2. Things that are different from its superclass
    3. Everything about the class
  3. What does an instance method of a class represent?
    1. The attributes of that class
    2. The behavior of that class
    3. The behavior of an object created from that class
  4. reserve

Answers

  1. B. A class is an abstract template used to create objects that are similar to each other.
  2. B. You define how the subclass is different from its superclass.
  3. C. Instance methods refer to a specific object's behavior. Class methods refer to the behavior of all objects belonging to that class.

Certification Practice

  1. All objects created from the same class must be identical.
  2. All objects created from the same class can have different attributes than each other.
  3. An object inherits attributes and behavior from the class used to create it.
  4. A class inherits attributes and behavior from its subclass.

Exercises

  1. In the main() method of the MarsRobot class, create a second MarsRobot robot named opportunity, set up its instance variables, and display them.
  2. Create an inheritance hierarchy for the pieces of a chess set.


End of Day One



From Version 23