Home > Store

Object-Oriented Programming with Java: An Introduction

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

Object-Oriented Programming with Java: An Introduction

  • Published Jan 18, 2000 by Pearson.

Book

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

About

Features

  • Computer systems basics—Presents a simple model of a computer and its components, and describes the ways in which the design of most programming languages are shaped by them.
    • Gives students with little or no experience in writing computer programs a solid understanding of how computer systems work. Ex.___

  • “Objects-early” approach—Stresses the importance of objects throughout, providing an introduction to basic object-oriented concepts and emphasizing that objects communicate by passing messages to one another.
    • Provides students with clear methodology for learning an object-oriented language. Ex.___

  • Core features—Covers elements of Java that enable behavior to be added to class definitions, including control structures (if-statements and loops), and the basics of arithmetic and boolean expressions.
    • Provides students with the foundational material necessary for creating functional classes that can interact with one another. Ex.___

  • Polymorphism—Offers a thorough investigation of Java's interface facility and the concept of polymorphism, and goes on to describe Java's extends facility for class inheritance.
  • Abstract Windowing Toolkit (AWT)—Examines a powerful collection of classes that simplify the creation of applications with graphical user interfaces.
    • Frees student programmers from a need to know details of the windowing environment in which their programs will be run. Ex.__

  • A complete examination of threads—Discusses multiprocessing, thread basics, resource sharing between threads, and more—and considers such potential problems as race hazards, starvation, livelock and deadlock, and how to avoid them.
    • Shows students how to create objects that run concurrently and share the available processor time between them, and alerts them to a number of new problems created by multithreaded programs. Ex.___

  • Exercises—Positions exercises between sections, rather than grouped at the end.
    • Encourages students to apply concepts at the point they are reached, and helps them feel confident about their understanding of key material throughout their progression of the text. Ex.___

  • Case studies.
    • Helps students gain a deeper understanding of points made by looking at real-world designs and implementations of problems. Ex.___

  • Periodic reviews.
    • Gives students the opportunity to thoroughly grasp the main points of the material covered before moving on to the next section. Ex.___

  • Based on Java 2—Students learn the latest version of Java.

Description

  • Copyright 2000
  • Dimensions: 7 X 9-1/4
  • Pages: 1028
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-086900-7
  • ISBN-13: 978-0-13-086900-5

This well-organized, clearly written and visually engaging book provides hands-on experience as it guides the reader through all of Java's functions and capabilities. This comprehensive text shows readers how to use such a versatile object-oriented programming language as a primary tool in many different aspects of programming work. It is designed primarily as a first programming text. Java's everyday applicability is reinforced through the book's many, interesting UK case studies. With an "objects-early" approach, David Barnes stresses the importance of objects for a clear methodology of learning an object-oriented language. Throughout the book, the author emphasizes the importance of good programming style, particularly the need to maintain an object's integrity from outside interference.

  • An objects-early approach showing how to design and use fully-fledged objects
  • .
  • An accessible introduction to the fundamental object-oriented topics of polymorphism and inheritance
  • .
  • Significant coverage of GUI classes belonging to both Abstract Windowing Toolkit (AWT) and Swing (JFC)
  • .
  • The latest coverage of Java 2 Platform API
  • .
  • Usage of power threads for multi-threaded programs
  • .
  • Timely coverage of networking, via TCP/IP, to interact with non-Java programs
  • .
  • A unique chapter on event-driven simulation
  • .
  • Support materials include Prentice Hall's Companion Web site

http://www.prenhall.com/barnes and links to the author's Web site <http://www.cs.ukc.ac.uk/people/staff/djb/Book/Index.html>

Sample Content

Table of Contents

I. JAVA FUNDAMENTALS.

 1. Bits, Bytes, and Java.
 2. Common Program Components.
 3. Creating and Using Objects.
 4. Defining Classes.
 5. Adding Sequential Behavior.
 6. Adding Selective Behavior.
 7. Adding Repetitive Behavior.
 8. Packages and Utility Classes.
 9. Arrays and Further Statements.
