100% found this document useful (9 votes)
52 views

Buy ebook Programming in Java Sachin Malhotra cheap price

Malhotra

Uploaded by

riazimoodyff
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (9 votes)
52 views

Buy ebook Programming in Java Sachin Malhotra cheap price

Malhotra

Uploaded by

riazimoodyff
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Programming in Java Sachin Malhotra

https://textbookfull.com/product/programming-in-java-sachin-
malhotra/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Java Programming Joyce Farrell

https://textbookfull.com/product/java-programming-joyce-farrell/

textboxfull.com

Java Programming Joyce Farrell

https://textbookfull.com/product/java-programming-joyce-farrell-2/

textboxfull.com

Computer Graphics Programming in OpenGL with Java Gordon

https://textbookfull.com/product/computer-graphics-programming-in-
opengl-with-java-gordon/

textboxfull.com

Murach s Java Programming Joel Murach

https://textbookfull.com/product/murach-s-java-programming-joel-
murach/

textboxfull.com
Learning Java An Introduction to Real World Programming
with Java Marc Loy

https://textbookfull.com/product/learning-java-an-introduction-to-
real-world-programming-with-java-marc-loy/

textboxfull.com

Learning Java Beginning programming with java for dummies


First Edition John Bach

https://textbookfull.com/product/learning-java-beginning-programming-
with-java-for-dummies-first-edition-john-bach/

textboxfull.com

Java Network Programming Fourth Edition Harold Elliotte

https://textbookfull.com/product/java-network-programming-fourth-
edition-harold-elliotte/

textboxfull.com

Java Performance In Depth Advice for Tuning and


Programming Java 8 11 and Beyond 2nd Edition Scott Oaks

https://textbookfull.com/product/java-performance-in-depth-advice-for-
tuning-and-programming-java-8-11-and-beyond-2nd-edition-scott-oaks/

textboxfull.com

Introduction to Programming in Java An Interdisciplinary


Approach 2nd Edition Robert Sedgewick

https://textbookfull.com/product/introduction-to-programming-in-java-
an-interdisciplinary-approach-2nd-edition-robert-sedgewick/

textboxfull.com
Programming in
Java
Second Edition

SACHIN MALHOTRA
Associate Professor
IMS, Ghaziabad

SAURABH CHOUDHARY
Formerly, Head
IT Department
IMS, Ghaziabad

1
3
Oxford University Press is a department of the University of Oxford.
It furthers the University’s objective of excellence in research, scholarship,
and education by publishing worldwide. Oxford is a registered trade mark of
Oxford University Press in the UK and in certain other countries.

Published in India by
Oxford University Press
YMCA Library Building, 1 Jai Singh Road, New Delhi 110001, India

© Oxford University Press 2010, 2014

The moral rights of the author/s have been asserted.

First Edition published in 2010


Second Edition published in 2014

All rights reserved. No part of this publication may be reproduced, stored in


a retrieval system, or transmitted, in any form or by any means, without the
prior permission in writing of Oxford University Press, or as expressly permitted
by law, by licence, or under terms agreed with the appropriate reprographics
rights organization. Enquiries concerning reproduction outside the scope of the
above should be sent to the Rights Department, Oxford University Press, at the
address above.

You must not circulate this work in any other form


and you must impose this same condition on any acquirer.

ISBN-13: 978-0-19-809485-2
ISBN-10: 0-19-809485-X

Typeset in Times New Roman


by Sukuvisa Enterprises
Printed in India by Yash Printographics, Noida 201301
Dedicated
to
Our Parents
About the Authors

Sachin Malhotra is currently Associate Professor in the IT department of IMS Ghaziabad. He has more
than a decade long experience in mentoring students on developing Java applications as well as training
practising professionals in the field of Java. He has also designed and conducted various corporate
trainings in Java and networking.
Saurabh Choudhary is currently a practising IT consultant and corporate trainer. He has more than 12
years of experience in industry, academia, and consultancy. He has worked on positions of eminence
at IMS Ghaziabad as Head of IT department and Dean Academics (University Campus). His areas of
expertise include Java, Database Management System, and Information Systems.

Testimonials
From pervasive computing to communications industry, medical science to aerospace, Java is
gaining a foothold in every domain. Programming in Java has been written to arouse the interest
even in a novice computer programmer to an expert, craving to sharpen his programming skills.
Pankaj Verma | Senior Software Engineer | OSI Inc.
It is definitely the best textbook on Java that I have run into. I highly recommend it.
Sachin Dhama | Team Lead | Accenture
Java is a very powerful language for developing enterprise applications. I am hopeful that this
book will provide a basic building platform for Java programmers to enhance their knowledge.
Awadhesh Kumar Katiyar | Technical Lead | HCL Technologies Ltd.
Java enables users to develop applications on the Internet for servers, desktops computers, and small
handheld devices. The future of computing is being influenced by the Internet, and Java promises to
play a big part in it. This book is perfect for those who are seeking a clear understanding of Java. It
should allow the readers to create codes that are a lot clearer and are far more effective than before.
Saurabh Moondhra | Sr. Technical Consultant | SGT Inc
This is the most interesting Java programming book for beginners; at the same time, it is equally
good for intermediate readers as well. This should be your first Java book if you are learning
from scratch.
Pankaj Jain | Senior Manager | Bank of America
When you go through this book, you will gain confidence after completing each chapter. The
authors have written it in such a simple way covering each and every aspect of Java that anyone
can learn how to develop effective codes.
Rajeev Varshney | Lead Consultant | HCL NZ Ltd.
Preface to the First Edition

Java was primarily designed as a platform-independent language for usage in small consumer
electronic devices. It was derived from C++ but with a lot of difference. Java’s platform
independence originally addressed the problem that applications for embedded devices must
run on a wide variety of hardware. But since the Internet was emerging at the same time, Java
soon got adopted as an Internet language because of its portable nature. Major Internet browsers
such as Netscape Navigator and Microsoft Internet Explorer became Java-compatible, as it
effectively addressed the concerns for security by providing a firewall between web applications
and the computer. Eventually it became a standard programming language and is now being
used for creating a variety of applications including standalone applications, web applications,
enterprise-wide applications, and mobile games.
It can therefore be inferred that since its inception, Java has emerged as the most important
programming language. As the domain of Java is quite vast and a bit more complex than other
programming languages such as C, C++, and Visual Basic, it is observed that students and novice
programmers strive hard to comprehend its core concepts. Hence, a need for a book in this area,
which is both concise and simple, is a necessity.
About the Book
The book encapsulates the concepts of the latest version of Java, i.e. Java 6, encompassing a
comprehensive coverage of curriculum and industry expectations. It is useful for the students of
undergraduate and postgraduate courses of computer science and engineering and information
technology disciplines as well as for the instructors at various levels.
The book provides a thorough understanding of the basic concepts of object-oriented
programming principles and gradually moves on to the advanced concepts in Java. It includes
numerous examples, line-by-line description of examples, figures, explanation of concepts, and
key notes. Review questions and programming exercises are included as chapter-end exercises
to assess the learning outcomes. Every topic in the book is supported by examples followed
by an output and explanation. It also offers an appendix on general interview questions which
provides students an insight into the current requirements of the industry and allows them to
prepare accordingly.
The main features of this book include the following:
  an exhaustive coverage of Java features such as operators, classes, objects, inheritance,

packages, and exception handling


  comprehensive discussion on the latest features of Java such as enumerations, generics,

logging API, console class, StringBuilder class, NetworkInterface class, and assertions
  latest features combined with core concepts such as multithreading, applets, AWT, and

swings
  an introduction to the advanced concepts in Java such as servlets, RMI, and JDBC
Preface to theLab
Appendix A: Lab Manual—Java First Edition XIxi
Exercises

ACKNOWLEDGEMENTS
Several people have been instrumental throughout this tiring yet wonderful journey. First of all,
we would like to express our sincere gratitude to our families without whose support, patience,
and cooperation, this would not have been possible and we would not have been what we are
today. We are very thankful to Dr R. K. Bharadwaj, Head of our institution, for his inspirational
thoughts which inculcated urgency for writing this book. We are also thankful to our colleagues
for their endless support and suggestions during the entire process of writing this book.
Sachin Malhotra
Saurabh Choudhary
Preface to the Second Edition

Java is an easy-to-learn, versatile, robust, portable, and secure language with rich user interfaces.
It has set up new benchmarks in the software development world ranging from desktop to web-
based enterprise applications to mobile and embedded applications. Since its inception in 1995,
it has come a long way by continuously evolving itself and in the process, changing the style of
programming the world over. Java is not only found in laptops or data centres, it is also widely
used in cell phones, SIM cards, smart cards, printers, routers and switches, set-top boxes, ATMs,
and navigation systems, to name a few. According to Oracle, a staggering 1.1 billion desktops
and 3 billion cell phones are based on Java.
This second edition of Programming in Java confirms to Java Standard Edition 7, the latest
release since Oracle took over Sun Microsystems. It is significant in the sense that the last update
was six years back and this major release comes bundled with plenty of enhancements which were
overdue. To list a few noticeable enhancements, Java 7 includes support for strings in switch and
try-with-resources statements, improved multi-catch, binary numeric literals, numeric literals
with underscores, new APIs in NIO such as path and files, automatic resource management, and
much more. All the new topics are appropriately explained with suitable examples.
New to the Second Edition
This revised edition has been updated thoroughly with greater topical coverage as well as more
programming examples in every chapter, in addition to the confirmation to Java 7. Practically
every chapter, with the exception of Chapter 11, has been revisited to refine the text as much as
possible. The most noticeable changes are as follows:
  New practical programming examples to show how Java is used in practice.

 Enhanced coverage of servlets and JDBC along with an introduction to JSP, Java beans,

Jar files and enterprise Java beans


 Enhanced coverage of swing components like JTree, JTable, layered pane, JDesktopPane,

internal frames, JColorChooser, JFileChooser, and JEditorPane


 New classes of java.nio package and project coin language enhancements

  Enhanced coverage of utility classes

 Appendix B contains more interview questions to help students prepare for their interviews.

 The second edition is supplemented with a rich online resource centre that contains chapter-

wise PPTs for teachers and additional practical programming examples for students.
Key Features
The most prominent feature of this book has been the line-by-line explanation section under
each program. They facilitate in-depth understanding of the whole program. We have retained
this feature in the second edition as it has been well appreciated by the users. Other noticeable
features include the following:
Preface to the Second Edition vii

  A recap of object-oriented programming concepts before introducing the concepts of Java


 Plenty of user-friendly programs and key notes at appropriate places to highlight important
concepts
 A variety of end-chapter exercises that includes subjective as well as objective questions
