rent-now

Rent More, Save More! Use code: ECRENTAL

5% off 1 book, 7% off 2 books, 10% off 3+ books

9781590594575

Beginning Java Objects : From Concepts to Code

by
  • ISBN13:

    9781590594575

  • ISBN10:

    1590594576

  • Edition: 2nd
  • Format: Paperback
  • Copyright: 2005-06-20
  • Publisher: Apress
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $69.99 Save up to $48.39
  • Digital
    $46.80*
    Add to Cart

    DURATION
    PRICE
    *To support the delivery of the digital material to you, a digital delivery fee of $3.99 will be charged on each digital item.

Summary

Among Java's many attractive features as a programming language, its object-oriented nature is key to creating powerful, reusable code and applications that are easy to maintain and extend. To take advantage of these capabilities, you're going to need not only to master the syntax of the Java language, but also to gain a practical understanding of what objects are all about, and more importantly, how to structure a Java application from the ground up to make the most of objects. With Beginning Java Objects: From Concepts to Code, you will learn all three! It uses a central case study to illustrate how a UML model is developed and is suitable both for individual self-study and as a university-level textbook.

Table of Contents

About the Author xxiii
About the Technical Reviewer xxv
Acknowledgments xxvii
Preface xxix
Introduction xxxi
PART 1 The ABCs of Objects
Abstraction and Modeling
3(12)
Simplification Through Abstraction
3(1)
Generalization Through Abstraction
4(5)
Organizing Abstractions into Classification Hierarchies
5(3)
Abstraction As the Basis for Software Development
8(1)
Reuse of Abstractions
9(1)
Inherent Challenges
10(2)
What Does It Take to Be a Successful Object Modeler?
11(1)
Summary
12(3)
Some Java Basics
15(50)
Why Java?
15(9)
Java Is Architecture Neutral
16(4)
Java Provides ``One-Stop Shopping''
20(2)
Java Is Object-Oriented from the Ground Up
22(1)
Practice Makes Perfect
23(1)
Java Is an Open Standard
23(1)
Java Is Free!
23(1)
A Reminder Regarding Pseudocode vs. Real Java Code
24(1)
Anatomy of a Simple Java Program
24(4)
Comments
24(2)
The Class Declaration
26(1)
The main Method
27(1)
The ``Mechanics'' of Java
28(4)
Compiling Java Source Code into Bytecode
30(1)
Executing Bytecode
31(1)
A Behind-the-Scenes Look at the JVM
32(1)
Primitive Types
32(1)
Variables
33(2)
Variable Naming Conventions
34(1)
Variable Initialization
35(1)
The String Type
36(1)
Case Sensitivity
37(1)
Java Expressions
38(4)
Arithmetic Operators
38(2)
Relational and Logical Operators
40(1)
Evaluating Expressions and Operator Precedence
41(1)
The Type of an Expression
42(1)
Automatic Type Conversions and Explicit Casting
42(2)
Loops and Other Flow-Control Structures
44(9)
if Statements
45(2)
switch Statements
47(2)
for Statements
49(2)
while Statements
51(1)
Jump Statements
52(1)
Block-Structured Languages and the Scope of a Variable
53(1)
Printing to the Screen
54(4)
print vs. println
56(1)
Escape Sequences
57(1)
Elements of Java Style
58(5)
Proper Use of Indentation
58(3)
Use Comments Wisely
61(1)
Placement of Braces
61(1)
Descriptive Variable Names
62(1)
Summary
63(2)
Objects and Classes
65(30)
Software at Its Simplest
65(3)
Functional Decomposition
66(1)
The Object-Oriented Approach
67(1)
What Is an Object?
68(3)
State/Data/Attributes
69(1)
Behavior/Operations/Methods
70(1)
What Is a Class?
71(3)
A Note Regarding Naming Conventions
73(1)
Declaring a Class, Java Style
73(1)
Instantiation
74(1)
Encapsulation
75(1)
User-Defined Types and Reference Variables
76(1)
Naming Conventions for Reference Variables
77(1)
Instantiating Objects: A Closer Look
77(8)
Garbage Collection
84(1)
Objects As Attributes
85(7)
A Compilation Trick: ``Stubbing Out'' Classes
88(1)
Composition
89(2)
The Advantages of References As Attributes
91(1)
Three Distinguishing Features of an Object-Oriented Programming Language
92(1)
Summary
92(3)
Object Interactions
95(72)
Events Drive Object Collaboration
95(2)
Declaring Methods
97(10)
Method Headers
98(1)
Method Naming Conventions
98(1)
Passing Arguments to Methods
99(1)
Method Return Types
100(1)
An Analogy
101(1)
Method Bodies
102(1)
Features May Be Declared in Any Order
103(1)
return Statements
104(3)
Methods Implement Business Rules
107(1)
Objects As the Context for Method Invocation
108(7)
Java Expressions, Revisited
111(1)
Capturing the Value Returned by a Method
111(1)
Method Signatures
112(2)
Choosing Descriptive Method Names
114(1)
Method Overloading
115(1)
Message Passing Between Objects
116(2)
Delegation
118(1)
Obtaining Handles on Objects
119(3)
Objects As Clients and Suppliers
122(2)
Information Hiding/Accessibility
124(8)
Public Accessibility
125(1)
Private Accessibility
126(1)
Publicizing Services
127(1)
Method Headers, Revisited
128(1)
Accessing the Features of a Class from Within Its Own Methods
129(3)
Accessing Private Features from Client Code
132(6)
Declaring Accessor Methods
133(1)
Recommended ``Get''/``Set'' Method Headers
134(3)
The ``Persistence'' of Attribute Values
137(1)
Using Accessor Methods from Client Code
137(1)
The Power of Encapsulation Plus Information Hiding
138(9)
Preventing Unauthorized Access to Encapsulated Data
139(1)
Helping to Ensure Data Integrity
139(1)
Limiting ``Ripple Effects'' When Private Features Change
140(3)
Using Accessor Methods from Within a Class's Own Methods
143(4)
Exceptions to the Public/Private Rule
147(3)
Exception #1: Internal Housekeeping Attributes
147(1)
Exception #2: Internal Housekeeping Methods
148(1)
Exception #3: ``Read-Only'' Attributes
149(1)
Exception #4: Public Attributes
150(1)
Constructors
150(11)
Default Constructors
150(1)
Writing Our Own Explicit Constructors
151(1)
Passing Arguments to Constructors
152(1)
Replacing the Default Parameterless Constructor
153(1)
More Elaborate Constructors
154(1)
Overloading Constructors
155(2)
An Important Caveat Regarding the Default Constructor
157(1)
Using the ``this'' Keyword to Facilitate Constructor Reuse
158(3)
Software at Its Simplest, Revisited
161(2)
Summary
163(4)
Relationships Between Objects
167(46)
Associations and Links
167(6)
Multiplicity
170(1)
Multiplicity and Links
171(2)
Aggregation and Composition
173(1)
Inheritance
174(35)
Responding to Shifting Requirements with a New Abstraction
175(1)
(Inappropriate) Approach #1: Modify the Student Class
176(3)
(Inappropriate) Approach #2: ``Clone'' the Student Class to Create a Graduate Student Class
179(1)
The Proper Approach (#3): Taking Advantage of Inheritance
180(1)
The ``is a'' Nature of Inheritance
181(2)
The Benefits of Inheritance
183(1)
Class Hierarchies
184(2)
The Object Class
186(1)
Is Inheritance Really a Relationship?
186(1)
Avoiding ``Ripple Effects'' in a Class Hierarchy
187(1)
Rules for Deriving Classes: The ``Do's''
187(1)
Overriding
188(3)
Reusing Superclass Behaviors: The ``super'' Keyword
191(3)
Rules for Deriving Classes: The ``Don'ts''
194(2)
Private Features and Inheritance
196(3)
Inheritance and Constructors
199(6)
A Few Words About Multiple Inheritance
205(4)
Three Distinguishing Features of an OOPL, Revisited
209(1)
Summary
209(4)
Collections of Objects
213(60)
What Are Collections?
213(3)
Collections Are Defined by Classes and Must Be Instantiated
214(1)
Collections Organize References to Other Objects
214(2)
Collections Are Encapsulated
216(1)
Three Generic Types of Collection
216(3)
Ordered Lists
216(1)
Dictionaries
217(1)
Sets
218(1)
Arrays As Simple Collections
219(8)
Declaring and Instantiating Arrays
220(1)
Accessing Individual Array Elements
221(1)
Initializing Array Contents
222(1)
Manipulating Arrays of Objects
223(4)
A More Sophisticated Type of Collection: The ArrayList Class
227(13)
Using the ArrayList Class: An Example
228(1)
Import Directives and Packages
228(3)
The Namespace of a Class
231(2)
User-Defined Packages and the Default Package
233(1)
Generics
234(1)
ArrayList Features
235(3)
Iterating Through Arraylists
238(1)
Copying the Contents of an ArrayList into an Array
238(2)
The HashMap Collection Class
240(6)
The TreeMap Class
246(2)
The Same Object Can Be Simultaneously Referenced by Multiple Collections
248(1)
Inventing Our Own Collection Types
249(10)
Approach #1: Designing a New Collection Class from Scratch
249(1)
Approach #2: Extending a Predefined Collection Class (MyIntCollection)
249(5)
Approach #3: Encapsulating a Standard Collection (MyIntCollection2)
254(4)
Trade-offs of Approach #2 vs. Approach #3
258(1)
Collections As Method Return Types
259(1)
Collections of Derived Types
260(1)
Revisiting Our Student Class Design
261(9)
The courseLoad Attribute of Student
262(1)
The transcript Attribute of Student
262(3)
The transcript Attribute, Take 2
265(5)
Our Completed Student Data Structure
270(1)
Summary
270(3)
Some Final Object Concepts
273(60)
Polymorphism
274(7)
Polymorphism Simplifies Code Maintenance
279(2)
Three Distinguishing Features of an Object-Oriented Programming Language
281(1)
The Benefits of User-Defined Types
281(1)
The Benefits of Inheritance
281(1)
The Benefits of Polymorphism
281(1)
Abstract Classes
282(8)
Implementing Abstract Methods
286(1)
Abstract Classes and Instantiation
287(2)
Declaring Reference Variables of Abstract Types
289(1)
An Interesting Twist on Polymorphism
289(1)
Interfaces
290(23)
Implementing Interfaces
293(3)
Another Form of the ``Is A'' Relationship
296(1)
Interfaces and Casting
297(3)
Implementing Multiple Interfaces
300(3)
Interfaces and Casting, Revisited
303(1)
Interfaces and Instantiation
303(1)
Interfaces and Polymorphism
304(1)
The Importance of Interfaces
304(9)
Static Features
313(14)
Static Variables
314(3)
A Design Improvement: Burying Implementation Details
317(1)
Static Methods
318(1)
Restrictions on Static Methods
319(2)
Revisiting the Syntax of Print Statements
321(1)
Utility Classes
321(1)
The final Keyword
322(3)
The Static Import Facility
325(1)
Custom Utility Classes
326(1)
Summary
327(6)
PART 2 Object Modeling 101
The Object Modeling Process in a Nutshell
333(10)
The ``Big Picture'' Goal of Object Modeling
333(4)
Modeling Methodology = Process + Notation + Tool
334(3)
Jacquie's Recommended Object Modeling Process, in a Nutshell
337(4)
Thoughts Regarding Object Modeling Software Tools
338(2)
A Reminder
340(1)
Summary
341(2)
Formalizing Requirements Through Use Cases
343(12)
What Are Use Cases?
344(2)
Functional vs. Technical Requirements
344(1)
Involving the Users
345(1)
Actors
346(4)
Identifying Actors and Determining Their Roles
346(1)
Diagramming a System and Its Actors
347(3)
Specifying Use Cases
350(1)
Matching Up Use Cases with Actors
351(1)
To Diagram or Not to Diagram?
351(2)
Summary
353(2)
Modeling the Static/Data Aspects of the System
355(54)
Identifying Appropriate Classes
356(11)
Noun Phrase Analysis
356(5)
Refining the Candidate Class List
361(4)
Revisiting the Use Cases
365(2)
Producing a Data Dictionary
367(1)
Determining Associations Between Classes
368(4)
Identifying Attributes
372(1)
UML Notation: Modeling the Static Aspects of an Abstraction
372(14)
Classes, Attributes, and Operations
372(4)
Relationships Between Classes
376(6)
Reflecting Multiplicity
382(4)
Object Diagrams
386(2)
Associations As Attributes
388(1)
Information ``Flows'' Along an Association ``Pipeline''
389(6)
``Mixing and Matching'' Relationship Notations
395(2)
Association Classes
397(3)
Our ``Completed'' Student Registration System Class Diagram
400(6)
Metadata
406(1)
Summary
407(2)
Modeling the Dynamic/Behavioral Aspects of the System
409(22)
How Behavior Affects State
410(5)
Events
412(3)
Scenarios
415(4)
Scenario #1 for the ``Register for a Course'' Use Case
416(2)
Scenario #2 for the ``Register for a Course'' Use Case
418(1)
Sequence Diagrams
419(5)
Using Sequence Diagrams to Determine Methods
424(2)
Communication Diagrams
426(2)
Revised SRS Class Diagram
428(1)
Summary
429(2)
Wrapping Up Our Modeling Efforts
431(10)
Testing the Model
431(1)
Revisiting Requirements
432(2)
Reusing Models: A Word About Design Patterns
434(3)
Summary
437(4)
PART 3 Translating an Object Blueprint into Java Code
Rounding Out Your Java Knowledge
441(126)
Java-Specific Terminology
441(3)
Java Application Architecture
444(2)
Java Archive (JAR) Files
446(4)
Creating a JAR File
447(1)
Inspecting the Contents of a JAR File
448(1)
Using the Bytecode Contained Within a JAR File
448(1)
Extracting Content from a JAR File
449(1)
``Jarring'' Entire Directory Hierarchies
449(1)
Javadoc Comments
450(7)
The Object Nature of Strings
457(13)
Operations on Strings
457(3)
Strings Are Immutable
460(2)
The StringBuffer Class
462(1)
The StringTokenizer Class
462(3)
Instantiating Strings and the String Literal Pool
465(4)
Testing the Equality of Strings
469(1)
Message Chains
470(2)
Object Self-Referencing with ``this''
472(1)
Java Exception Handling
473(28)
The Mechanics of Exception Handling
475(9)
Catching Exceptions
484(5)
Interpreting Exception Stack Traces
489(1)
The Exception Class Hierarchy
490(3)
Catching the Generic Exception Type
493(1)
Compiler Enforcement of Exception Handling
494(2)
Taking Advantage of the Exception That We've ``Caught''
496(1)
Nesting of try/catch Blocks
496(1)
User-Defined Exception Types
497(3)
Throwing Multiple Types of Exceptions
500(1)
Enum(eration)s
501(8)
Enumerating Choices Prior to J2SE 5.0
508(1)
Providing Input to Command Line-Driven Programs
509(13)
Accepting Command-Line Arguments: The args Array
510(1)
Introducing Custom Command-Line Flags to Control a Program's Behavior
511(5)
Using the Wrapper Classes for Input Conversion
516(2)
Accepting Keyboard Input
518(4)
Features of the Object Class
522(10)
Determining the Class That an Object Belongs To
522(1)
Testing the Equality of Objects
523(4)
Overriding the equals Method
527(3)
Overriding the toString Method
530(2)
A Deeper Look Behind the Scenes of the JVM
532(9)
The JVM's Class Loader
532(1)
The -verbose Option
533(4)
The Static Nature of main(...)
537(1)
Import Directives, Revisited
537(2)
Static Initializers
539(2)
The Date Class
541(6)
Accessibility, Revisited
547(5)
Default Accessibility of a Feature
547(1)
Public vs. Nonpublic Classes
547(5)
Variable Initialization, Revisited
552(2)
Inner Classes
554(3)
Additional J2SE 5.0 Enhancements
557(7)
Formatted Output
558(1)
Formatted Input
559(1)
Variable Arguments (Varargs)
560(4)
Summary
564(3)
Transforming Your Model into Java Code
567(52)
Suggestions for Getting the Maximum Value from This and Subsequent Chapters
567(1)
The SRS Class Diagram Revisited
568(49)
The Person Class (Specifying Abstract Classes)
571(3)
The Student Class (Reuse Through Inheritance, Abstract Class Extension, Delegation)
574(8)
The Professor Class (Bidirectional Relationships)
582(2)
The Course Class (Reflexive Relationships, Unidirectional Relationships)
584(3)
The Section Class (Representing Association Classes, Public Static Final Attributes, Enums)
587(8)
Delegation Revisited
595(5)
The Schedule Of Classes Class
600(2)
The TranscriptEntry Association Class (Static Methods)
602(3)
The Transcript Class
605(1)
The SRS Driver Program
606(11)
The Importance of Model--View and Model--Data Layer Separation
617(1)
Summary
618(1)
Rounding Out Your Application, Part 1: Adding a Data Access Layer
619(62)
An Overview of Upcoming SRS Enhancements
621(1)
Approaches to Object Persistence
621(3)
The Basics of File I/O in Java
624(7)
Reading from a File
624(2)
Writing to a File
626(3)
Exception Handling with File I/O
629(2)
Populating the Main SRS Collections
631(8)
The ScheduleOfClasses Collection
631(1)
Two New Encapsulated Collection Classes: CourseCatalog and Faculty
631(3)
Initializing the SRS Collections from Record-Oriented Data Files
634(3)
Persisting Student Data
637(2)
Read vs. Write Access to the Data Files
639(1)
Configuring Applications with the Java Properties Class
639(5)
The FileNames.properties File
640(1)
Accessing System Properties
641(3)
Defining Custom Exceptions for the SRS
644(1)
Encapsulating Persistence Details
645(24)
Introducing the SRSDataAccess Class
645(3)
Initializing the ScheduleOfClasses Collection
648(4)
Initializing the Faculty Collection
652(3)
Initializing the CourseCatalog Collection
655(2)
Initializing a Student's State
657(3)
Persisting the State of a Student
660(1)
Streamlining the SRS Driver Class
661(8)
The Importance of Model--Data Access Layer Separation
669(9)
Objects and Databases
670(1)
Using the JDBC API: A Conceptual Overview
671(3)
Retrofitting the SRS with Database Access
674(4)
Our SRS Modifications, Revisited
678(1)
Summary
679(2)
Rounding Out Your Application, Part 2: Adding a Presentation Layer
681(92)
Java GUIs: a Primer
682(10)
Components
682(1)
Containers
683(1)
Model--View Separation
684(4)
AWT vs. Swing Components
688(4)
Crafting the View/Presentation of a Java GUI
692(34)
JFrames
692(4)
Positioning a Frame on the Screen
696(1)
Explicitly Positioning a Frame on the Screen
697(1)
Centering a Frame on the Screen
698(2)
Adding Components to a JFrame
700(2)
JPanels
702(1)
Common Component Properties and Behaviors
702(4)
Layout Fundamentals
706(1)
BorderLayout
706(5)
GridLayout
711(6)
FlowLayout
717(2)
JLabels
719(1)
JTextFields and JPasswordFields
719(3)
JButtons
722(1)
JLists
723(3)
A Simple Calculator Example
726(3)
An Improved Application Architecture for GUIs
729(5)
Adding a ``Test Scaffold'' main() Method
733(1)
Other Interesting AWT/Swing Components to Explore
734(1)
Java Event Handling
735(26)
Events: Basic Concepts
735(3)
Basic Event Types
738(1)
Creating and Registering Listeners
739(3)
Adding Behavior to Our Calculator
742(4)
Combining Listeners: Utilizing the ActionEvent
746(2)
Closing a Window, Revisited
748(3)
Adapter Classes vs. Listener Interfaces
751(3)
Selecting an Item from a JList
754(7)
More Container Types
761(8)
JDialog
761(5)
One-Step Dialog Boxes with JOptionPane
766(3)
Reusable Custom Components
769(2)
Summary
771(2)
SRS, Take 3: Adding a GUI
773(58)
Our SRS Code Road Map
773(2)
Preparing a Concept of Operations
775(8)
The SRS Concept of Operations
776(7)
The MainFrame Class
783(20)
Planning the ``Look'' of MainFrame: Getting Creative with GridLayout
783(1)
Coding the ``Look'' of MainFrame
784(5)
Adding Behaviors to MainFrame
789(14)
The PasswordPopup Class: Sharing Information Across Windows/Classes
803(2)
The SRS Driver Class, Significantly Streamlined
805(1)
An Overview of J2EE
806(20)
The Downside of Desktop Application Deployment
807(1)
The Upside of Web Deployment
808(5)
What Is J2EE?
813(1)
What Is a Servlet?
814(2)
What Is a JavaServer Page?
816(3)
J2EE, Model View Controller-Style
819(3)
N-Tier Architectures
822(1)
What Are EJBs?
822(3)
Dispelling J2EE Myths
825(1)
The Relevance of What You've Learned in This Book to J2EE
826(1)
Review of the Architecture of an ``Industrial-Strength'' Java Application
826(3)
Summary
829(2)
Next Steps
831(8)
Jacquie's ``Tried and True'' Approach to Learning Java Properly
832(1)
Taming the Technology Tidal Wave
833(1)
Other Recommended Reading
834(1)
Your Comments, Please!
835(4)
PART 4 Appendixes
APPENDIX A Suggestions for Using This Book As a Textbook
839(4)
Recommended Teaching Approaches
839(1)
Suitability of Java As a Teaching Language
840(1)
Some Final Recommendations
840(3)
APPENDIX B Alternative Case Studies
843(6)
Case Study #1: Prescription Tracking System
843(2)
Background
843(1)
Simplifying Assumptions
844(1)
Case Study #2: Conference Room Reservation System
845(2)
Background
845(1)
Goals for the System
846(1)
Case Study #3: Blue Skies Airline Reservation System
847(2)
Background
847(1)
Other Simplifying Assumptions
848(1)
APPENDIX C Setting Up Your Java Development Environment
849(16)
The Java Software Development Kit
849(1)
Testing Your Installation
850(2)
Troubleshooting Your Installation
852(9)
PATH and CLASSPATH Settings
852(5)
Common Compilation Errors
857(3)
Common Run-Time Errors
860(1)
Using the Online Java Documentation with Windows
861(1)
Special Tips for Using Microsoft Windows Command Prompts
862(3)
Capturing Program Output to a File
863(1)
Resizing the Command Prompt Window
863(2)
APPENDIX D Downloading and Compiling the Book's Source Code
865(2)
APPENDIX E Note to Experienced C++ Programmers
867(6)
No More Pointers!
867(1)
Dynamic vs. Static Object Creation
868(1)
Exception Handling
869(1)
``Breaking the OO Rules'' with C++
869(1)
Platform Portability
870(1)
Abstract Methods and Abstract Classes
870(1)
Other Simplifications
870(3)
APPENDIX F How Polymorphism Works Behind the Scenes (Static vs. Dynamic Binding)
873(6)
Static Binding
874(1)
Dynamic Binding
875(4)
APPENDIX G Collections Prior to J2SE 5.0
879(12)
Summary of 5.0 Collection Enhancements
879(1)
Constraining Collection Contents
880(1)
Iterating Through Collections
881(3)
Managing Primitive Types with Collections
884(2)
The Iterator Class
886(2)
Using the -Xlint:unchecked Compiler Option
888(3)
APPENDIX H Programming 101, and the Role of a Compiler
891(6)
A LEGOs Analogy
891(1)
The Compiler's Job in a Nutshell
892(5)
Index 897

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Rewards Program