10. Collection Classes.

II. FURTHER LANGUAGE FEATURES.

11. Exceptions.
12. Input-Output.
13. Interfaces.
14. Class Inheritance.
15. Abstract and Nested Classes.

III. GUI PACKAGES.

16. AWT Applications.
17. Swing.

IV. ADVANCED FEATURES.

18. Threads.
19. Networking.

V. APPLETS.

20. Applets.

VI. JAVA FOR SIMULATION.

21. Simulation.

APPENDICES.

A: The Primitive Data Types.
B: Number Representations.
C: Java Operators.
D: Java Reserved Words.
E: Common Design Patterns.
F: Stylistic Conventions.
G: The Java 2 SDK.
H: Javadoc.
I: Glossary.
Bibliography.
Index.

Preface

Preface

Introduction
This book is designed for those readers who wish to start learning to program in an object-oriented programming language. It has been designed primarily as a first programming text. It is also suitable for those who already have some experience with another programming language, and who now wish to move on to an object-oriented one. Indeed, much of the material is based on courses delivered by the author to students with a wide range of both non-programming and programming backgrounds. The language we use to teach object-oriented programming is Java.

Since its arrival on the scene in 1995, the adoption of Java as a primary programming language has been amazing. In its favor at the time of its arrival were the facts that it was an object-oriented language, and that it offered a safer and more portable alternative to other languages. It also rode the wave of interest in the World Wide Web, with which it integrated well in its provision of applets. Since then, however, Java has come to be regarded as a genuine mainstream programming language.

Our approach in this book is to regard Java as a language that readers will want to use as a primary tool in many different areas of their programming work - not just for creating programs with graphical content within Web pages. For this reason, in the early chapters we have avoided an emphasis on creating applets and GUI-based programs. While being able to create GUI-based programs is superficially attractive, the language concepts required to create them properly are, in fact, quite advanced. Nevertheless, we recognize that visual examples are much more fun to create and work with. To this end, many of our early examples and exercises are enhanced by the provision of visual material that makes them more interesting to experiment with. An object-oriented language makes this approach relatively easy, without the reader needing to become enmeshed in the details of how they are implemented.

Key Features
The following are key features of this book:

  • An 'objects-early' approach; showing how to interact with fully-fledged objects, before moving on, in Chapter 4, to define classes from scratch.
  • Frequent in-place exercises and reviews.
  • A thorough glossary, explaining many of the highlighted items of terminology found in the text.
  • An accessible introduction to the fundamental object-oriented topics of polymorphism and inheritance.
  • Significant coverage of the many GUI classes belonging to both the Abstract Windowing Toolkit (AWT) and Swing (JFC), which support both standalone applications and applets.
  • Up-to-date coverage of the Java 2 Platform API.
  • How to use the power of threads for multi-threaded programs, while avoiding hazards such as deadlock, livelock, and thread starvation.
  • Timely coverage of networking, via TCP/IP, to interact with non-Java programs.
  • A unique chapter on event-driven simulation.

Chapter Outlines
In Chapter 2 through Chapter 15, we cover the most important features of object-oriented programming and the Java language. Within those chapters, exercises have been deliberately positioned between sections, rather than grouped at the end. We recommend that these exercises are attempted at the point they are reached, because many of them are designed to reinforce important concepts that you should feel confident with before moving forward. Each of these chapters also includes periodic reviews to reprise and reinforce the main points of the material covered in the preceding sections. From time to time, case studies are used in order to reinforce or bring out further points that are best made in looking at the design and implementation of a larger problem.

In the remaining chapters, we describe in detail how to use many of the GUI components provided by the AWT and Swing classes, how to write multi-threaded programs, and how to interact with programs across a network. We conclude with a chapter on simulation - a common application area for object-oriented programs. Throughout the book, there is an emphasis on the importance of good programming style; particularly the need to maintain an object's integrity from outside interference.