Extended Chapter Material
The second edition includes the following changes:
Chapter 1, Introduction to OOP: Enhanced coverage of UML and its application in pictorial
representation of OOP concepts.
Chapter 2, Getting Started with Java: New sections about the features of Java 7 and how
to install JDK 1.7.
Chapter 3, Java Programming Constructs: Numeric literals with underscores, binary
numeric literals, and how to use strings in switch statements.
Chapter 4, Classes and Objects: New topics such as inner classes, variable length arguments,
arrays as return values from methods, and objects as arguments to and return type from methods.
It contains a practical problem on complex numbers to demonstrate how OOP concepts can be
put to practise.
Chapter 5, Inheritance: New section that highlights the differences between shadowing and
overriding. At the end of the chapter, there is a practical programming example on circle and
cylinder class.
Chapter 6, Interfaces, Packages, and Enumeration: Practical problem on banking concepts
to demonstrate the usage of packages in creating applications.
Chapter 7, Exception, Assertions, and Logging: try-with-resources and catching multiple
exceptions features which are new enhancements of Java 7.
Chapter 8, Multithreading in Java: Concrete practical example to show the use of threads
in applications.
Chapter 9, Input/Output, Serialization, and Cloning: New classes included in java.nio
package and how to perform cloning of objects.
Chapter 10, Generics, java.util and other API: Utility classes like Random class, Runtime
class, Observer and Observable and reflection API.
Chapter 12, Applets: how to use threads and images in applets. The practical problem at the
end of the chapter explains how to display a digital clock.
Chapter 13, Event Handling in Java: Practical programming example that explains how to
create a cartoon on applet and performs its event handling. This is actually a series of examples
with gradual and step-by-step revision in all of them in order to enhance their functionality and
then eliminate their drawbacks.
Chapter 14, Abstract Window Toolkit: Mini project like programming example on CityMap
Applet. The applet shows the map of a city from top angle with five buttons, namely, Hospitals,
Shopping Malls, Police station, Post Office, and Stadium. If a user presses the Hospital button,
all the hospitals are shown on the map with a specific color and likewise for Malls, Police station,
Post office and Stadium.
Chapter 15, Swing: Explanation of new classes with examples and also includes a practical
programming example to create a mini text editor.
Chapter 16, Introduction to Advanced Java: Introductory sections on JSP, Java Beans, Jar
files and enterprise Java beans with lots of examples apart from enhanced coverage of servlets
and JDBC. This chapter also encompasses a login application built using servlets and database
to demonstrate how to create and use a web application.
viii Preface to the Second Edition

Content and Structure


This book comprises 16 chapters and two appendices. A brief outline of each chapter is as follows.
Chapter 1 focuses on the object-oriented concepts and principles. It provides real life mapping
of concepts and principles besides depicting them pictorially. In addition to this, the chapter also
provides an introduction to Unified Modeling Language (UML), which is a modeling language
to show classes, objects, and their relationship with other objects.
Chapter 2 introduces Java and its evolution from its inception to its current state. Besides
introducing the features of Java, it also tells you about the structure of JDK (Java Development
Kit) and the enhancements made to Java in its latest versions. It describes how to install and run
the JDK that is in turn required for executing a Java program.
Chapter 3 describes the basic programming constructs used in Java such as variables, data
types, identifiers, etc. Java reserved keywords are also depicted in this chapter. The operators
(arithmetic, relational, boolean, etc.) that act on variables are also explained in this chapter. For
each set of operators, we have provided sufficient examples along with their explanation and
output. Apart from variables and operators, this chapter focuses on statements like if and other
loops available in Java (for, while, do…while, and for...each).
Chapter 4 deals with classes and objects. A lot of practical problems and their solutions
have been discussed in this chapter. It begins with how to define classes, objects, and method
creation. Method overloading is also discussed. Later, it emphasizes on the differences between
instance variables/methods and class variables and methods. Finally, a discussion about arrays,
this keyword, and command-line arguments is also provided.
Chapter 5 focuses on inheritance and its uses. How it is realized in Java is discussed in this
chapter. Apart from this, polymorphism concepts are visualized through method overriding and
super keyword. How practical programming problems are solved through super keyword forms
a major part of this chapter. Towards the end of the chapter, some related concepts like abstract
classes are also discussed.
Chapter 6 covers interfaces, packages, and enumeration. It highlights the differences between
abstract classes and interfaces and their practical usages with examples. The role of packages in
Java and their creation and usage is also discussed. In-depth coverage of a predefined package
java.lang is included in this chapter along with some of the famous classes such as String,
StringBuffer, StringBuilder, and Wrapper classes.
Chapter 7 discusses exceptions in detail. Apart from explaining in detail the five keywords
(try, catch, throw, throws, and finally) used in handling exceptions, it also discusses how a user
can create his own exceptions and handle them. Concepts such as exception, encapsulation, and
enrichment are also explained in this chapter. Besides these, the new facilities provided by Java
like assertions and logging are also discussed.
Chapter 8 covers multithreading concepts, its states, priorities, etc. It also discusses in detail
the inter-thread communication and synchronization concepts. Methods like wait(), notify(), and
notifyAll() have also been discussed.
Chapter 9 emphasizes on the essentials of I/O concepts like how standard input can be taken
and how output is delivered to the standard output. A few main classes of the java.io package
are discussed with examples and their usages. Console class, used for taking user input, is also
discussed. What is the use of making objects persistent and how will it be done is discussed
towards the end of the chapter.
Chapter 10 discusses the java.util package in detail. The interfaces like Map, Set, and List
etc have been discussed in detail as well as their subclasses like LinkedList, ArrayList, Vector,
HashSet, HashMap, TreeMap, etc. Java 5 introduced a new feature named ‘Generics’ which
Preface to the Second Edition ix

forms the core of the java.util package. This concept along with its application has been covered
in detail.
Chapter 11 explains how network programming can be done in Java. In-depth coverage of
sockets is extended in this chapter. Client and server concept is illustrated by the programs
created. TCP and UDP clients and server and their interactions are demonstrated. The concept
of multithreading is merged with socket and illustrated to create server programs. Some main
classes such as URL, URL connection, and network interface (new feature) are also discussed.
Chapter 12 focuses on applets, its lifecycle, methods, etc. and how they are different from
applications. Besides providing an in-depth coverage of java.applet package, some of the
classes of java.awt package are also discussed as they are very useful in creating applets such
as Graphics class, Font class, Color class, and FontMetric class. All these classes are discussed
and supported by an example for each of them.
Chapter 13 talks about event handling in Java. Basically for creating effective GUI applications,
we need to handle events and this forms the basis of this chapter. The event handling model is
not only discussed but applied throughout the chapter. All the approaches to event handling have
been discussed such as Listener interfaces, Adapter classes, inner classes, and anonymous inner
classes.
Chapter 14 focuses on GUI creation through java.awt package. It has an in-depth coverage
of containers and components. Containers like Frame, Window, etc. and components like Label,
Button, TextField, Choice, Checkbox, List, etc. are discussed in detail. How the components can
be arranged in a container is also discussed, e.g. BorderLayout, GridBagLayout, and GridLayout.
Chapter 15 shows how to create more advanced and lightweight GUI applications in Java.
More advanced layouts like SpringLayout have been discussed. Lightweight components like
JButton, JLabel, JCheckBox, JToggleButton, JList, JScrollPane, JTabbedPane, etc. have been
discussed. How to create Dialogs is also discussed. The pluggable look and feel of Java is
explained in detail.
Chapter 16 focuses on advanced Java concepts such as servlets, JDBC, and RMI. An
introduction to the advanced technologies has been discussed. This chapter is equipped with
numerous figures showing how to install the necessary softwares required for executing an
advanced Java program. The chapter also provides a step-by-step and simplified approach on
how to learn advanced concepts.
Appendix A on practical lab problems will facilitate better understanding of the concepts
explained in the book. Appendix B includes a list of interview questions along with their answers
that provides an overview of the industry scenario and their requirements.

ACKNOWLEDGEMENTS
Several people have been instrumental throughout this tiring yet wonderful journey. First of all, we
would like to express our sincere gratitude to our families without whose support, patience, and
cooperation, this would not have been possible and we would not have been what we are today.
We are also thankful to our colleagues and friends for their endless support and suggestions
during the entire process of writing this book. Lastly, we would also like to thank all our readers
/students who have supported us, encouraged us, and provided feedback to us regularly which
has helped us in shaping this edition.
Sachin Malhotra
Saurabh Choudhary
Brief Contents
Preface to the Second Edition vi
Preface to the First Edition x
Detailed Contents xiii
1. Introduction to OOP 1
2. Getting Started With Java 12
3. Java Programming Constructs 42
4. Classes and Objects 74
5. Inheritance 132
6. Interfaces, Packages, and Enumeration 156
7. Exception, Assertions, and Logging 199
8. Multithreading in Java 224
9. Input/Output, Serialization and Cloning 256
10. Generics, java.util and other API 296
11. Network Programming 336
12. Applets 354
13. Event Handling in Java 394
14. Abstract Window Toolkit 429
15. Swing 495
16. Introduction to Advanced Java 553
Appendix A: Lab Manual 628
Appendix B: Interview Questions 650
Index 657
Detailed Contents
Preface to the Second Edition vi
Preface to the First Edition x

1. Introduction to OOP 1 2.6.6 Java is Multithreaded 20


2.6.7 Other Features 20
1.1 Introduction 1
2.7 Program Structure 21
1.2 Need of Object-Oriented
Programming 2 2.7.1 How to Execute a Java
Program 21
1.2.1 Procedural Languages 2
2.7.2 Why Save as Example.Java? 22
1.2.2 Object-Oriented Modeling 2
2.7.3 Explanation 22
1.3 Principles of Object-Oriented
2.8 Java Improvements 23
Languages 3
2.8.1 Java 5.0 Features 23
1.3.1 Classes 3
2.8.3 Java 6 Features 25
1.3.2 Objects 3
2.8.4 Java 7 Features 26
1.3.3 Abstraction 3
2.8.4 Brief Comparison of Different
1.3.4 Inheritance 4
Releases 27
1.3.5 Encapsulation 4
2.9 Differences between Java and C++ 28
1.3.6 Polymorphism 5
2.10 Installation of JDK 1.7 29
1.4 Procedural Language vs OOP 5
2.10.1 Getting Started With the JDK 29
1.5 OOAD Using UML 6
2.10.2 JDK Installation Notes 29
1.6 Applications of OOP 9
2.10.3 Exploring the JDK 37
2. Getting Started With Java 12 2.11 Integrated Development
Environment 39
2.1 Introduction 12
2.2 History of Java 13 3. Java Programming Constructs 42
2.3 Java’s Journey: From Embedded Systems
3.1 Variables 42
To Middle-Tier Applications 13
3.2 Primitive Data Types 42
2.4 Java Essentials 14
3.3 Identifier 44
2.5 Java Virtual Machine 15 3.3.1 Rules for Naming 44
2.6 Java Features 16 3.3.2 Naming Convention 44
2.6.1 Platform Independence 16 3.3.3 Keywords 45
2.6.2 Object Oriented 16 3.4 Literals 45
2.6.3 Both Compiled and Interpreted 17 3.5 Operators 48
2.6.4 Java is Robust 18 3.5.1 Binary Operators 48
2.6.5 Java Language Security 3.5.2 Unary Operators 54
Features 18 3.5.3 Ternary Operator 54
xiv Detailed Contents

