Home > Store

Objects First with Java: A Practical Introduction Using BlueJ, 5th Edition

Register your product to gain access to bonus material or receive a coupon.

Objects First with Java: A Practical Introduction Using BlueJ, 5th Edition

Book

  • Sorry, this book is no longer in print.
Not for Sale

About

Features

  • Use of BlueJ to get students started on object-oriented programming:
    • Created specifically for teaching, the BlueJ environment has a strong emphasis on visualization which helps students understand class structure and the nature of objects. 
    • BlueJ uses UML-like diagrams to represent classes and their relationships.  The ease of BlueJ makes the objects-first style of object-oriented programming possible from the beginning.
    • Easy to use, free of charge, and readily available, BlueJ enables students to manipulate objects and call methods as a first exercise.
  • Accompanying CD with JDK, BlueJ, a BlueJ tutorial and code for all the projects.
  • A useful website (Author's Companion Website: http://www.bluej.org/objects-first/) with resources for students and lecturers, including:
    • Program style guide for all examples in the book.
    • Links to material of further interest.
    • PowerPoint slides that can be downloaded and used as OHTs (lecturers only).
    • Solutions to exercises (lecturers only).
    • Additional activities, exercises and projects for use in teaching (lecturers only).
    • Discussion forum for students and teachers.

Description

  • Copyright 2012
  • Edition: 5th
  • Book
  • ISBN-10: 0-13-249266-0
  • ISBN-13: 978-0-13-249266-9

Objects First with Java: A Practical Introduction Using BlueJ, 5e, is ideal for introductory courses in Java/Introduction to Programming and Object-Oriented Programming and for beginning programmers.
 
This is the only introductory programming textbook that uses the BlueJ integrated development environment (IDE) to teach introductory and object-oriented programming principles using Java. Its close integration with the BlueJ development environment allows this book to focus on key aspects of object-oriented software development from day one. BlueJ's clear visualization of classes and objects means that readers can immediately appreciate the differences between them, and gain a much better understanding of the nature of an object than they would from simply reading source code. Unlike traditional textbooks, the chapters are not ordered by language features but by software development concepts. Language features are introduced as a response to the problems to be solved. A large number of different, interesting projects are used to provide variety and avoid the monotony of a running problem. This book takes an “objects first” approach to teaching the traditionally difficult concepts of objects in a manipulative visual form. Throughout, the emphasis is on developing a practical approach to programming, with students encouraged to add code to existing programs rather than working with an intimidating sheet of blank paper. This textbook is printed in four-color to aid pedagogy and reader learning.

 

Sample Content

Table of Contents

Foreword xiii
Preface xiv
List of projects discussed in detail
in this book xxiii
Acknowledgments xxv
Part 1 Foundations of object orientation 1
Chapter 1 Objects and classes 3

1.1 Objects and classes 3
1.2 Creating objects 4
1.3 Calling methods 5
1.4 Parameters 6
1.5 Data types 7
1.6 Multiple instances 8
1.7 State 8
1.8 What is in an object? 9
1.9 Java code 10
1.10 Object interaction 12
1.11 Source code 12
1.12 Another example 14
1.13 Return values 14
1.14 Objects as parameters 14
1.15 Summary 16
Chapter 2 Understanding class definitions 18
2.1 Ticket machines 18
2.1.1 Exploring the behavior of a naïve ticket machine 19
2.2 Examining a class definition 20
2.3 The class header 22
2.3.1 Keywords 23
2.4 Fields, constructors, and methods 23
2.4.1 Fields 24
2.4.2 Constructors 27
2.5 Parameters: receiving data 28
2.5.1 Choosing variable names 30
2.6 Assignment 30
2.7 Methods 31
2.8 Accessor and mutator methods 33
2.9 Printing from methods 36
2.10 Method summary 38
2.11 Summary of the naïve ticket machine 38
2.12 Reflecting on the design of the ticket machine 39
2.13 Making choices: the conditional statement 42
2.14 A further conditional-statement example 44
2.15 Scope highlighting 45
2.16 Local variables 46
2.17 Fields, parameters, and local variables 48
2.18 Summary of the better ticket machine 49
2.19 Self-review exercises 50
2.20 Reviewing a familiar example 51
2.21 Calling methods 54
2.22 Experimenting with expressions: the Code Pad 55
2.23 Summary 58
Chapter 3 Object interaction 62
3.1 The clock example 62
3.2 Abstraction and modularization 63
3.3 Abstraction in software 64
3.4 Modularization in the clock example 64
3.5 Implementing the clock display 65
3.6 Class diagrams versus object diagrams 66
3.7 Primitive types and object types 67
3.8 The ClockDisplay source code 67
3.8.1 Class NumberDisplay 68
3.8.2 String concatenation 72
3.8.3 The modulo operator 73
3.8.4 Class ClockDisplay 73
3.9 Objects creating objects 77
3.10 Multiple constructors 78
3.11 Method calls 79
3.11.1 Internal method calls 79
3.11.2 External method calls 79
3.11.3 Summary of the clock display 81
3.12 Another example of object interaction 81
3.12.1 The mail-system example 82
3.12.2 The this keyword 83
3.13 Using a debugger 85
3.13.1 Setting breakpoints 85
3.13.2 Single stepping 87
3.13.3 Stepping into methods 88
3.14 Method calling revisited 88
3.15 Summary 89
Chapter 4 Grouping objects 92
4.1 Building on themes from Chapter 3 92
4.2 The collection abstraction 93
4.3 An organizer for music files 94
4.4 Using a library class 95
4.4.1 Importing a library class 97
4.4.2 Diamond notation 98
4.4.3 Key methods of ArrayList 98
4.5 Object structures with collections 98
4.6 Generic classes 100
4.7 Numbering within collections 101
4.7.1 The effect of removal on numbering 102
4.7.2 The general utility of numbering with collections 103
4.8 Playing the music files 104
4.8.1 Summary of the music organizer 106
4.9 Processing a whole collection 106
4.9.1 The for-each loop 107
4.9.2 Selective processing of a collection 109
4.9.3 A limitation of using strings 111
4.9.4 Summary of the for-each loop 111
4.10 Indefinite iteration 112
4.10.1 The while loop 112
4.10.2 Iterating with an index variable 114
4.10.3 Searching a collection 115
4.10.4 Some non-collection examples 118
4.11 Improving structure–the Track class 119
4.12 The Iterator type 122
4.12.1 Index access versus iterators 124
4.12.2 Removing elements 125
4.13 Summary of the music-organizer project 126
4.14 Another example: An auction system 128
4.14.1 Getting started with the project 129
4.14.2 The null keyword 130
4.14.3 The Lot class 130
4.14.4 The Auction class 131
4.14.5 Anonymous objects 134
4.14.6 Chaining method calls 135
4.14.7 Using collections 136
4.15 Flexible-collection summary 138
4.16 Fixed-size collections 139
4.16.1 A log-file analyzer 139
4.16.2 Declaring array variables 142
4.16.3 Creating array objects 142
4.16.4 Using array objects 144
4.16.5 Analyzing the log file 144
4.16.6 The for loop 145
4.16.7 Arrays and the for-each loop 147
4.16.8 The for loop and iterators 148
4.17 Summary 150
Chapter 5 More-sophisticated behavior 153
5.1 Documentation for library classes 154
5.2 The TechSupport system 155
5.2.1 Exploring the TechSupport system 155
5.2.2 Reading the code 157
5.3 Reading class documentation 160
5.3.1 Interfaces versus implementation 162
5.3.2 Using library-class methods 163
5.3.3 Checking string equality 165
5.4 Adding random behavior 166
5.4.1 The Random class 166
5.4.2 Random numbers with limited range 167
5.4.3 Generating random responses 168
5.4.4 Reading documentation for parameterized classes 171
5.5 Packages and import 171
5.6 Using maps for associations 172
5.6.1 The concept of a map 173
5.6.2 Using a HashMap 173
5.6.3 Using a map for the TechSupport system 175
5.7 Using sets 177
5.8 Dividing strings 178
5.9 Finishing the TechSupport system 179
5.10 Writing class documentation 181
5.10.1 Using javadoc in BlueJ 182
5.10.2 Elements of class documentation 182
5.11 Public versus private 183
5.11.1 Information hiding 184
5.11.2 Private methods and public fields 185
5.12 Learning about classes from their interfaces 186
5.12.1 The scribble demo 186
5.12.2 Code completion 189
5.12.3 The bouncing-balls demo 190
5.13 Class variables and constants 190
5.13.1 The static keyword 191
5.13.2 Constants 192
5.14 Summary 193
Chapter 6 Designing classes 196
6.1 Introduction 197
6.2 The world-of-zuul game example 198
6.3 Introduction to coupling and cohesion 200
6.4 Code duplication
6.5 Making extensions 204
6.5.1 The task 205
6.5.2 Finding the relevant source code 205
6.6 Coupling 207
6.6.1 Using encapsulation to reduce coupling 207
6.7 Responsibility-driven design 212
6.7.1 Responsibilities and coupling 212
6.8 Localizing change 214
6.9 Implicit coupling 215
6.10 Thinking ahead 218
6.11 Cohesion 219
6.11.1 Cohesion of methods 219
6.11.2 Cohesion of classes 220
6.11.3 Cohesion for readability 221
6.11.4 Cohesion for reuse 221
6.12 Refactoring 222
6.12.1 Refactoring and testing 223
6.12.2 An example of refactoring 223
6.13 Refactoring for language independence 226
6.13.1 Enumerated types 227
6.13.2 Further decoupling of the command interface 229
6.14 Design guidelines 231
6.15 Executing without BlueJ 232
6.15.1 Class methods 232
6.15.2 The main method 233
6.15.3 Limitations in class methods 234
6.16 Summary 234
Chapter 7 Well-behaved objects 236
7.1 Introduction 236
7.2 Testing and debugging 237
7.3 Unit testing within BlueJ 237
7.3.1 Using inspectors 243
7.3.2 Positive versus negative testing 245
7.4 Test automation 245
7.4.1 Regression testing 245
7.4.2 Automated testing using JUnit 246
7.4.3 Recording a test 248
7.4.4 Fixtures 251
7.5 Debugging 252
7.6 Commenting and style 254
7.7 Manual walkthroughs 255
7.7.1 A high-level walkthrough 255
7.7.2 Checking state with a walkthrough 257
7.7.3 Verbal walkthroughs 260
7.8 Print statements 260
7.8.1 Turning debugging information on or off 262
7.9 Debuggers 263
7.10 Choosing a debugging strategy 265
7.11 Putting the techniques into practice 265
7.12 Summary 265
Part 2 Application structures 267
Chapter 8 Improving structure with inheritance 269

8.1 The network example 269
8.1.1 The network project: classes and objects 270
8.1.2 Network source code 273
8.1.3 Discussion of the network application 282
8.2 Using inheritance 282
8.3 Inheritance hierarchies 284
8.4 Inheritance in Java 285
8.4.1 Inheritance and access rights 286
8.4.2 Inheritance and initialization 286
8.5 Network: adding other post types 288
8.6 Advantages of inheritance (so far) 290
8.7 Subtyping 291
8.7.1 Subclasses and subtypes 293
8.7.2 Subtyping and assignment 293
8.7.3 Subtyping and parameter passing 295
8.7.4 Polymorphic variables 295
8.7.5 Casting 296
8.8 The Object class 297
8.9 Autoboxing and wrapper classes 298
8.10 The collection hierarchy 299
8.11 Summary 299
Chapter 9 More about inheritance 302
9.1 The problem: network’s display method 302
9.2 Static type and dynamic type 304
9.2.1 Calling display from NewsFeed 305
9.3 Overriding 307
9.4 Dynamic method lookup 309
9.5 Super call in methods 311
9.6 Method polymorphism 313
9.7 Object methods: toString 313
9.8 Object equality: equals and hashCode 316
9.9 Protected access 318
9.10 The instanceof operator 320
9.11 Another example of inheritance with overriding 321
9.12 Summary 323
Chapter 10 Further abstraction techniques 326
10.1 Simulations 326
10.2 The foxes-and-rabbits simulation 327
10.2.1 The foxes-and-rabbits project 328
10.2.2 The Rabbit class 331
10.2.3 The Fox class 334
10.2.4 The Simulator class: setup 337
10.2.5 The Simulator class: a simulation step 341
10.2.6 Taking steps to improve the simulation 342
10.3 Abstract classes 342
10.3.1 The Animal superclass 343
10.3.2 Abstract methods 344
10.3.3 Abstract classes 346
10.4 More abstract methods 348
10.5 Multiple inheritance 351
10.5.1 An Actor class 351
10.5.2 Flexibility through abstraction 353
10.5.3 Selective drawing 353
10.5.4 Drawable actors: multiple inheritance 354
10.6 Interfaces 354
10.6.1 An Actor interface 355
10.6.2 Multiple inheritance of interfaces 356
10.6.3 Interfaces as types 357
10.6.4 Interfaces as specifications 358
10.6.5 Library support through abstract classes and interfaces 359
10.7 A further example of interfaces 359
10.8 The Class class 361
10.9 Abstract class or interface? 362
10.10 Event-driven simulations 362
10.11 Summary of inheritance 363
10.12 Summary 364
Chapter 11 Building graphical user interfaces 367
11.1 Introduction 367
11.2 Components, layout, and event handling 368
11.3 AWT and Swing 368
11.4 The ImageViewer example 369
11.4.1 First experiments: creating a frame 369
11.4.2 Adding simple components 372
11.4.3 An alternative structure 373
11.4.4 Adding menus 374
11.4.5 Event handling 375
11.4.6 Centralized receipt of events 376
11.4.7 Inner classes 378
11.4.8 Anonymous inner classes 380
11.4.9 Summary of key GUI elements 382
11.5 ImageViewer 1.0: the first complete version 383
11.5.1 Image-processing classes 383
11.5.2 Adding the image 384
11.5.3 Layout 386
11.5.4 Nested containers 389
11.5.5 Image filters 391
11.5.6 Dialogs 394
11.5.7 Summary of layout management 396
11.6 ImageViewer 2.0: improving program structure 396
11.7 ImageViewer 3.0: more interface components 402
11.7.1 Buttons 402
11.7.2 Borders 405
11.8 Further extensions 406
11.9 Another example: MusicPlayer 408
11.10 Summary 411
Chapter 12 Handling errors 413
12.1 The address-book project 414
12.2 Defensive programming 418
12.2.1 Client—server interaction 418
12.2.2 Parameter checking 420
12.3 Server-error reporting 421
12.3.1 Notifying the user 422
12.3.2 Notifying the client object 422
12.4 Exception-throwing principles 425
12.4.1 Throwing an exception 426
12.4.2 Checked and unchecked exceptions 426
12.4.3 The effect of an exception 428
12.4.4 Using unchecked exceptions 429
12.4.5 Preventing object creation 430
12.5 Exception handling 431
12.5.1 Checked exceptions: the throws clause 432
12.5.2 Anticipating exceptions: the try statement 432
12.5.3 Throwing and catching multiple exceptions 434
12.5.4 Multi-catch Java 7 436
12.5.5 Propagating an exception 436
12.5.6 The finally clause 437
12.6 Defining new exception classes 438
12.7 Using assertions 440
12.7.1 Internal consistency checks 440
12.7.2 The assert statement 440
12.7.3 Guidelines for using assertions 442
12.7.4 Assertions and the BlueJ unit testing framework 443
12.8 Error recovery and avoidance 443
12.8.1 Error recovery 443
12.8.2 Error avoidance 445
12.9 File-based input/output 446
12.9.1 Readers, writers, and streams 447
12.9.2 The File class and Path interface 447
12.9.3 File output 448
12.9.4 The try-with-resource statement 450
12.9.5 Text input 452
12.9.6 Scanner: parsing input 455
12.9.7 Object serialization 457
12.10 Summary 458
Chapter 13 Designing applications 460
13.1 Analysis and design 460
13.1.1 The verb/noun method 461
13.1.2 The cinema booking example 461
13.1.3 Discovering classes 461
13.1.4 Using CRC cards 463
13.1.5 Scenarios 463
13.2 Class design 467
13.2.1 Designing class interfaces 467
13.2.2 User interface design 468
13.3 Documentation 469
13.4 Cooperation 469
13.5 Prototyping 470
13.6 Software growth 470
13.6.1 Waterfall model 471
13.6.2 Iterative development 471
13.7 Using design patterns 472
13.7.1 Structure of a pattern 473
13.7.2 Decorator 474
13.7.3 Singleton 474
13.7.4 Factory method 475
13.7.5 Observer 476
13.7.6 Pattern summary 477
13.8 Summary 478
Chapter 14 A case study 480
14.1 The case study 480
14.1.1 The problem description 480
14.2 Analysis and design 481
14.2.1 Discovering classes 481
14.2.2 Using CRC cards 482
14.2.3 Scenarios 483
14.3 Class design 485
14.3.1 Designing class interfaces 485
14.3.2 Collaborators 485
14.3.3 The outline implementation 486
14.3.4 Testing 490
14.3.5 Some remaining issues 490
14.4 Iterative development 491
14.4.1 Development steps 491
14.4.2 A first stage 492
14.4.3 Testing the first stage 496
14.4.4 A later stage of development 496
14.4.5 Further ideas for development 498
14.4.6 Reuse 499
14.5 Another example 499
14.6 Taking things further 499
Appendices
A Working with a BlueJ project 500
B Java data types 503
C Operators 507
D Java control structures 510
E Running Java without BlueJ 517
F Using the debugger 520
G Unit unit-testing tools 524
H Teamwork tools 526
I Javadoc 528
J Program style guide 531
K Important library classes 535
Index 539


Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020