The individual chapters are organized as follows:

  • Chapter 1 provides an introduction to the basics of computer systems, for those with little or no experience of using a computer to write programs. We present a simple model of a computer and its components, in order to provide a foundation for the ways in which the design of most programming languages is shaped by them. Experienced programmers will find that they can skip this chapter.
  • In Chapter 2, we describe the fundamental elements of the Java language, and show how to compile and run a simple program.
  • In Chapter 3, we provide an introduction to basic object-oriented concepts, such as classes and objects. The approach taken in this chapter is fundamental to that taken in the rest of the book: objects are important. We believe that an 'objects-early' approach is the best way to learn an object-oriented language. At this stage, the emphasis is on using existing classes rather than defining them. This approach helps to emphasize that objects communicate bypassing messages to one another.
  • In Chapter 4, we begin to show how simple classes may be defined from scratch. We discuss the ways in which objects use attributes to maintain their state and the importance of protecting those attributes from inappropriate modification. It is at this early stage that the concepts of accessors, mutators, and encapsulation are introduced.
  • In Chapter 5, we start to introduce the core features of Java that enable behavior to be added to class definitions. We concentrate on straight-line sequences of statements, and discuss arithmetic expressions.
  • In Chapter 6, we continue to add behavior to classes but introduce statements that allow objects to perform alternative sequences of statements. We include a discussion of Boolean expressions, which are used to control this behavior.
  • In Chapter 7, the ability to repeat statements is added to class definitions. By the end of this chapter, we are able to use the three fundamental elements of behavior - sequence, choice, and repetition.
  • In Chapter 8, we introduce packages-Java's means of grouping related classes. We include a description of several pre-defined classes that are used over and over again in programs: Math, String, and StringBuffer.
  • In Chapter 9, we describe array objects, which make it possible to group related objects or items of data into fixed-sized collections.
  • In Chapter 10, we introduce classes that support arbitrary-sized collections of objects. While most programming languages provide array facilities, Java adds standard collection classes that other languages often leave to programmers to create for themselves.
  • In Chapter 11, we explore Java's exception-handling mechanism. This provides a way for objects to indicate when an unexpected situation has arisen with which they do not know how to deal. Complementary to this is the ability to `catch' exceptions and develop work-grounds for the problems encountered.
  • In Chapter 12, we look at some of the many ways in which a program can interact with the external file system, via pre-defined input-output classes.
  • In Chapter 13, we investigate Java's interface facility. In earlier chapters we use the term 'public interface' informally, but this chapter explores the issue in more depth. Central to it is the concept of polymorphism. Since polymorphism is such a fundamental concept in any objectoriented language, we continue our discussion of it in the next chapter.
  • In Chapter 14, we take the discussion of polymorphism one stage further by describing Java's extends facility for class inheritance. Inheritance provides the ability to derive new classes that inherit much of their code and functionality from existing classes. Among other things, this permits code reuse. As part of the material in this chapter, we discuss alternatives to inheritance and inappropriate inheritance.
  • In Chapter 15, we look at abstract classes, nested classes, and nested interfaces. By the end of this chapter, we have covered most of the main features of the Java language. Apart from Chapter 18, therefore, the remaining chapters are largely concerned with using these features in different applications; such as graphical programming, networking, and simulation.
  • In Chapter 16, we describe the classes of the Abstract Windowing Toolkit (AWT). The AWT provides a powerful collection of classes that simplify the creation of applications with graphical user interfaces. They free a programmer from a need to know details of the windowing environment in which their programs will be run. For the sake of generality, we concentrate on standalone applications, rather than applets. Applets are covered, separately, in Chapter 20.
  • In Chapter 17, we continue the description of Java's graphical features. This chapter covers the Swing classes, which build on the AWT facilities to provide a more complex set of classes, and greater programmer control over the look-and-feel of a program.
  • In Chapter 18, we introduce the final major language feature: threads. Threads are a powerful feature that make it possible to create objects that run concurrently, sharing the available processor time between them. However, the power of threads brings with it a number of new problems of which the designer of multi-threaded programs needs to be aware. We discuss problems such as race hazards, starvation, livelock, and deadlock, and how to avoid them.
  • In Chapter 19, we introduce the classes that allow a program to interact with other programs across a network. We discuss use of the reliable TCP protocol and the unreliable UDP protocol, both of which are well supported by Java's socket classes.
  • In Chapter 20, we return to features of graphical programming, with a description of applets. Applets are largely restricted forms of the stand-alone applications described in Chapter 16. They are provided with a secure environment which prevents them from directly accessing the host machine on which they are run. These restrictions apply so that they can be run within browsers, providing the familiar active content of Web pages.
  • Chapter 21 concludes the main content of the book with a description of the basic elements of event-driven (discrete) simulation. Simulations represent an important set of object-oriented programs and we describe them through the presentation of two case studies.
  • The Appendices provide additional background material on primitive data types, number representations, operators, and a list of Java's reserved words. Some recurring design patterns are discussed in Appendix E, and our main stylistic conventions are summarized in Appendix F. The book concludes with a comprehensive glossary of terminology.