3.6 Expressions 55 4.9 this Keyword 103


3.7 Precedence Rules and 4.10 Arrays 105
Associativity 55 4.10.1 One-Dimensional Arrays 105
3.8 Primitive Type Conversion 4.10.2 Two-Dimensional Arrays 110
and Casting 57 4.10.3 Using for-each With Arrays 115
3.9 Flow of Control 61 4.10.4 Passing Arrays to Methods 115
3.9.1 Conditional Statements 62 4.10.5 Returning Arrays from
3.9.2 Loops 65 Methods 116
3.9.3 Branching Mechanism 68 4.10.6 Variable Arguments 117
4.11 Command-line Arguments 118
4. Classes and Objects 74 4.12 Nested Classes 119
4.1 Classes 74 4.12.1 Inner Class 119
4.2 Objects 75 4.12.2 Static Nested Class 122
4.2.1 Difference between Objects 4.12.3 Why Do We Create Nested
and Classes 76 Classes? 124
4.2.2 Why Should We Use 4.13 Practical Problem: Complex
Objects and Classes? 76 Number Program 124
4.3 Class Declaration in Java 77
4.3.1 Class Body 78 5. Inheritance 132
4.4 Creating Objects 79 5.1 Inheritance vs Aggregation 132
4.4.1 Declaring an Object 79 5.1.1 Types of Inheritance 133
4.4.2 Instantiating an Object 79 5.1.2 Deriving Classes Using
4.4.3 Initializing an Object 80 Extends Keyword 135
4.5 Methods 82 5.2 Overriding Method 137
4.5.1 Why Use Methods? 82 5.3 super Keyword 141
4.5.2 Method Types 82 5.4 final Keyword 146
4.5.3 Method Declaration 83 5.5 Abstract Class 147
4.5.3 Instance Method Invocation 86 5.6 Shadowing vs Overriding 149
4.5.4 Method Overloading 87 5.7 Practical Problem: Circle
4.6 Constructors 90 and Cylinder Class 151
4.6.1 Parameterized Constructors 93
6. Interfaces, Packages, and
4.6.2 Constructor Overloading 94
Enumeration 156
4.7 Cleaning Up Unused Objects 96
4.7.1 The Garbage Collector 96 6.1 Interfaces 156
4.7.2 Finalization 97 6.1.1 Variables in Interface 158
4.7.3 Advantages and Disadvantages 97 6.1.2 Extending Interfaces 160
4.8 Class Variable and 6.1.3 Interface vs Abstract Classes 160
Methods—Static Keyword 97 6.2 Packages 161
4.8.1 Static Variables 98 6.2.1 Creating Packages 162
4.8.2 Static Methods 99 6.2.2 Using Packages 164
4.8.3 Static Initialization Block 101 6.2.3 Access Protection 168
Detailed Contents xv

6.3 java.lang Package 169 8.4 Main Thread 227


6.3.1 java.lang.Object Class 169 8.5 Creation of New Threads 228
6.3.2 Java Wrapper Classes 170 8.5.1 By Inheriting the Thread
6.3.3 String Class 174 Class 228
6.3.4 StringBuffer Class 179 8.5.2 Implementing the Runnable
6.3.5 StringBuilder Class 180 Interface 231
6.3.6 Splitting Strings 181 8.6 Thread.State in Java 234
6.4 Enum Type 183 8.6.1 Thread States 235
6.4.1 Using Conditional Statements with 8.7 Thread Priority 240
an Enumerated Variable 185 8.8 Multithreading—Using isAlive()
6.4.2 Using for Loop for Accessing and join() 243
Values 185 8.9 Synchronization 245
6.4.3 Attributes and Methods Within 8.9.1 Synchronized Methods 246
Enumeration 186 8.9.2 Synchronized Statements 246
6.5 Practical Problem: Banking 8.10 Suspending and Resuming Threads 246
Example 187 8.11 Communication between
Threads 248
7. Exception, Assertions, 8.12 Practical Problem: Time
and Logging 199 Clock Example 251
7.1 Introduction 199
7.1.1 Exception Types 201 9. Input/Output, Serialization
and Cloning 256
7.2 Exception Handling Techniques 202
7.2.1 try…catch 203 9.1 Introduction 256
7.2.2 throw Keyword 206 9.1.1 java.io.InputStream and
7.2.3 throws 207 java io.OutputStream 257
7.2.4 finally Block 209 9.2 java.io.File Class 258
7.2.5 try-with-resources 9.3 Reading and Writing Data 261
Statement 210 9.3.1 Reading/Writing Files Using Byte
7.2.6 Multi Catch 212 Stream 261
7.2.7 Improved Exception Handling 9.3.2 Reading/Writing Console
in Java 7 213 (User Input) 264
7.3 User-Defined Exception 215 9.3.3 Reading/Writing Files Using
7.4 Exception Encapsulation Character Stream 269
and Enrichment 216 9.3.4 Reading/Writing Using Buffered
7.5 Assertions 217 Byte Stream Classes 270
7.6 Logging 219 9.3.5 Reading/Writing Using Buffered
Character Stream Classes 272
8. Multithreading in Java 224
9.4 Randomly Accessing a File 273
8.1 Introduction 224 9.5 Reading and Writing Files
8.2 Multithreading in Java 225 Using New I/O Package 276
8.3 java.lang.Thread 225 9.6 Java 7 Nio Enhancements 278
xvi Detailed Contents

9.7 Serialization 283 12. Applets 354


9.8 Cloning 285 12.1 Introduction 354
12.2 Applet Class 355
10. Generics, java.util and other API 296
12.3 Applet Structure 356
10.1 Introduction 296 12.4 Example Applet Program 357
10.2 Generics 301 12.4.1 How to Run an Applet? 358
10.2.1 Using Generics in Arguments and 12.5 Applet Life Cycle 359
Return Types 304 12.6 Common Methods Used in
10.2.2 Wildcards 304 Displaying the Output 361
10.2.3 Bounded Wildcards 306 12.7 paint(), update(), and repaint() 364
10.2.4 Defining Your Own 12.7.1 paint() Method 364
Generic Classes 307 12.7.2 update() Method 365
10.3 Linked List 309 12.7.3 repaint() Method 366
10.4 Set 311 12.8 More About Applet Tag 366
10.4.1 Hashset Class 312 12.9 getDocumentbase() and
10.4.2 Treeset Class 314 getCodebase() Methods 369
10.5 Maps 315 12.10 Appletcontext Interface 370
10.5.1 Hashmap Class 315 12.10.1 Communication between Two
Applets 371
10.5.2 Treemap Class 317
12.11 How To Use An Audio Clip? 372
10.6 Collections Class 318
12.12 Images in Applet 373
10.7 Legacy Classes and Interfaces 319
12.12.1 Mediatracker Class 375
10.7.1 Difference between Vector
12.13 Graphics Class 377
and Arraylist 319
12.13.1 An Example Applet Using
10.7.2 Difference between Enumerations
Graphics 379
and Iterator 320
12.14 Color 380
10.8 Utility Classes: Random Class 320
12.15 Font 382
10.8.1 Observer and Observable 322
12.16 Fontmetrics 386
10.9 Runtime Class 326
12.17 Practical Problem: Digital Clock 390
10.10 Reflection API 328
13. Event Handling in Java 394
11. Network Programming 336
13.1 Introduction 394
11.1 Introduction 336 13.2 Event Delegation Model 395
11.1.1 TCP/IP Protocol Suite 336 13.3 java.awt.Event Description 395
11.2 Sockets 337 13.3.1 Event Classes 395
11.2.1 TCP Client and Server 338 13.4 Sources of Events 404
11.2.2 UDP Client and Server 342 13.5 Event Listeners 404
11.3 URL Class 344 13.6 How Does The Model Work? 406
11.4 Multithreaded Sockets 346 13.7 Adapter Classes 410
11.5 Network Interface 349 13.7.1 How To Use Adapter Classes 410
Detailed Contents xvii

13.7.2 Adapter Classes in Java 412 15. Swing 495


13.8 Inner Classes in Event Handling 413
15.1 Introduction 495
13.9 Practical Problem: Cartoon
15.1.1 Features of Swing 496
Applet 416
15.1.2 Differences between
13.9.1 Smiling Cartoon With Blinking Swing and AWT 496
Eyes (Part 1) 416
15.2 JFrame 497
13.9.2 Smiling Cartoon With Blinking
15.3 JApplet 500
Eyes (Part 2) 420
15.4 JPanel 501
13.9.3 Smiling Cartoon (Part 3) 423
15.5 Components in Swings 502
14. Abstract Window Toolkit 429 15.6 Layout Managers 506
15.6.1 Springlayout 506
14.1 Introduction 429 15.6.2 Boxlayout 509
14.1.1 Why Awt? 429 15.7 JList and JScrollPane 510
14.1.2 java.awt Package 430 15.8 Split Pane 513
14.2 Components and Containers 432 15.9 JTabbedPane 514
14.2.1 Component 432 15.10 JTree 516
14.2.2 Components as Event 15.11 JTable 521
Generator 433 15.12 Dialog Box 525
14.3 Button 434 15.13 JFileChooser 529
14.4 Label 437 15.14 JColorChooser 530
14.5 Checkbox 438 15.15 Pluggable Look and Feel 531
14.6 Radio Buttons 441 15.16 Inner Frames 539
14.7 List Boxes 444 15.17 Practical Problem: Mini Editor 545
14.8 Choice Boxes 448
16. Introduction to Advanced Java 553
14.9 Textfield and Textarea 451
14.10 Container Class 455 16.1 Introduction to J2ee 553
14.10.1 Panels 455 16.2 Database Handling Using JDBC 553
14.10.2 Window 456 16.2.1 Load the Driver 554
16.2.2 Establish Connection 556
14.10.3 Frame 456
16.2.3 Create Statement 556
14.11 Layouts 458
16.2.4 Execute Query 557
14.11.1 FlowLayout 459
16.2.5 Iterate Resultset 557
14.11.2 BorderLayout 462
16.2.6 Scrollable Resultset 559
14.11.3 CardLayout 465
16.2.7 Transactions 560
14.11.4 GridLayout 469 16.3 Servlets 562
14.11.5 GridbagLayout 471 16.3.1 Lifecycle of Servlets 562
14.12 Menu 478 16.3.2 First Servlet 563
14.13 Scrollbar 483 16.3.3 Reading Client Data 567
14.14 Practical Problem: City 16.3.4 Http Redirects 571
Map Applet 487 16.3.5 Cookies 572
xviii Detailed Contents

16.3.6 Session Management 574 16.7.1 Creating a Jar File 605


