Part 2. Object-Oriented Programming

 
[Page 211]
The Goddess Chalchihuitlicue, found in the Valley of Mexico, 1300-1500 AD (stone), Aztec / Muse de l'Homme, Paris, France / Bridgeman Art Library.

In Part 1, "Fundamentals of Programming," you learned how to write simple Java applications using primitive data types, control statements, methods , and arrays, all of which are features commonly available in procedural programming languages. Java, however, is an object-oriented programming language that uses abstraction, encapsulation, inheritance, and polymorphism to provide great flexibility, modularity, and reusability for developing software. In this part of the book you will learn how to define, extend, and work with classes and their objects.


[Page 212]

Prerequisites for Part 2

Optional GUI sections are provided at the end of Chapters 710 in Part 2, while a complete introduction to GUI programming is presented in Part 3. This serves two purposes: (1) GUI can be covered early to stimulate student interest in programming; (2) GUI components are excellent examples to demonstrate object-oriented programming. The optional GUI sections can be used as additional examples to teach OOP.

The text I/O in Chapter 8, "Strings and Text I/O," can be covered whenever text I/O is needed.

Exception handling and binary I/O can be covered after Chapter 9, "Inheritance and Polymorphism."

Part 3, "GUI Programming," may be intertwined with Part 2. You can cover GUI programming in Chapters 12 and 13, "GUI Basics" and "Graphics," after you have covered abstract classes in Chapter 10, "Abstract Classes and Interfaces."

Interfaces in Chapter 10, "Abstract Classes and Interfaces," can be covered just before introducing Chapter 14, "Event-Driven Programming."

The sections in Chapter 11 , "Object-Oriented Design," can be covered selectively. For example, if you want to use sequence diagrams to model dynamic behaviors, you can cover sequence diagrams at that time.


 

Chapter 7 Objects and Classes

 

Chapter 8 Strings and Text I/O

 

Chapter 9 Inheritance and Polymorphism

 

Chapter 10 Abstract Classes and Interfaces

 

Chapter 11 Object-Oriented Design

[Page 213]

Chapter 7. Objects and Classes

Mayan God Shel, Mexico. Photographer: Philip Coblentz. Courtesy Brand X Pictures.

Objectives

  • To understand objects and classes, and use classes to model objects (7.2).

  • To use UML graphical notations to describe classes and objects (7.2).

  • To learn how to declare a class and how to create an object of a class (7.3).

  • To understand the role of constructors when creating objects (7.3).

  • To distinguish between object reference variables and primitive data type variables (7.4).

  • To use classes in the Java library (7.5).

  • To understand the difference between instance and static variables and methods (7.6).

  • To declare private data fields with appropriate get and set methods for data field encapsulation to make classes easy to maintain (7.77.8).

  • To create immutable objects from immutable classes (7.9).

  • To develop methods with object arguments (7.10).

  • To determine the scope of variables in the context of a class (7.11).

  • To use the keyword this to refer to the calling object (7.12).

  • To store and process objects in arrays (7.13).

  • To apply class abstraction to develop software (7.147.17).

  • (Optional GUI) To create windows using JFrame (7.18).


[Page 214]

7.1. Introduction

Programming in procedural languages like C, Pascal, BASIC, Ada, and COBOL involves choosing data structures, designing algorithms, and translating algorithms into code. An object-oriented language like Java combines the power of procedural languages with an added dimension that provides more flexibility, modularity, clarity, and reusability through abstraction, encapsulation, inheritance, and polymorphism.

In procedural programming, data and operations on the data are separate, and this methodology requires sending data to methods. Object-oriented programming places data and the operations that pertain to them within a single entity called an object ; this approach solves many of the problems inherent in procedural programming. The object-oriented programming approach organizes programs in a way that mirrors the real world, in which all objects are associated with both attributes and activities. Using objects improves software reusability and makes programs easier to develop and easier to maintain. Programming in Java involves thinking in terms of objects; a Java program can be viewed as a collection of cooperating objects.

This chapter introduces declaring classes, creating objects, manipulating objects, and making objects work together.

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net