Table Of ContentApplied Computing
Springer
London
Berlin
Heidelberg
New York
Barcelona
Budapest
Hong Kong
Milan
Paris
Santa Clara
Singapore
Tokyo
The Springer-Verlag Series on Applied Computing is an advanced
series of innovative textbooks that span the full range of topics in
applied computing technology.
Books in the series provide a grounding in theoretical concepts in
computer science alongside real-world examples of how those
concepts can be applied in the development of effective computer
systems.
The series should be essential reading for advanced undergraduate
and postgraduate students in computing and information systems.
Books in the series are contributed by international specialist
researchers and educators in applied computing who draw together
the full range of issues in their specialist area into one concise
authoritative textbook.
Titles already available:
Deryn Graham and Anthony Barrett
Knowledge-Based Image Processing Systems
Linda Macaulay
Requirements Engineering
Derrick Morris, Gareth Evans, Peter Green, Colin Theaker
Object Oriented Computer Systems Engineering
Forthcoming titles include:
Jan Noyes and Chris Baber
Designing Systems
Derek Wills and Rob Macredie
Applied Computer Graphics
David Gray
Real Time Systems Design
John Hunt
Java and Object
Orientation:
An Introduction
Springer
John Hunt, BSc, PhD, MBCS, CEng
Department of Computer Science, University of Wales,
Aberystwyth, Ceredigion SY 23 3DB, UK
Series Editors
Professor Peter J. Thomas, BA (Hons), PhD, AI Mgt, FRSA, FVRS
Centre for Personal Information Management, University of the West of
England, Coldharbour Lane, Bristol, BS16 lQY, UK
Professor Ray J. Paul, BSc, MSc, PhD
Department of Computer Science and Information Systems at st. John's,
BruneI University, Kingston Lane, Uxbridge, Middlesex UB8 3PH, UK
British Library Cataloguing in Publication Data
Hunt,John
Java and object orientation: an introduction. -(Applied computing)
l.Java (Computer program language) 2.0bject-oriented programming (Computer science)
I.Title
005·7'12'62
ISBN-13: 978-3-540-76201-0 e-ISBN-13: 978-1-4471-3380-3
DOl: 10.1007/978-1-4471-3380-3
Library of Congress Cataloging-in-Publication Data
Hunt, John, 1964-
Java and object orientation: an introduction / John Hunt.
p. cm. --(Applied computing)
Includes bibliographical references and index.
ISBN-1J: 978-3-540-76201-0
I.Java (Computer program language) 2.0bject-oriented programming
I.Title. ILSeries.
QA76.nJ38H86 1997
00S.13'3-dc21 97-29238
Apart from any fair dealing for the purposes of research or private study, or criticism or
review, as permitted under the Copyright, Designs and Patents Act 1988, iliis publication may
only be reproduced, stored or transmitted, in any form or by any means, with ilie prior
permission in writing of ilie publishers, or in ilie case of repro graphic reproduction in
accordance with the terms of licences issued by the Copyright Licensing Agency. Enquiries
concerning reproduction outside those terms should be sent to the publishers.
© Springer-Verlag London Limited 1998
The use of registered names, trademarks etc. in this publication does not imply, even in the
absence of a specific statement, iliat such names are exempt from the relevant laws and
regulations and therefore free for general use.
The publisher makes no representation, express or implied, with regard to the accuracy of the
information contained in this book and cannot accept any legal responsibility or liability for
any errors or omissions iliat may be made.
Typesetting: Mitcham Editorial Services, Mitcham, Surrey
3413830-543210 Printed on acid-free paper
This book is dedicated with love to my wife, Denise,
and our daughter, Phoebe
Preface
This book was originally written to support an introductory course in
Object Orientation through the medium of Java (and the Sun Java
Development Kit, in particular) for those with experience of a
procedural programming language such as C or Pascal. However, it can
be used as a book to teach the reader Java, or to introduce object
orientation, as well as to present object oriented design and analysis.
It takes as its basic premise that most computer scientists and
software engineers learn best by doing rather than reading theoretical
discussions. The chapters therefore attempt to introduce concepts by
getting you, the reader, to do things, rather than by extensive
theoretical discussion. This means that the chapters take a hands-on
approach to the subject and assume that you have a suitable Java
environment available.
The chapters are listed below and are divided into eight parts. You
are advised to work through Parts 1 and 3 thoroughly in order to gain a
detailed understanding of object orientation. Parts 2 and 4 introduce
the Java language. You may then dip into other chapters as required.
For example, if you wish to hone your Java skills then the chapters in
Part 6 will be useful, whereas if you wish to gain an overview of object
oriented design then you may prefer to read Part 7. However, if you
wish to discover the delights of graphical user interfaces in Java, then
you should read Part 5 next.
CONTENT SUMMARY
Part 1: Introduction to Object Orientation
Chapter 1: Introduction to Object Orientation
This chapter introduces the range of concepts and ideas, which make
up object technology. It presents the background that led to the
acceptance of object orientation as a mainstream technology and
discusses the pedigree of the Java language.
viii Java and Object Orientation
Chapter 2: Elements of Object Orientation
This chapter provides a more formal definition of the terminology
introduced in Chapter 1. It also considers the advantages and
disadvantages of an object oriented approach compared to more
traditional procedural approaches.
Chapter 3: Constructing an Object Oriented System
A typical problem for many people when being introduced to a new
approach is that they understand the terminology and the concepts but
not how to use them. This chapter aims to alleviate this problem by
presenting a detailed worked example of the way in which an object
oriented system may be designed and constructed. It does so without
reference to any particular language, so that language issues do not
confuse the discussion.
Part 2: Introduction to the Java Language
Chapter 4: A Brief History of Time, the Universe and Java
This chapter provides some background on the history of Java and the
development environments which are available to support it (such as
the Sun Java Development Kit). It also considers some of the tools that
you will encounter.
Chapter 5: A Little Java
This chapter introduces the Java syntax, and examines the structure of
a basic Java application.
Chapter 6: Java Building Blocks
This chapter considers classes, instances, methods and variables as well
as interface specifications in Java. These are the basic building blocks of
any object oriented program and in particular of a Java program.
Chapter 7: Java Constructs
This chapter presents further details of the Java language, including
numbers, operators, variables and message passing. This chapter also
looks at the String, Integer and Character classes.
Chapter 8: An Example Java Class
This chapter presents you with a detailed worked example of software
development in Java. This example presents a very simple class
definition which uses only those concepts which have been introduced
at this stage. The intention is to illustrate how the constructs and
language elements can be combined in a real (if simple) application.
Preface ix
Part 3: Java and Object Orientation
Chapter 9: Classes, Inheritance and Abstraction
This chapter considers how you should use inheritance, abstraction
and classes in Java. It considers the role of classes and when to create
subclasses and define abstract classes.
Chapter 10: Encapsulation and Polymorphism
This chapter considers how to achieve encapsulation in Java. It
considers how the visibility of methods and variables can be modified.
It presents packages and how they are defined and used. It also
discusses issues associated with the polymorphic appearance of Java.
Chapter 11: Data Structures
This chapter discusses the Java classes which are used to construct data
structures. These classes include Array, Vector and Hashtable.
Chapter 12: Defining Collection Classes
This chapter considers how to create further data structure classes,
such as Sets and Ordered Collections. It introduces interfaces as a way
of ensuring a common set of facilities and enabling the generic use of
such classes. It concludes by describing enumerations and their use.
Part 4: Further Java
Chapter 13: Control and Iteration
This chapter introduces control and iteration in Java.
Chapter 14: An Object Oriented Organizer
This chapter presents a detailed example application constructed using
the Vector class. The application is an electronic personal organizer
that contains an address book, a diary (or appointments section) and a
section for notes. The remainder of this chapter describes one way of
implementing such an organizer. At the end of this chapter is a
programming exercise.
Chapter 15: Streams and Files
This chapter discusses the other most common class hierarchies in
Java, the Stream classes. The Stream classes are used (amongst other
things) for accessing files.
Chapter 16: Serialization
This chapter explains how objects can be stored to file and restored
from file using serialization. This provides a very basic persistent object
system for Java.
x Java and Object Orientation
Chapter 17: Observers and Observables
The Observer interface and Observable class are used to implement the
Java dependency mechanism. This mechanism allows one or more
objects to be informed about changes in the state of an object, without
that object knowing anything about the first set of objects. It is
particularly important in the construction of reusable, object oriented,
graphical user interfaces.
Part 5: Graphical Interfaces and Applets
Chapter 18: Graphic Programming Using the AWT
The Abstract Window Toolkit (A WT) is a platform-independent set of
classes for constructing graphical interfaces. This chapter looks at how to
construct windows and generate graphics.
Chapter 19: User Interface Programming
This chapter considers the Java Delegation Event Model and the range
of GUI construction classes in the AW T.
Chapter 20: Managing Component Layout
This chapter introduces the layout managers provided with the AWT.
These objects control how components are laid out within an interface
in a portable and useful manner.
Chapter 21: A GUI Case Study
This chapter describes a detailed worked example of how to construct a
user interface for the organizer application developed in Chapter 14.
Chapter 22~ Combining Graphics and GUI Components
This chapter brings together the graphic elements of the AW T
described in Chapter 18 with the user interface components described
in Chapters 19 to 21.
Chapter 23: Applets and the Internet
This chapter examines the facilities in Java for programming for the
Internet. It introduces applets and URLs.
Part 6: Java Development
Chaptp.r 24: Java Style Guidelines
This chapter aims to promote readable, understandable, concise and
efficient Java code.
Preface xi
Chapter 25: Exception Handling
In Java, exceptions are objects (just like almost everything else). Thus,
to throw an exception you must first make an instance of an exception
class. This chapter considers exceptions and how to create, throw and
handle them. It also discusses defining new exceptions by creating
subclasses.
Chapter 26: Concurrency
This chapter describes the concurrency mechanism of Java. That is, it
describes the way in which Java implements lightweight threads.
Part 7: Object Oriented Design
Chapter 27: Object Oriented Analysis and Design
This chapter introduces the concepts of object oriented analysis and
design. It reviews a number of the more popular techniques such as
OOA, OMT, Objectory and Booch. It also briefly considers the
unification of the OMT and Booch notations.
Chapter 28: The Unified Modeling Language
The Unified Modeling Language (UML) is a third generation object
oriented modeling language which adapts and extends the published
notations used in the Booch, OMT and Objectory methods. UML is
intended to form a single, common" widely used modeling language for
a range of object oriented design methods (including Booch, Objectory
and OMT). It should also be applicable to a wide range of applications
and domains. This chapter summarizes the UML notation.
Chapter 29: The Object Modeling Technique
This chapter discusses the influential design method referred to as the
Object Modeling Technique (OMT). It summarizes the main phases of
OMT using the UML notation. An extension to OMT introduces use
case models from Objectory to improve the requirements analysis
process. This is motivated by the inclusion of use case diagrams in
UML.
Part 8: The Future
Chapter 30: Areas of Java and Object Technology not Covered
Java has many features which are not suitable for an introductory book.
This chapter attempts to make you aware of what has not been covered,
without going into any detail. It includes discussion of the current
developments within the Java world. In particular, it introduces the
Java Beans (component) model, and discusses the RMI (Remote