16.4 Practical Problem: Login Application 577 16.7.2 Viewing the Contents of
16.5 Introduction to Java a Jar File 606
Server Pages 589 16.7.3 Extracting the Contents
16.5.1 JSP Life Cycle 589 of Jar 607
16.5.2 Steps in JSP Page Execution 590 16.7.4 Manifest Files 607
16.5.3 JSP Elements 590 16.8 Remote Method Invocation 609
16.5.4 Placing Your JSP in the 16.8.1 RMI Networking Model 609
Webserver 593
16.8.2 Creating an Rmi Application 610
16.6 Java Beans 597
16.9 Introduction to EJB 613
16.6.1 Properties of a Bean 597
16.9.1 Types of EJB 614
16.6.2 Using Beans Through JSP 601
16.6.3 Calculatebean Example 602 16.9.2 EJB Architecture 615
16.7 Jar Files 605 16.10 Hello World—EJB Example 616

Appendix A: Lab Manual 628


Appendix B: Interview Questions 650
Index 657
Introduction to
OOP 1
Beauty is our weapon against nature; by it we make objects, giving them limit,
symmetry, proportion. Beauty halts and freezes the melting flux of nature.
Camille Paglia

After reading this chapter, the readers will be able to


 know what is object-oriented programming

 understand the principles of OOP

 understand how is OOP different from procedural languages

 comprehend the problems in procedural programming and how OOP overcomes them

 learn the applications of OOP

 use UML notations

1.1 INTRODUCTION
Object-oriented programming (OOP) is one of the most interesting and useful innovations in
software development. OOP has strong historical roots in programming paradigms and practices.
It addresses the problems commonly known as the software crisis. Software have become
inherently complex which has led to many problems within the development of large software
projects. Many software have failed in the past. The term ‘software crisis’ describes software
failure in terms of
 Exceeding software budget
 Software not meeting clients’ requirements
 Bugs in the software
OOP is a programming paradigm which deals with the concepts of object to build programs
and software applications. It is modeled around the real world. The world we live in is full of
objects. Every object has a well-defined identity, attributes, and behavior. Objects exhibit the
same behavior in programming. The features of object-oriented programming also map closely
to the real-world features like inheritance, abstraction, encapsulation, and polymorphism. We
will discuss them later in the chapter.
2 Programming in Java

1.2 NEED OF OBJECT-ORIENTED PROGRAMMING


There were certain limitations in earlier programming approaches and to overcome these
limitations, a new programming approach was required. We first need to know what these
limitations were.
1.2.1 Procedural Languages
In procedural languages, such as C, FORTRAN, and PASCAL, a program is a list of instructions.
The programmer creates a list of instructions to write a very small program. As the length of a
program increases, its complexity increases making it difficult to maintain a very large program.
In the structured programming, this problem can be overcome by dividing a large program into
different functions or modules, but this gives birth to other problems. Large programs can still
become increasingly complex. There are two main problems in procedural language—(i) the
functions have unrestricted access to global data and (ii) they provide poor mapping to the real
world.
Here are some other problems in the procedural languages. Computer languages generally
have built-in data types: integers, character, float, and so on. It is very difficult to create a new
data type or a user-defined data type. For example, if we want to work with dates or complex
numbers, then it becomes very difficult to work with built-in types. Creating our own data types is
a feature called extensibility: we can extend the capabilities of a language. Procedural languages
are not extensible. In the traditional languages, it is hard to write and maintain complex results.
1.2.2 Object-Oriented Modeling
In the physical world, we deal with objects like person, plane, or car. Such objects are not like
data and functions. In the complex real-world situations, we have objects which have some
attributes and behavior. We deal with similar objects in OOP. Objects are defined by their unique
identity, state, and behavior. The state of an object is identified by the value of its attributes and
behavior by methods.
Attributes
Attributes define the data for an object. Every object has some attributes. Different types of
objects contain different attributes or characteristics. For example, the attributes of a student
object are name, roll number, and subject; and the attributes for a car object would be color,
engine power, number of seats, etc. These attributes will have specific values, such as Peter (for
name) or 23 (for roll number).
Behavior
The response of an object when subjected to stimulation is called its behavior. Behavior defines
what can be done with the objects and may manipulate the attributes of an object. For example,
if a manager orders an employee to do some task, then he responds either by doing it or not
doing it. The wings of a fan start moving only when the fan is switched ON. Behavior actually
determines the way an object interacts with other objects. We can say that behavior is synonym
to functions or methods: we call a function to perform some task. For example, an Employee
class will have functions such as adding an employee, updating an employee details, etc.
Introduction to OOP 3

Note If we try to represent the CPU of a computer in OOP terminology, then CPU is the object.
The CPU is responsible for fetching the instructions and executing them. So fetching and
executing are two possible functions (methods or behavior) of CPU. The place (attributes)
where CPU stores the retrieved instructions, values and result of the execution (registers) will
then be the attributes of the CPU.

1.3 PRINCIPLES OF OBJECT-ORIENTED LANGUAGES


OOP languages follow certain principles such as class, object, and abstraction. These principles
map very closely to the real world.
1.3.1 Classes
A class is defined as the blueprint for an object. It serves as a plan or a template. The description
of a number of similar objects is also called a class. An object is not created by just defining a
class. It has to be created explicitly. Classes are logical in nature. For example, furniture does
not have any existence but tables and chairs do exist. A class is also defined as a new data type,
a user-defined type which contains two things: data members and methods.
1.3.2 Objects
Objects are defined as the instances of a class, e.g. table, chair are all instances of the class
Furniture. Objects of a class will have same attributes and behavior which are defined in that
class. The only difference between objects would be the value of attributes, which may vary.
Objects (in real life as well as programming) can be physical, conceptual, or software. Objects
have unique identity, state, and behavior. There may be several types of objects:
 Creator objects: Humans, Employees, Students, Animal

 Physical objects: Car, Bus, Plane

 Objects in computer system: Monitor, Keyboard, Mouse, CPU, Memory

1.3.3 Abstraction
Can you classify the following items?
 Elephant  CD player

 Television  Chair

 Table  Tiger

How many classes do you identify here? The obvious answer anybody would give is three, i.e.,
Animal, Furniture, and Electronic items. But how do you come to this conclusion? Well, we
grouped similar items like Elephant and Tiger and focused on the generic characteristics rather
than specific characteristics. This is called abstraction. Everything in this world can be classified
as living or non-living and that would be the highest level of abstraction.
Another well-known analogy for abstraction is a car. We drive cars without knowing the
internal details about how the engine works and how the car stops on applying brakes. We are
happy with the abstraction provided to us, e.g., brakes, steering, etc. and we interact with them.
In real life, human beings manage complexity by abstracting details away. In programming,
we manage complexity by concentrating only on the essential characteristics and suppressing
implementation details.
4 Programming in Java

1.3.4 Inheritance
Inheritance is the way to adopt the characteristics of one class into another class. Here we have
two types of classes: base class and subclass. There exists a parent–child relationship among
the classes. When a class inherits another class, it has all the properties of the base class and it
adds some new properties of its own. We can categorize vehicles into car, bus, scooter, ships,
planes, etc. The class of animals can be divided into mammals, amphibians, birds, and so on.
The principle of dividing a class into subclass is that each subclass shares common
characteristics with the class from where they are inherited or derived. Cars, scooters, planes,
and ships all have an engine and a speedometer. These are the characteristics of vehicles. Each
subclass has its own characteristic feature, e.g., motorcycles have disk braking system, while
planes have hydraulic braking system. A car can run only on the surface, while a plane can fly
in air and a ship sails over water (see Fig. 1.1).

Vehicle

Road vehicle Air vehicle Water vehicle

Bus Motor bike Aeroplane Boat

Fig. 1.1 Inheritance

Inheritance aids in reusability. When we create a class, it can be distributed to other


programmers which they can use in their programs. This is called reusability. Suppose someone
wants to make a program for a calculator, he can use a predefined class for arithmetic operations,
and then he need not define all the methods for these operations. This is similar to using library
functions in procedural language. In OOP, this can be done using the inheritance feature. A
programmer can use a base class with or without modifying it. He can derive a child class from
a parent class and then add some additional features to his class.
1.3.5 Encapsulation
Encapsulation is one of the features of object-oriented methodology. The process of binding
the data procedures into objects to hide them from
the outside world is called encapsulation (see Fig.
1.2). It provides us the power to restrict anyone from
directly altering the data. Encapsulation is also known Method
as data hiding. An access to the data has to be through
the methods of the class. The data is hidden from the Method Data
outside world and as a result, it is protected. The details Accessing
that are not useful for other objects should be hidden data Method
from them. This is called encapsulation. For example,
an object that does the calculation must provide an
interface to obtain the result. However, the internal
coding used to calculate need not be made available Fig. 1.2 Diagrammatic Illustration of a
to the requesting object. Class to Show Encapsulation
Introduction to OOP 5

1.3.6 Polymorphism
Polymorphism simply means many forms. It can be defined as the same thing being used in
different forms. For example, there are certain bacteria that exhibit in more than one morphological
form. In programming, polymorphism is of two types: compile-time and runtime polymorphism.
Runtime polymorphism, also known as dynamic binding or late binding, is used to determine
which method to invoke at runtime. The binding of method call to its method is done at runtime
and hence the term late binding is used. In case of compile-time polymorphism, the compiler
determines which method (from all the overloaded methods) will be executed. The binding of
method call to the method is done at compile time. So the decision is made early and hence
the term early binding. Compile-time polymorphism in Java is implemented by overloading
and runtime polymorphism by overriding. In overloading, a method has the same name with
different signatures. (A signature is the list of formal argument that is passed to the method.)
In overriding, a method is defined in subclass with the same name and same signature as that
of parent class. This distinction between compile-time and runtime polymorphism is of method
invocation. Compile-time polymorphism is also implemented by operator overloading which
is a feature present in C++ but not in Java. Operator overloading allows the user to define new
meanings for that operator so that it can be used in different ways. The operator (+) in Java is
however an exception as it can be used for addition of two integers as well as concatenation of
two strings or an integer with a string. This operator is overloaded by the language itself and
the Java programmer cannot overload any operator.

1.4 PROCEDURAL LANGUAGE VS OOP


Table 1.1 highlights some of the major differences between procedural and object-oriented
programming languages.
Table 1.1 Procedural Language vs OOP
Procedural Language OOP
 Separate data from functions that operate on them.  Encapsulate data and methods in a class.
 Not suitable for defining abstract types.  Suitable for defining abstract types.
 Debugging is difficult.  Debugging is easier.
 Difficult to implement change.  Easier to manage and implement change.
 Not suitable for larger programs and applications.  Suitable for larger programs and applications.
 Analysis and design not so easy.  Analysis and design made easier.
 Faster.  Slower.
 Less flexible.  Highly flexible.
 Data and procedure based.  Object oriented.
 Less reusable.  More reusable.
 Only data and procedures are there.  Inheritance, encapsulation, and polymorphism are the