The Java API continues to grow, and it is impossible to cover it all in detail within the scope of a teaching text such as this. In Chapter 16 through Chapter 20, therefore, we only attempt to sample the riches of the classes it defines, and provide illustrations of something of what is possible with them. By that stage, our hope is that the reader will be able to harness the power that object-oriented programming in Java permits, and be able to create their own interesting and practical everyday programs.

Supporting Materials
The examples we use have been developed using the Java 2 SDK, which is freely available from the JavaSoft Web site (http://www.javasoft.com). You are strongly recommended to obtain a copy of the documentation on the Java API which is available from the JavaSoft site. The source code for the examples in this book is available from the Companion Website: http://ww.prenhall.com/barnes

Acknowledgements
I have the privilege of working in a Computer Science Department in which excellent teaching is both encouraged and practiced. I have benefited enormously from working with many talented colleagues. I have probably received help and picked up ideas from most of them over the years, but I would like to thank a few by name for the particular help and support that they have given to me while putting this book together.

David Bateman - a legendary source of good teaching and great ideas for assignments. Thanks to him for allowing me to use his chess program idea. Tim Hopkins, for being a constant source of books and sink of videos (neither of which seem to get returned by either of us), for his willingness to proofread, and for his good humour sic!. Janet Linington, for many discussions about the best ways to teach introductory programming, and for the gas station idea that ultimately led to the chapter on simulation. Simon Thompson, who is also an excellent teacher. Thanks to him for encouraging me to start this project in the first place, and for his introducing me to Jackie Harbor (now at Macmillan) that made it happen. Ian Utting, who pioneered the teaching of object-oriented software engineering at UKC and who currently shares the teaching of the first-year course with me. He remains a constant source of wisdom in this area and contributed important ideas to the chess program.

I would also like to thank David Till of City University, for being willing to let me use his and the late Michael Bell's 'soup salting' analogy as the basis of some of my early examples. At Pearson, thanks to my publisher, Alan Apt, and his editorial assistant, Toni Holm, both of whom have been extremely efficient at making this book happen. They provided superb support at the other end of a stream of email messages from me, and were always patient when deadlines were missed! To the several reviewers of this book, I also owe a debt of thanks. Their diligence and thoroughness were remarkable, and much appreciated. During the production stages, Amy Ryan and her team at Interactive Composition Corporation did an amazing job, accommodating my frequent changes, and yet keeping us ahead of schedule.

Finally, to my immediate family, for putting up with the extreme working hours that creating a book seems to require, and to the Scottish contingent for accommodating an antisocial me and my laptop over Christmas!

David Barnes
December 1999

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