key features.
 Use top-down approach.  Use bottom-up approach.
 Only a function call another.  Object communication is there.
 Example: C, Basic, FORTRAN.  Example: JAVA, C++, VB.NET, C#.NET.
6 Programming in Java

1.5 OOAD USING UML


An object-oriented system comprises of objects. The behavior of a system results from its objects
and their interactions. Interaction between objects involves sending messages to each other.
Every object is capable of receiving messages, processing them, and sending to other objects.
Object-oriented Analysis and Design (OOAD)
It is an approach that models software as a group of interacting objects. A model is a description
of the system that we intend to build. Each object is characterized by its class having its own state
(attributes) and behavior. Object-oriented analysis (OOA) analyzes the functional requirements
of a system and focuses on what the system should do. Object-oriented design (OOD) focuses on
how the system does it. The most popular modeling language for OOAD is the unified modeling
language (UML).
UML is a standard language for OOAD. It contains graphical notations for all entities (class,
object, etc.) used in the object-oriented languages along with the relationship that exists among
them. These notations are used to create models. UML helps in visualizing the system, thereby
reducing complexity and improving software quality. The notations used for class and object are
shown in Fig. 1.3. For example, consider an Employee class with attributes name, designation,
salary, etc. and operations such as addEmployee, deleteEmployee, and searchEmployee.
The notation for employee class and its object is as follows:

Employee Class
name
address
designation Attributes
salary

addEmployee
deleteEmployee Behavior
searchEmployee

Fig. 1.3 UML Notation for Class


The notation for an object is very much similar to the class notation. The class name underlined
and followed by a colon represents an object (Fig. 1.4).

:Employee Object
name=peter
address=NY
designation=manager Attributes
salary=10000

addEmployee
deleteEmployee
searchEmployee

Fig. 1.4 UML Notation for Object


Introduction to OOP 7

An instance of a class can be related to any number of instances of other class known as
multiplicity of the relation. One-to-one, one-to-many, and many-to-many are different types
of multiplicities that exist among objects. The multiplicities along with their examples and
respective notations are shown below. Figure 1.5(a) illustrates the generic notation for representing
multiplicity in object-oriented analysis and design. One-to-one mapping is shown as a straight
line between the two classes. Figure 1.5(b) shows the UML notation for demonstrating the one-
to-one mapping. The 1..1 multiplicity depicted on the straight line (both ends) indicates a single
instance of a class is associated with single instance of other class. Figure 1.5 shows that each
country has a president and a president is associated with a country.

Country has Country 1.1 has 1.1


President President

(a) (b)

Fig. 1.5 One-to-one Relationship

A country has many states and many states belong to a country. So there exists a one-to-many
relationship between the two. This relationship is shown in Fig. 1.6. Part (a) of this figure shows
the generic notation where a solid dot is indicated on the many side and both classes are joined
by a straight line. Figure 1.6(b) shows the UML notation where 1..* indicates the one to many
relationship between country and states. On the country end, a 1..1 multiplicity is placed to
indicate one country and on states end, a 1..* is placed to indicate many states.

has 1..1 has 1..*


Country States Country States

(a) (b)

Fig. 1.6 One-to-many Relationship

Let us take another example to explain many-to-many relationship. A teacher teaches many
students and a student can be taught by many teachers. There exists a many-to-many relationship
between them. Many-to-many relationship (Generic notation in OOAD) are represented by
placing solid dots on both ends joined by a straight line as shown in Fig. 1.7(a). The respective
notation in UML is shown in Fig. 1.7(b) where 1..* on both ends is used to signify many-to-
many relationship.

teaches 1..* teaches 1..*


Teacher Student Teacher Student

(a) (b)

Fig. 1.7 Many-to-many Relationship


8 Programming in Java

Besides multiplicity of relations, the relationships can be of various types: inheritance,


aggregation, composition. These relationships can be denoted in UML with links and associations.
The links represent the connection between the objects and associations represent groups of links
between classes. If a class inherits another class, then there exists a parent-child relationship
between them. This relationship is depicted in UML as shown in Fig. 1.8. For example, Shape
is the superclass, and the subclasses of Shape can take any shape, e.g., Square, Triangle, etc.

Shape

Triangle Square

Fig. 1.8 UML Diagram Depicting Inheritance


The above diagram can be extended to depict the OOP principle of polymorphism. Every shape
will have a method named area() which would calculate the area of that shape. The implementation
of area() method would be different for different shapes. For example, the formula for calculating
area of a triangle is different from a square. So the implementation is different but the name of
the method is same. This is polymorphism (one name many implementations). In Fig 1.9 below,
the area() method is overridden by Triangle and Square classes.

Shape

area( )

Triangle Square Rectangle

area( ) area( ) area( )

Fig. 1.9 UML Diagram Depicting Polymorphism

Another kind of relationship that exists among objects is the part-of-relationship. When a
particular object is a part of another object then we say that it is aggregation. For example, car is
Introduction to OOP 9

an aggregation of many objects: engine, door, etc. and engine in turn is an aggregation of many
objects, e.g., cylinder, piston, valves, etc. as shown in Fig. 1.10(a). A special kind of aggregation
is composition where one object owns other objects. If the owner object does not exist, the
owned objects also ceases to exist. For example, the human body is a very good example of
composition. It is a composition of different organs. The hands, feet, and internal organs such
as the lung and intestine are also parts of the body owned by the body.

Car

Human body
Engine Door

Cylinder Radiator Liver Lungs

(a) (b)

Fig. 1.10 (a) Aggregation and (b) Composition

1.6 APPLICATIONS OF OOP


The basic thought behind object-oriented language is to make an object by combining data and
functions as a single unit and then operate on that data. In procedural approach, the focus is on
business process and the data needed to support the process. For example, in the last decade, a
problem bothered every programmer, popularly known as the Y2K problem. Everybody related
to the computer industry was afraid of what will happen past midnight 31 December 1999. The
problem arises due to the writing convention of the year attribute. In early programming days,
a programmer wrote a year in two digits, so there was a problem to distinguish the year 1900
from 2000 because if we write only the last two digits of a year, the computer cannot differentiate
between the two. Nobody perceived this problem and used the date and year code as and when
required, thus aggravating the problem. The solution to this problem was to analyze multiple
lines of codes everywhere and change the year to four digits rather than two. It seems simple to
change the state variable of year but analyzing a code of several thousands of lines to find how
many times you have used date in your code is not an easy task.
If object-oriented programming language had been used, we could have created a Date class
with day, month, and year attributes in it. Wherever the date functionality would be required,
10 Programming in Java

a Date object would be created and used. At a later point of time, if a change is required, for
example, the year of Date class needs to be changed to four digits, then this change would be
incorporated in the class only and this change would automatically be reflected in all the objects
of the Date class whenever they are created and used. So, the change would have to be done at
one place only, i.e., the class and wherever the objects of the class are being used, the changes
would be reflected automatically. There is no need to analyze the whole code and change it.
In OOP, we access data with the help of objects, so it is very easy to overcome a problem
without modifying the whole system. Likewise, OOP is used in various fields, such as
 Real-time systems  Neural networks

 Artificial intelligence  Database management

 Expert systems

SUMMARY
Object-oriented languages have become an ubiquitous large projects, a technique known as OOAD is used.
standard for programming. They have been derived Object-oriented analysis and design deals with how a
from the real world. OOP revolves around objects and system is modeled. OOA deals with what the system
classes. A class is defined as a group of objects with should do and OOD deals with how the system
similar attributes and behavior. OOP is a programming achieves what has been specified by OOA.
paradigm which deals with the concepts of objects to OOAD is realized with the help of a language known
develop software applications. Certain principles have as UML. UML stands for unified modeling language;
been laid down by OOP which are followed by every it is a standard language used for visualizing the
OOP language. These principles are: inheritance, software. An abstract model is created for the entire
abstraction, encapsulation, and polymorphism. software using graphical notations provided by UML.
We have presented a detailed comparison of
procedural and object-oriented languages. For building

EXERCISES
Objective Questions
1. In an object model, which one of the following is (c) Polymorphism (d) None of the above
true? 4. Which one of the following terms must relate to
(a) Abstraction, encapsulation, and multitasking polymorphism?
are the major principles (a) Static allocation (b) Static typing
(b) Hierarchy, concurrency, and typing are the
(c) Dynamic binding (d) Dynamic allocation
major principles
5. Providing access to an object only through its
(c) Abstraction, encapsulation, and polymor-
phism are the major principles member functions, while keeping the details
(d) Typing is the major principle private is called
(a) Information hiding (b) Encapsulation
2. Which one of the following is not an object-
(c) Modularity (d) Inheritance
oriented language?
(a) Simula (b) Java 6. The concept of derived classes is involved in
(c) C++ (d) C (a) Inheritance
3. The ability to hide many different implementations (b) Encapsulation
behind an interface is. (c) Data hiding
(a) Abstraction (b) Inheritance (d) Abstract data types
Introduction to OOP 11

7. Inheritance is a way to (d) All the above


(a) Organize data 9. Which of the following is true about class?
(b) Pass arguments to objects of classes (a) Class possesses data and methods
(c) Add features to existing classes without (b) Classes are physical in nature
rewriting them (c) Collection of similar type of objects is a class
(d) Improve data-hiding and encapsulation (d) Both (a) and (c)
8. UML is used for 10. Which of the following is true about procedural
(a) Creating models languages?
(b) Representing classes, objects and their (a) Debugging is easier
(b) analysis and design is easy
relationships pictorially
(c) less reusable
(c) Reducing complexity and improving software
(d) difficult to implement changes
quality

Review Questions
1. Explain the importance of object-oriented pro- 4. Write short notes on: (a) inheritance, (b) poly-
gramming languages. morphism, (c) abstraction, (d) encapsulation.
2. Explain the difference between class and object. 5. Differentiate between runtime and compite-time
3. Differentiate between procedural languages and polymorphism.
OOP languages.

Programming Exercises
1. Identify the relevant classes along with their A hospital wants to keep track of scheduled
attributes for the following: A departmental store appointments of a patient with his doctor. When
needs to maintain an inventory of cosmetic items a patient is given an appointment, he should be
which might be found there. You should include given a confirmation that states the time and date
female as well as male cosmetic items. Keep of appointment along with the doctor’s name.
information on all items such as item name, Meanwhile the doctor should also be informed
category, manufacturer, cost, date purchased, about the patient details. Each doctor has one
and serial number. weekday as off-day and no patients should be
2. Identify the relevant classes along with their assigned to a doctor on that day.
attributes from the following problem specification:

Answers to Objective Questions


1. (c) 2. (d) 3. (c) 4. (c)
5. (b) 6. (a) 7. (c) 8. (d)
9. (d) 10. (c) and (d)
Getting Started
with Java 2
The road of life can only reveal itself as it is traveled; each turn in the road reveals a
surprise. Man’s future is hidden. Anon

After reading this chapter, the readers will be able to


 know the history of Java

 understand the features of Java and its runtime environment

 know the basic structure of a Java program

 know the details about JDK installation

 understand various constituents of JDK and its development environments

2.1 INTRODUCTION
Java is a popular and powerful language. Although it is a very simple language, there are a
number of subtleties that can trip up less-experienced programmers. Java is an object-oriented
programming language with a built-in application programming interface (API) that can handle
graphical user interfaces (GUI) used to create applications or applets. Java provides a rich set
of APIs apart from being platform-independent.
Much of the syntax in Java is similar to C and C++. One of the major differences between
Java and other languages is that it does not have pointers. However, the biggest difference is that
you are forced to write object-oriented code in Java. Procedural code is embedded in objects.
In Java, we distinguish between applications and applets, applications being programs that
perform functions similar to those written in other programming languages and applets are
programs that are meant to be embedded in a web page and downloaded over the Internet.
When a program is compiled, a byte code is generated which can be executed on any platform,
provided the runtime environment exists on the destination platform.
This chapter guides the readers to a step-by-step introduction to Java programming. An
important thrust of this chapter is to cover the features of Java from an object-oriented perspective.
It also gives an insight about the installation of Java runtime environment and the various
integrated development environments (IDEs) of Java.
This chapter also focusses on the different versions of Java (including the latest Java 7) and
the Core API’s (Java 7 is also known as Java 1.7).
Random documents with unrelated
content Scribd suggests to you:
—— (Virgil’s), xi. 492.
Ænobarbas (in Shakespeare’s Antony and Cleopatra), see
Enobarbus.
Ænone, v. 203.
Æschylus, i. 194; iv. 216; v. 56; vi. III; viii. 12; x. 33; xi. 284, 506; xii.
240, 260.
Æsop. See Fables by Æsop.
Ætna, v. 122.
Afrancesadoes (Spaniards), i. 428.
African (or Negro), i. 69.
Agamemnon (Æschylus), i. 221; v. 54; x. 81, 94, 98; xi. 284, 421; xii.
240, 260.
Agar (Welbore Ellis), vi. 369.
Agatha Friburg (in Kotzebue’s Lovers’ Vows), viii. 335.
Age of Elizabeth, The Lectures on, etc.; Lecture I.—Introductory, v.
175.
Agincourt, i. 285, 289, 425.
Aglaura (Suckling’s), viii. 57.
Agli, Messer, x. 300.
Agnes, or the Triumph of Principle, iv. 243 n.
—— (Mrs Radcliffe’s), viii. 126
—— (in Lillo’s Fatal Curiosity), ii. 212.
—— (in Molière’s School for Wives), viii. 76; xi. 276.
Agnese (opera by Paer), viii. 540.
Agnolo, Andrea d’. See Andrea del Sarto.
Agreeable Surprise, The (O’Keeffe’s), viii. 166, 167, 319, 387, 463.
Agriculture, On (Cowley), viii. 60.
Aickin, James, ii. 197, 199, 201.
Aikin, Dr John (Dr A.), ii. 198; xi. 505.
Ailsa, Craig of, ii. 64.
Aimwell (Farquhar’s Beaux’ Stratagem), viii. 10, 88.
Airy, Sir George, viii. 503.
Ajax, x. 94; xii. 10.
Akenside, Mark, i. 114; ii. 79; iii. 222; v. 68, 119, 375; xi. 573.
Aladdin, ix. 269.
Alastor, or the Spirit of Solitude (Shelley’s), x. 261, 265.
Albano, Francesco, i. 77; vi. 441; ix. 34, 111, 236.
—— Hills of, ix. 234, 254, 376.
Albany, The, xi. 486.
—— Duke of, ii. 80.
Albemarle Street, i. 370; iii. 217; iv. 367; xi. 423, 486, 487.
Albergo di Venezia (an inn), ix. 264.
Alberigi, Frederigo, i. 163, 331; vii. 303; x. 68; xi. 501.
Albigeois, The Civil Wars of the, x. 56.
Alcæus, iv. 271.
Alcamenes (painter), ix. 466.
Alcantara (town), iii. 290 n.
Alceste (in Molière’s Misanthrope), ix. 150–1
Alcestis, vi. 179; x. 97.
Alchymist, The (Ben Jonson’s), viii. 45, 227; x. 117, 171.
Alcibiades, i. 211 seq.; vii. 213; xi. 228.
Alcides, The (acrobats), vi. 442.
Alcinous, Gardens of, ix. 325; xi. 514.
Alderman Gripe (Wycherley’s Love in a Wood), viii. 78.
Aldermanbury, xi. 441.
Aldobrand (in Maturin’s Bertram), viii. 306–7.
Aldridge’s, ii. 174.
Ale-house Door (Wilkie’s), viii. 140; ix. 15; xi. 252.
Aleman, Mateo. See Guzman D’Alfarache.
Aleppo (referred to in Shakespeare’s Othello), xi. 283.
Alexander and Campaspe (John Lyly’s), v. 197, 201, 202.
—— Battle of (a picture), ix. 41.
—— of Aberdeen, ii. 209.
—— I. of Russia, iii. 56, 160, 306; iv. 189; ix. 479; xi. 415.
—— the Great, i. 291; ii. 67, 173; iv. 71; v. 124; vi. 106, 107; x. 15, 17,
26, 329; xi. 3, 234, 553; xii. 37, 204.
Alexander the Great (by Lee, Nathaniel), v. 357; vi. 342; vii. 301.
—— VI., Pope, Bower’s Life of, ii. 172.
—— the Spy, ii. 154 n.
Alexander’s Feast (Dryden’s), iv. 276; v. 81, 372; vi. 204 n.; xii. 347.
Alfieri, Count, x. 45, 232, 241; xi. 424.
Alfred (Wilkie’s), ix. 389.
Algiers, iii. 335, 442.
Alhambra, The, ix. 349.
Alice (in Scott’s Old Mortality), iv. 247.
—— Bridgenorth (in Scott’s Peveril of the Peak), xi. 540.
Alicia (in Rowe’s Jane Shore), viii. 352.
Alien Bill, The Scotch, ix. 214.
—— Office, The, ii. 248.
Alighieri, Family of the, x. 63.
Alithea (in Wycherley’s adaptation of Molière’s School for Wives),
viii. 76, 153, 554; xi. 276.
Allan, The bog of, v. 34.
Allen, Bobbie (Lamb’s schoolfellow), xi. 585.
Allen-a-Dale (in Scott’s Ivanhoe), iv. 209.
Allen, John, M.D., ix. 17.
All Fools (Chapman’s), v. 234.
All for Love (Dryden’s), viii. 190.
All-Foxden, vi. 183; xii. 269, 271.
All in the Wrong (Murphy’s), viii. 164.
Allston, Washington, xi. 189, 190, 456 n.
All’s Well that Ends Well (Shakespeare’s), i. 329;
also referred to, iii. 437; viii. 330; xi. 296.
Allworthy (in Fielding’s Tom Jones), vi. 452.
Almack’s, xi. 343.
Almanach des Gourmands, The, xi. 501.
Almeria (Congreve’s Mourning Bride), viii. 75.
Almeyda (in Dryden’s Don Sebastian), v. 357.
Alonzo (in Maywood’s Zanga), xi. 398.
Alphonso VI. of Castile and Leon, x. 57.
Alps, The, iv. 193; vii. 368; ix. 182, 188, 190, 195, 199, 207, 208, 240,
263, 264, 273, 277, 288, 290, 297, 303, 360; xi. 231; xii. 134.
Alpuente, Romero (Landor’s), x. 251.
Alric (in Holcroft’s The Noble Peasant), ii. 110.
Alsop, Mrs, viii. 252, 355, 361, 369, 370, 412, 524; xi. 277, 305.
Alsop’s Rosalind, Mrs, viii. 252.
Altarpiece of St Mark (Tintoretto’s), ix. 113.
Alton (town), vii. 126.
Altona (town), ii. 256.
Alwyn, or the Gentleman Comedian (Holcroft’s), ii. 95 seq., 280.
Amadis de Gaul (early romance), i. 133; vii. 253; x. 14, 19, 20, 57; xii.
62.
Amadis of Greece, x. 57.
Amanda (Vanbrugh’s Relapse), viii. 83.
Amanthis (in Mrs Inchbald’s Child of Nature), viii. 196.
Amaryllis, vii. 41.
—— (in Fletcher’s Faithful Shepherdess), v. 255.
Ambrogetti, Signor, viii. 365; xi. 308.
Ambrose Lamela (in Le Sage’s Gil Blas), vii. 380.
Ambrose (Wilson’s Noctes Ambrosianæ), xii. 367.
Amelia (Fielding’s), i. 130; vi. 457; vii. 84; viii. 114, 115, 152, 555; x.
32, 33; xi. 501; xii. 64.
—— Mammonton (in Ups and Downs), xi. 385, 387.
Amelia, the Princess (George II.’s daughter), x. 159.
—— Carolina Wilhelmina Skeggs (in Goldsmith’s Vicar of Wakefield),
iii. 313.
—— Wildenheim (in Lovers’ Vows, Mrs Inchbald’s adap. of
Kotzebue’s Natural Son), viii. 249, 336.
American Farmer’s Letters, The, x. 314.
—— Lion (Kean’s), xi. 332.
—— Literature—Dr Channing, x. 310.
—— Revolution, ii. 133; iii. 32 n., 279, 302, 304; vii. 52.
—— War, The, iii. 250, 420, 422, 424; vi. 385; x. 150–2; xii. 263, 293.
Americans, ix. 257.
Amiens, ii. 216; iii. 6, 61, 83, 99; vii. 227 n.
—— (Shakespeare’s As You Like It), xi. 367, 378; xii. 122.
Amine (in Arabian Nights), viii. 14.
Aminta (Tasso’s), x. 73.
Amintor (in Beaumont and Fletcher’s Maid’s Tragedy), v. 251, 252.
Amlet, Mrs (Vanbrugh’s Confederacy), viii. 14, 80.
Ammerbach (philosopher), x. 143.
Amory, John, i. 52.
Amours of Peter the Long (L. E. Billardson de Sauvigny), ii. 107.
Amphion, xi. 282.
Amphitheatre of Titus, ix. 234.
—— The (at Verona), ix. 277.
Amsterdam, vii. 100; ix. 295, 300, 301.
Amy Robsart (in Scott’s Kenilworth), ii. 314; iv. 248, 251.
Anabaptists, x. 360.
Anacharsis (traveller), vii. 255.
Anacreon, iv. 356; vii. 372 n.
Anacreon (Herrick’s translation), v. 312.
Anacreontics (Cowley’s), v. 372; viii. 59.
Anah (Byron’s), vii. 85.
Analogy (Butler’s), vi. 224; ix. 415; xii. 266, 346.
Analytical Review, The, ii. 116.
Ananias (Raphael’s), ix. 272 n.
Anastasius, vii. 220.
Anatomy of Melancholy (Burton’s), iv. 365; vi. 225.
Ancient Britons (the corps), ii. 176.
—— Mariner (Coleridge’s), iii. 205; iv. 218; v. 166, 377; viii. 14; xii.
236, 273, 319, 460.
—— Pistol (Shakespeare’s Henry IV., etc.), i. 425; iii. 54.
—— and Modern Literature, On Spirit of; On German Drama
contrasted with that of Age of Elizabeth, v. 345.
Ancona, View of (Wilson’s), xi. 199.
Andalusia, Castle of (O’Keeffe’s), viii. 329.
Anderson, Dr, v. 124.
Andes, iv. 193; vii. 255; viii. 415.
Andrea del Sarto, vi. 11; ix. 25, 51, 226.
Andromache (Racine’s), viii. 334.
Andromeda (Guido’s), vi. 441; viii. 253; ix. 61, 237.
Andrugio (in Marston’s Antonio and Mellida), v. 225.
Angelica (Congreve’s Love for Love), i. 133; viii. 15, 152, 555.
—— and Medora (a picture), ii. 212, 227; v. 3; x. 71.
Angelo (in Shakespeare’s Measure for Measure), i. 346, 347.
—— Michael. See Michael Angelo.
Angerstein, John Julius, vi. 174, 346; ix. 9, 35, 75, 113, 439.
Angerstein’s Collection, ix. 7.
Angiers, i. 311.
Anglade Family (or Accusation, by Payne), viii. 279.
Anglaises pour rire (a play), xi. 366.
Angler. See Complete Angler.
Angrisani (Signor), viii. 365, 371; xi. 308.
Anhalt (in Lovers’ Vows, Mrs Inchbald’s version of Kotzebue’s
Natural Son), viii. 249.
Anjou, Charles of, x. 56.
Anlaff the Dane (in Holcroft’s The Noble Peasant), ii. 110.
Anna, Verses upon (Gifford’s), iv. 302; vi. 221.
—— St Ives (Holcroft’s), ii. 128, 132, 136, 201, 279.
Annabel (in Holcroft’s The Man of Ten Thousand), ii. 160.
Annabella (in Ford’s ’Tis a Pity She’s a Whore), v. 269.
Anne Page (in Shakespeare’s Merry Wives), i. 350; ix. 36.
—— Queen, i. 8, 138; iii. 405; iv. 212, 217, 367; v. 82, 104, 105; vi. 113,
322, 323, 376, 445; viii. 96; x. 73, 205, 310, 358, 373, 374, 377,
378; xii. 405.
Annecy (town), i. 17; v. 100; vii. 304.
Annesley (a novel), x. 392.
Annual Anthology, iii. 211.
—— Register, ii. 56.
Annunciation (Guido’s), ix. 111.
Annus Mirabilis, The (Dryden’s), v. 81.
Anselme (in Molière’s L’Avare), xi. 379.
Anstey, Christopher, viii. 560.
Antæus, i. 160; iv. 38.
Antigone (Sophocles), x. 81, 97.
Antigonus (Shakespeare’s Winter’s Tale), i. 324.
Anti-Jacobin Review, i. 401; iii. 219, 238, 261, 262, 295; v. 164; x.
139, 158, 225.
Antinous, The (statue), vii. 167; viii. 149; ix. 107, 350, 378; xi. 228,
486, 542.
Antipholis (in Shakespeare’s Comedy of Errors), i. 351; iv. 341; vi. 58;
viii. 401.
Antipodes, xii. 279.
Antiquary (Scott’s), iv. 248; vii. 156; viii. 413, 425; ix. 202; xi. 558.
Antiquaries, Society of, viii. 335.
Antiquity, On, vii. 252.
Antonines, The, ix. 366.
Antonio (in Middleton’s Witch), v. 218.
—— (Shakespeare’s Merchant of Venice), i. 321; viii. 179, 250, 374; xi.
417.
—— (Godwin’s), iv. 210 n.; xii. 326.
—— and Mellida (Marston’s), v. 224, 225.
Antony (Shakespeare’s Julius Cæsar and Antony and Cleopatra), i.
197; iv. 183; vii. 264.
—— and Cleopatra (Shakespeare’s), i. 228; v. 50, 253; viii. 190;
also referred to, i. 195; v. 253; viii. 31, 389; ix. 27.
Antwerp, ix. 110, 300, 302, 492; xii. 48 n.
A. P. E., vii. 124, 207.
Ape, Lines on the Story of the (Merry’s), iv. 309 n.
Apelles (sculptor), vi. 74.
—— (in Lyly’s Alexander and Campaspe), v. 201.
Apemantus (Shakespeare’s Timon of Athens), i. 210 et seq.
Apennines, The, ix. 199, 207, 208, 209, 210, 254, 260, 263, 264, 276,
303; xii. 57, 134.
Apicius, xii. 141.
Apocalypse, The, vii. 199; xii. 280, 441.
Apollo, i. 34, 416; v. 83, 192; vi. 141; vii. 157; x. 349, 350; xi. 544; xii.
341.
—— (statues), iii. 169; v. 164; vi. 141; ix. 28, 107, 147, 164, 165 n., 169
n., 222, 223, 237, 240, 339, 340, 341, 350, 378, 379, 381, 430,
491–2; x. 341, 342, 344; xi. 196, 227, 228, 493.
Apollo and Daphne (Titian’s), ix. 74.
—— giving a Poet a Cup of Water (Poussin’s), vi. 172; ix. 24.
—— and the Seasons (R. Wilson’s), ix. 392; xi. 198.
Apollodorus, x. 100.
Apology for His Own Life (Cibber), viii. 160, 359.
Apostate, The (by Richard Lalor Sheil), v. 345; viii. 538.
Apostates, On Modern, iii. 155.
Apothecary (in Shakespeare’s Romeo and Juliet), ii. 368 n.
Apparitions, History of (Defoe’s), x. 382.
Appeal to Honour and Honesty (Defoe’s), x. 369 n.
—— from the New to the Old Whigs (Burke’s), iii. 32.
Appius and Virginia (Webster’s), v. 234.
Appleby, iii. 423; v. 148.
Application to Study, On, vii. 55.
Apprentice, The (Murphy’s), viii. 514.
Apuleius, Lucius, v. 199; vi. 201; x. 17, 18.
Apullius and Apullia (Turner’s), xi. 190.
Aquapendente (town), ix. 230.
Aquinas, Thomas, iv. 217; xii. 35.
Arabia, v. 88, 340 n.; xi. 560.
Arabian Nights, i. 46; ii. 347; iv. 337; v. 113; vi. 53, 408; vii. 23, 421
n.; viii. 12, 13, 14; ix. 69; x. 46.
Aram, Eugene, vi. 314; xii. 34.
Araminta (Vanbrugh’s Relapse), viii. 83.
Arbaces (in Beaumont and Fletcher’s King and no King), v. 252.
—— (in the opera Artaxerxes), viii. 248, 321, 451.
Arbe, The (river), ix. 292.
Arbela, The Battle of, vi. 107.
Arbuthnot, John, iii. 33; iv. 217; v. 78, 104, 105.
Arcadia, i. 338; ix. 324, 325.
—— Sir Philip Sidney’s, v. 98, 318, 319, 320, 321, 323, 324, 325, 326;
ix. 9, 10, 58; x. 14; xii. 282.
Arch of Constantine (Claude), ix. 54.
—— of Constantine, ix. 232.
Archangel, ii. 251.
Archbishop of Grenada, The (in Le Sage’s Gil Blas), x. 31.
Archer (in Farquhar’s Beaux’ Stratagem), viii. 14, 88; xii. 451, 452.
Archimago (in Spenser), v. 36.
Archimedes, iii. 151; vi. 377; x. 13; xii. 36.
Arcite (Chaucer), v. 21, 29, 30, 258.
Arctic Circle, The, xii. 253.
Arden of Feversham (play), i. 357.
—— Forest of, i. 185, 338, 339; xi. 367; xii. 122.
Arethusa, xii. 200.
—— (in Beaumont and Fletcher’s Philaster), v. 262.
Aretine, Peter, iii. 218; iv. 225; v. 186; viii. 10.
Aretino, Pietro (Titian’s supposed portrait of), ix. 354; xii. 30.
Arezzo, ix. 262, 302.
Argenis (Barclay’s), x. 145.
Arguing in a Circle, xii. 285.
Argus, The (a newspaper), xi. 386.
Argyll, Duke of, vi. 521.
—— 2nd Duke of, John Campbell, iii. 415.
—— The Duchess of, vi. 450.
—— in Prison (Northcote’s), vi. 341.
—— Place, vi. 358.
Ariadne, vi. 238; vii. 125; xii. 203.
Ariel (Shakespeare’s Tempest), i. 23, 238, 241, 245; iv. 216; v. 15, 151;
viii. 235, 236; ix. 177, 463; x. 116; xi. 179.
Ariosto, i. 161; iv. 257, 356; v. 3, 35, 45, 224; vi. 425; vii. 94, 252; ix.
29, 239, 266, 301; x. 9, 13, 16, 20, 45, 69, 70, 71, 73, 77, 409; xi.
235, 492.
Ariosto (Titian’s portrait of), ix. 270; xi. 30.
—— (Harington’s), v. 186; vi. 319 n.
Aristarchus, iv. 307.
Ariste (should be Valère), (in Molière’s L’Ecole des Femmes), xi. 356.
Aristocracy of Letters, On the, vi. 205.
Aristophanes, v. 56; viii. 28, 166; x. 99, 100, 112 n.
—— of Byzantium, i. 183.
Aristotle, i. 13, 123, 139; iv. 9 n., 143, 144, 283, 285; v. 360; vi. 107,
109, 198; vii. 248, 316; viii. 63, 93, 305; x. 143, 248, 249; xi. 97,
262; xii. 164, 326, 361, 370.
Arkwright (Sir Richard), ii. 175; vi. 456; vii. 165, 186; ix. 243 n.
Armelie (in L. Bonaparte’s Charlemagne), xi. 232, 235.
Armida (Ariosto’s), x. 71.
Armitage (racket-player), vi. 89.
Armstrong, John, ii. 169, 183, 194, 195; v. 119, 376; vi. 332.
Arnaud, Anthony, xi. 289.
—— Daniel, x. 55.
Arne, Michael, ii. 86.
—— Dr Thomas Augustine, ii. 86; viii. 451, 452.
Arno, The, ix. 211, 212, 221; xii. 134.
Arnold, S. J., viii. 224, 243, 244, 314, 322, 323, 463, 476.
Arpasia (in Bajazet), xi. 275.
Arragon, x. 56.
Arruntius (in Ben Jonson’s Sejanus), v. 264.
Arsinoe (in Molière’s Misanthrope), ix. 149.
Art, Fragments on, ix. 489.
—— of Walking the Streets. See Trivia.
Artamène (in Mlle. de Scudéry’s Artamène ou Le Grand Cyrus), xii.
61.
Artaxerxes (F. A. Arne’s), viii. 192;
also referred to in viii. 248, 320, 330, 451, 532; xi. 455 n.
Arthur, King, x. 20–21, 56; xii. 221.
—— (in Shakespeare’s King John), i. 306 et seq.; vii. 344.
Arthur’s Seat, ii. 314; ix. 98, 324, 336, 337.
—— —— View of (Nasmyth’s), xi. 247.
Artist, The (a magazine), vi. 416.
Artists, On the Old Age of, vii. 88.
Arts, On the Progress of the, i. 372.
—— are not Progressive, Why the, i. 160; ix. 489;
referred to, ix. 478.
Arundel, Thomas Howard, Earl of, ix. 34.
Arviragus (in Shakespeare’s Cymbeline), i. 182 seq.; v. 258; xi. 293.
Ascham, Roger, x. 236–7.
Ascot Heath, ii. 4, 5, 6.
Ashburton, Baron. See Dunning, John.
—— the Inn at, vi. 407.
Ashby-de-la-Zouch, ii. 14.
Ashmole, Elias, iii. 141.
Asia Minor, v. 199.
Aspasia (Landor’s), ii. 396; vii. 299.
Aspatia (in Beaumont and Fletcher’s Maid’s Tragedy), v. 251.
Aspin, Mr, ii. 205.
Ass (of Apuleius), x. 17, 18.
Assembly of the Just (Raphael’s), iii. 142; xii. 208.
—— of Saints (Raphael’s), ix. 380; xi. 227.
Assignation Scene, The (Hogarth’s), viii. 134.
Assizi, ix. 261.
Ass’s Foal, Ode to an (Coleridge’s), v. 164.
Assumption (Titian’s), ix. 273.
Astley, John, vii. 111.
Astley’s, xii. 49.
Astolpho (Ariosto’s), vii. 252.
Astræa, xi. 384.
Astrea and Cleopatra, Histories of, x. 14.
Astronomical Discourses, Dr Chalmers’s, iv. 230; xii. 279.
Asturias, xi. 317.
As You Like It (Shakespeare’s), i. 338;
also referred to in i. 185; vii. 260 n.; viii. 513; xi. 396.
Atala at the Tomb (Girodet’s), ix. 132.
At-all (in Abbe’s Double Gallant), viii. 162, 360.
Athalie (Racine’s), x. 106; xi. 452.
Athanasius, Creed of St, iii. 139, 269.
Athenæ Oxonienses (Wood’s), iii. 276.
Athenæum, The, xi. 386.
Athenians, xi. 312.
Athens, i. 4, 212; vi. 188, 448; vii. 95, 185, 254; ix. 381, 379, 466, 492;
x. 347; xii. 170.
Atherstone, ii. 14.
Atkins, Mr (actor), viii. 275.
—— Mrs, ii. 219.
Atkinson (in Fielding’s Tom Jones), vii. 214; viii. 114; x. 33.
Atlas (the horse), ii. 22.
—— The, vi. 505, 517, 520, 521, 522; ix. 484–5; x. 403; xii. 320, 339,
342, 346, 348, 350, 353, 354, 357, 360, 363, 364, 367, 369, 370,
377, 381, 386, 391, 394, 402.
Atterbury, Francis, iii. 408; v. 79; vii. 24; viii. 14.
Attica, ix. 325; xi. 495.
Atticus (Pope’s), ii. 79, 199.
Attila, ix. 267.
—— (Raphael’s), ix. 364.
Attributes (Samuel Clarke’s), xi. 118.
Attwood, Mr (actor), ii. 195, 222, 225.
Audrey (in Shakespeare’s As You Like It), i. 185, 340; iv. 348; v. 146;
viii. 167, 252, 319; xi. 367, 397.
Aufidius (in Shakespeare’s Coriolanus), i. 217; iii. 435; viii. 375.
Augustus (in Shakespeare’s Antony and Cleopatra), i. 230.
—— (statue), ix. 165, 221.
Auld Reekie School, The, viii. 478 n.
Auld Robin Gray (ballad), v. 141; vii. 253.
Aumerle (Shakespeare’s Richard II.), i. 273.
Aurelia, Duchess of Pietro Jacomo (in Marston’s Malcontent), v. 230.
Aurelio and Miranda (Boaden’s), ii. 218.
Aurora (newspaper), xi. 386.
—— (in Le Sage’s Gil Blas), xii. 141.
—— (Guido’s), ix. 237; xii. 36.
—— (Poussin’s), vi. 171.
Ausias (Italian author), x. 56.
Austerlitz, i. 415; iii. 99, 112; vi. 13, 237.
Austria, iii. 14, 104, 179.
—— Archduke of, i. 310, 311.
—— Emperor of, iii. 106, 107; ix. 277.
Austrian Catechism, The, xi. 343–4.
—— Troops, ix. 259.
Austrians, ix. 187 n.
Authors, On the Conversation of, vii. 24.
——, The Royal Society of, vii. 105.
Autolycus (in Shakespeare’s Winter’s Tale), i. 155, 326; viii. 230, 388.
Auvergne, Countess of, i. 292.
Avare (Molière). See L’Avare.
Avarice (in Spenser), v. 39.
Avon, v. 297.
Aylesbury, iii. 422.
Ayr, ii. 78.
Ayrton, William, vi. 195, 201; vii. 37.
Ayton, Miss Fanny, xi. 378.
B.

B——, xii. 455 n.


B., Arthur, ii. 211.
B——, Col., ii. 194, 196.
B., Dr, ii. 224.
B., Duke of, ii. 225.
B——ll, ii. 176.
B——r, ii. 215.
Babilonia, La (Salvator’s), x. 301.
Babylon, v. 183, 203, 273; vii. 185; ix. 268; xii. 153.
Baccano (a town), ix. 231.
Bacchus, v. 81; viii. 28, 231; ix. 216, 220.
—— and Ariadne (Titian’s), iv. 276; ix. 72.
Bacon, Lord, i. 23, 82, 123; iii. 293; iv. 45, 200 n., 283, 365; v. 3, 175,
179, 307, 326, 332, 333; vi. 85, 154; vii. 182 n., 262, 306, 320; viii.
58, 100; ix. 28, 186, 243 n.; x. 249, 258, 291, 326; xi. 25, 26, 27,
163, 164, 203, 287, 323; xii. 35 n., 50, 369, 372.
—— Friar, v. 334.
—— Roger, vii. 443 n.
Bacon’s Works, Character of Lord, compared as to Style with Sir
Thomas Brown and Jeremy Taylor, v. 326.
Bagdad, iii. 146.
Bagnigge Wells, iv. 108; vii. 70; viii. 140; xi. 252.
Bagot (Henry VI.), i. 295.
Bagshot, xi. 375; xii. 13.
Bailie Bradwardine (Scott’s Waverley), viii. 129; xi. 534.
—— Nicol Jarvie (Scott’s Rob Roy), iv. 248.
Baillie, Miss Joanna, v. 147, 148, 270; viii. 420 n.
Baird, Mr (a mate), ii. 248, 249, 252.
Baker, Mr (actor), viii. 318; x. 382.
—— Sir George, ii. 174, 175.
Bakewell, ii. 18.
Bakhuysen, Ludolf, ix. 20.
Balaam (in Holcroft’s The Exiles), ii. 201.
—— (in Kotzebue’s Indian in England), ii. 196.
Balafre (in Scott’s Quentin Durward), iv. 248.
Balasteros, Francisco, x. 250.
Bal Champêtre (Watteau’s), ix. 22, 23.
Balfour of Burley (Scott’s Old Mortality), iv. 229, 247; viii. 129; xi.
381, 532.
Ball, John, iii. 194, 303.
Ballad on a Wedding (Sir John Suckling’s), v. 371; viii. 56.
Ballads, On the Old English, v. 123.
Ballantyne Press, vii. 222.
Ballets, Two New, viii. 353.
Balmawhapple (in Scott’s Waverley), xii. 91.
Balmerino, Lord, iii. 285 n.; x. 161, 168.
Baltimore, viii. 473; xii. 377.
—— House, viii. 12.
Banbury, ii. 14.
—— Mutton, ii. 246.
Banchieri, Monsignore, iii. 178.
Bandello, Matteo, x. 9.
Bandinelli, Baccio (Correggio’s), ix. 43.
——, Bartolommeo, ix. 219, 229.
Bank of a River (Gainsborough’s), xi. 203.
Banks, Henry, xi. 473.
—— Sir Joseph, ii. 178, 183, 199, 203; vii. 210.
—— Mr, ix. 56 n.
—— Miss, ii. 206.
—— the Miller (in The Merry Devil), v. 294.
—— of the Thames (J. Wilson’s), xi. 247.
—— of the Wye (Wordsworth’s), v. 156.
Bannister, John, i. 155, 326; ii. 160, 162, 165, 195, 196, 197, 198, 202,
368; vi. 273, 417; vii. 76, 127; viii. 230, 234, 317, 387, 388, 514; xi.
366; xii. 24.
Bannister’s Farewell, viii. 229.
Banquo (in Shakespeare’s Macbeth), vi. 410; xi. 316.
Banstead Downs, vi. 12.
Baptistery, The, at Florence, ix. 212.
Barabbas, v. 210.
Barbara Yellowley (in Scott’s Pirate), xi. 534.
Barbarelli, Giorgio. See Giorgione.
Barbarosa (Brown’s), viii. 372.
Barbaroux, vi. 102.
Barbauld, Mrs (Anna Letitia), v. 147.
Barber, Mrs, xii. 139 n.
—— of Bagdad, The (in Arabian Nights), viii. 13.
Barberigo Palace, The, ix. 269, 270.
Barbieri, Giovanni Francesco. See Guercino.
Barcelona, ix. 185.
Barclay, Captain, viii. 203.
Bard (Gray’s), xi. 326 n.; xii. 223.
—— Bracy (in Coleridge’s Christabel), x. 415.
Bardolph (in Shakespeare), ii. 72; viii. 33; xii. 7.
Barebone’s Parliament, iii. 395.
Baretti, G. M. A., vi. 381.
—— Reynolds’ Portrait of, ix. 399.
Bareuth, the Margravine of, vi. 445.
Barker, Benjamin, xi. 248.
Barkley, Sir Robert, ii. 224.
—— Miss, ii. 224.
Barlow, Joel, iii. 460.
Barmecide, The, iii. 139; iv. 337; vi. 53; viii. 13.
Barnaby Brittle (a play founded on Molière), viii. 28.
Barnard, Mr (actor), viii. 241, 279, 280, 302, 399, 460, 475, 525, 532.
—— Sir John, iii. 413.
Barnard’s Inn, ii. 218.
Barnes, Mrs and Mr, viii. 271, 439.
Barney o’ Mulchesen (in Leigh’s Where to Find a Friend), viii. 258,
260.
Baron of Bradwardine (Scott’s Waverley), iv. 247.
—— Wildenheim (in Mrs Inchbald’s Lovers’ Vows), viii. 335.
Barrés, The, iii. 420; iv. 237; xii. 293.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like