Cover
About the Authors
Preface to the First Edition
Preface to the Second Edition
Brief Contents
Detailed Contents
1. Introduction to OOP
1.1 Introduction
1.2 Need of Object-Oriented Programming
1.2.1 Procedural Languages
1.2.2 Object-Oriented Modeling
1.2.2.1 Attributes
1.2.2.2 Behavior
1.3 Principles of Object-Oriented Languages
1.3.1 Classes
1.3.2 Objects
1.3.3 Abstraction
1.3.4 Inheritance
1.3.5 Encapsulation
1.3.6 Polymorphism
1.4 Procedural Language vs OOP
1.5 OOAD Using UML
1.6 Applications of OOP
Summary
Exercises
2. Getting Started with Java
2.1 Introduction
2.2 History of Java
2.3 Java's Journey: From Embedded Systems to Middle-Tier Applications
2.4 Java Essentials
2.5 Java Virtual Machine
2.6 Java Features
2.6.1 Platform Independence
2.6.2 Object Oriented
2.6.3 Both Compiled and Interpreted
2.6.3.1 Interpretation
2.6.3.2 Compilation
2.6.3.3 Java Approach
2.6.4 Java is Robust
2.6.5 Java Language Security Features
2.6.5.1 Java Security Model
2.6.5.2 Sandbox - Definition
2.6.6 Java is Multithreaded
2.6.7 Other Features
2.6.7.1 Automatic Memory Management
2.6.7.2 Dynamic Binding
2.6.7.3 Good Performance
2.6.7.4 Built-in Networking
2.6.7.5 No Pointers
2.6.7.6 No Global Variables
2.7 Program Structure
2.7.1 How to Execute a Java Program?
2.7.2 Why Save as Example.java?
2.7.3 Explanation
2.8 Java Improvements
2.8.1 Java 5.0 Features
2.8.1.1 Autoboxing and Unboxing
2.8.1.2 Enhanced for Loop
2.8.1.3 Enumerated Types
2.8.1.4 StringBuilder Class
2.8.1.5 Static Import
2.8.1.6 Metadata
2.8.1.7 Formatted I/O and VarArgs
2.8.1.8 Graphics System Improvements
2.8.1.9 New Concurrency Features
2.8.1.10 Generics
2.8.2 Java 6 Features
2.8.2.1 Collections API
2.8.2.2 Input/Output
2.8.2.3 Jar and Zip Enhancements
2.8.2.4 Enhancements Common to Java Web Start and Java Plug-in
2.8.2.5 Enhanced Network Interface
2.8.2.6 Splash Screen
2.8.3 Java 7 Features
2.8.3.1 String in switch...case Statement
2.8.3.2 Unicode 6.0.0 Support
2.8.3.3 Binary Literals and Numeric Literals with Underscores
2.8.3.4 Automatic Resource Management
2.8.3.5 Improved Exception Handling
2.8.3.6 nio 2.0 Non-Blocking I/O - New File System API
2.8.4 Brief Comparison of Different Releases
2.9 Differences between Java and C++
2.10 Installation of JDK 1.7
2.10.1 Getting Started with the JDK
2.10.2 JDK Installation Notes
2.10.2.1 Step 1: Run the JDK Installer
2.10.2.2 Installed Directory Structure
2.10.2.3 Step 2: Update Path and Classpath Variables
2.10.2.4 Setting the Classpath
2.10.2.5 Step 3: Testing the Installation
2.10.3 Exploring the JDK
2.10.3.1 Tools in JDK
2.10.3.2 Basic Tools
2.11 Integrated Development Environment
Summary
Exercises
3. Java Programming Constructs
3.1 Variables
3.2 Primitive Data Types
3.3 Identifier
3.3.1 Rules for Naming
3.3.2 Naming Convention
3.3.3 Keywords
3.4 Literals
3.5 Operators
3.5.1 Binary Operators
3.5.1.1 Assignment Operators
3.5.1.2 Arithmetic Operators
3.5.1.3 Relational Operators
3.5.1.4 Boolean Logical Operators
3.5.1.5 Bitwise Operators
3.5.2 Unary Operators
3.5.2.1 Increment and Decrement Operators
3.5.3 Ternary Operators
3.6 Expressions
3.7 Precedence Rules and Associativity
3.8 Primitive Type Conversion and Casting
3.9 Flow of Control
3.9.1 Conditional Statements
3.9.1.1 if...else
3.9.1.2 switch-case
3.9.2 Loops
3.9.2.1 for Loop
3.9.2.2 while Loop
3.9.2.3 do-while Loop
3.9.2.4 for-each Loop
3.9.3 Branching Mechanism
3.9.3.1 break Statement
3.9.3.2 continue Statement
Summary
Exercises
4. Classes and Objects
4.1 Classes
4.2 Objects
4.2.1 Difference between Objects and Classes
4.2.2 Why Should We Use Objects and Classes?
4.3 Class Declaration in Java
4.3.1 Class Body
4.3.1.1 Instance Variables
4.4 Creating Objects
4.4.1 Declaring an Object
4.4.2 Instantiating an Object
4.4.3 Initializing an Object
4.5 Methods
4.5.1 Why Use Methods?
4.5.2 Method Type
4.5.3 Method Declaration
4.5.4 Instance Method Invocation
4.5.5 Method Overloading
4.6 Constructors
4.6.1 Parameterized Constructors
4.6.2 Constructor Overloading
4.7 Cleaning Up Unused Objects
4.7.1 Garbage Collector
4.7.2 Finalization
4.7.3 Advantages and Disadvantages
4.8 Class Variables and Methods - static Keyword
4.8.1 Static Variables
4.8.2 Static Methods
4.8.3 Static Initialization Block
4.9 this Keyword
4.10 Arrays
4.10.1 One-Dimensional Arrays
4.10.1.1 Creation of Array
4.10.1.2 How to Use for Loops with Arrays?
4.10.2 Two-Dimensional Arrays
4.10.3 Using for-each with Arrays
4.10.4 Passing Arrays to Methods
4.10.5 Returning Arrays from Methods
4.10.6 Variable Arguments
4.11 Command-Line Arguments
4.12 Nested Classes
4.12.1 Inner Class
4.12.2 Static Nested Class
4.12.3 Why Do We Create Nested Classes?
4.13 Practical Problem: Complex Number Program
Summary
Exercises
5. Inheritance
5.1 Inheritance vs Aggregation
5.1.1 Types of Inheritance
5.1.2 Deriving Classes Using extends Keyword
5.2 Overriding Method
5.3 super Keyword
5.4 final Keyword
5.5 Abstract Class
5.6 Shadowing vs Overriding
5.7 Practical Problem: circle and cylinder Class
Summary
Exercises
6. Interfaces, Packages, and Enumeration
6.1 Interfaces
6.1.1 Variables in Interface
6.1.2 Extending Interfaces
6.1.3 Interface vs Abstract Class
6.2 Packages
6.2.1 Creating Packages
6.2.1.1 Saving, Compiling, and Executing Packages
6.2.1.2 Setting the Classpath
6.2.1.3 Subpackages
6.2.2 Using Packages
6.2.2.1 Static Import
6.2.3 Access Protection
6.3 java.lang Package
6.3.1 java.lang.Object Class
6.3.2 Java Wrapper Classes
6.3.2.1 Wrapper Classes: Constructors and Methods
6.3.2.2 Ordinary Methods
6.3.2.3 Parser Methods
6.3.2.4 Autoboxing and Unboxing of Wrappers
6.3.3 String Class
6.3.3.1 String Manipulation
6.3.3.2 String Methods
6.3.4 StringBuffer Class
6.3.5 StringBuilder Class
6.3.6 Splitting Strings
6.4 enum Type
6.4.1 Using Conditional Statements with an Enumerated Variable
6.4.2 Using for Loop for Accessing Values
6.4.3 Attributes and Methods within Enumeration
6.5 Practical Problem: Banking Example
Summary
Exercises
7. Exception, Assertions, and Logging
7.1 Introduction
7.1.1 Exception Types
7.2 Exception Handling Techniques
7.2.1 try...catch
7.2.2 throw Keyword
7.2.3 throws
7.2.4 finally Block
7.2.5 try-with-resources Statement
7.2.6 Multi catch
7.2.7 Improved Exception Handling in Java 7
7.3 User-Defined Exception
7.4 Exception Encapsulation and Enrichment
7.5 Assertions
7.6 Logging
Summary
Exercises
8. Multithreading in Java
8.1 Introduction
8.2 Multithreading in Java
8.3 java.lang.Thread
8.4 main Thread
8.5 Creation of New Threads
8.5.1 By Inheriting the Thread Class
8.5.2 Implementing the Runnable Interface
8.6 Thread.State in Java
8.7 Thread Priority
8.8 Multithreading - Using isAlive and join
8.9 Synchronization
8.9.1 Synchronized Methods
8.9.2 Synchronized Statements
8.10 Suspending and Resuming Threads
8.11 Communication between Threads
8.12 Practical Problem: Time Clock Example
Summary
Exercises
9. Input/Output, Serialization, and Cloning
9.1 Introduction
9.1.1 java.io.InputStream and java.io.OutputStream
9.2 java.io.File Class
9.3 Reading and Writing Data
9.3.1 Reading/Writing Files Using Byte Stream
9.3.2 Reading/Writing Console User Input
9.3.3 Reading/Writing Files Using Character Stream
9.3.4 Reading/Writing Using Buffered Byte Stream Classes
9.3.5 Reading/Writing Using Buffered Character Stream Classes
9.4 Randomly Accessing a File
9.5 Reading and Writing Files Using New I/O Package
9.6 Java 7 nio Enhancements
9.7 Serialization
9.8 Cloning
Summary
Exercises
Project Work
10. Generics, java.util, and other API
10.1 Introduction
10.2 Generics
10.2.1 Using Generics in Arguments and Return Types
10.2.2 Wildcards
10.2.3 Bounded Wildcards
10.2.4 Defining Your Own Generic Classes
10.3 Linked List
10.4 Set
10.4.1 HashSet Class
10.4.2 TreeSet Class
10.5 Maps
10.5.1 HashMap Class
10.5.2 TreeMap Class
10.6 Collections Class
10.7 Legacy Classes and Interfaces
10.7.1 Difference between Vector and ArrayList
10.7.2 Difference between Enumerations and Iterator
10.8 Utility Classes: Random Class
10.8.1 Observer and Observable
10.9 Runtime Class
10.10 Reflection API
Summary
Exercises
11. Network Programming
11.1 Introduction
11.1.1 TCP/IP Protocol Suite
11.2 Sockets
11.2.1 TCP Client and Server
11.2.1.1 How to Run the Client and Server?
11.2.2 UDP Client and Server
11.3 URL Class
11.4 Multithreaded Sockets
11.5 Network Interface
Summary
Exercises
12. Applets
12.1 Introduction
12.2 Applets
12.3 Applet Structure
12.4 An Example Applet Program
12.4.1 How to Run an Applet?
12.5 Applet Life Cycle
12.6 Common Methods Used in Displaying the Output
12.7 paint, update, and repaint
12.7.1 paint Method
12.7.2 update Method
12.7.3 repaint Method
12.8 More about APPLET Tag
12.9 getDocumentBase and getCodeBase Methods
12.10 AppletContext Interface
12.10.1 Communication between Two Applets
12.11 How to Use an Audio Clip?
12.12 Images in Applet
12.12.1 MediaTracker Class
12.13 Graphics Class
12.13.1 An Example Applet Using Graphics Class
12.14 Color Class
12.15 Font Class
12.16 FontMetrics Class
12.17 Practical Problem: Digital Clock
Summary
Exercises
13. Event Handling in Java
13.1 Introduction
13.2 Event Delegation Model
13.3 java.awt.event Package
13.3.1 Event Classes
13.3.1.1 ActionEvent Class
13.3.1.2 AdjustmentEvent Class
13.3.1.3 KeyEvent Class
13.3.1.4 MouseEvent Class
13.3.1.5 FocusEvent Class
13.3.1.6 ItemEvent Class
13.3.1.7 TextEvent Class
13.4 Sources of Events
13.5 Event Listeners
13.6 How Does the Model Work?
13.7 Adapter Classes
13.7.1 How to Use Adapter Classes?
13.7.2 Adapter Classes in Java
13.8 Inner Classes in Event Handling
13.9 Practical Problem: Cartoon Applet
13.9.1 Smiling Cartoon with Blinking Eyes Part 1
13.9.2 Smiling Cartoon with Blinking Eyes Part 2
13.9.3 Smiling Cartoon Part 3
Summary
Exercises
14. Abstract Window Toolkit
14.1 Introduction
14.1.1 Why AWT?
14.1.2 java.awt Package
14.2 Components and Containers
14.2.1 Component Class
14.2.2 Components as Event Generator
14.3 Button
14.4 Label
14.5 Checkbox
14.6 Radio Buttons
14.7 List Boxes
14.8 Choice Boxes
14.9 TextField and TextArea
14.10 Container Class
14.10.1 Panels
14.10.1.1 How to Use Panels?
14.10.2 Window
14.10.3 Frame
14.11 Layouts
14.11.1 FlowLayout
14.11.2 BorderLayout
14.11.3 CardLayout
14.11.4 GridLayout
14.11.5 GridBagLayout
14.11.5.1 gridx and gridy
14.11.5.2 gridwidth and gridheight
14.11.5.3 fill
14.11.5.4 ipadx and ipady
14.11.5.5 insets
14.11.5.6 anchor
14.11.5.7 weightx and weighty
14.12 Menu
14.13 Scrollbar
14.14 Practical Problem: City Map Applet
Summary
Exercises
15. Swing
15.1 Introduction
15.1.1 Features of Swing
15.1.2 Differences between Swing and AWT
15.2 JFrame
15.3 JApplet
15.4 JPanel
15.5 Components in Swings
15.6 Layout Managers
15.6.1 SpringLayout
15.6.2 BoxLayout
15.7 JList and JScrollPane
15.8 Split Pane
15.9 JTabbedPane
15.10 JTree
15.11 JTable
15.12 Dialog Box
15.13 JFileChooser
15.14 JColorChooser
15.15 Pluggable Look and Feel
15.16 Inner Frames
15.17 Practical Problem: Mini Editor
Summary
Exercises
16. Introduction to Advanced Java
16.1 Introduction to J2EE
16.2 Database Handling Using JDBC
16.2.1 Load the Driver
16.2.1.1 Type 1: JDBC ODBC Bridge Driver
16.2.1.2 Type 2: Native-API/Partly Java Driver
16.2.1.3 Type 3: Net-Protocol Driver
16.2.1.4 Type 4: Pure Java Driver
16.2.2 Establish Connection
16.2.3 Create Statements
16.2.4 Execute Query
16.2.5 Iterate ResultSet
16.2.6 Scrollable ResultSet
16.2.7 Transactions
16.3 Servlets
16.3.1 Lifecycle of Servlets
16.3.2 First Servlet
16.3.2.1 How to Run the Servlet?
16.3.3 Reading Client Data
16.3.4 HTTP Redirects
16.3.5 Cookies
16.3.6 Session Management
16.3.6.1 Hidden Fields
16.3.6.2 URL Rewriting
16.3.6.3 Cookies
16.3.6.4 Session API
16.4 Practical Problem: Login Application
16.5 Introduction to Java Server Pages
16.5.1 JSP Life Cycle
16.5.2 Steps in JSP Page Execution
16.5.3 JSP Elements
16.5.3.1 Directives
16.5.3.2 Expressions
16.5.3.3 Scriptlets
16.5.3.4 Declarations
16.5.3.5 Actions
16.5.4 Placing Your JSP in the Webserver
16.6 Java Beans
16.6.1 Properties of a Bean
16.6.1.1 Basic Properties
16.6.1.2 Indexed Properties
16.6.1.3 Bound Properties
16.6.1.4 Constrained Properties
16.6.2 Using Beans through JSP
16.6.2.1 Accessing Bean Properties in JSP
16.6.2.2 Setting Bean Properties through JSP
16.6.3 CalculateBean Example
16.6.3.1 Directory Structure for the Example
16.7 JAR Files
16.7.1 Creating a JAR File
16.7.2 Viewing the Contents of a JAR File
16.7.3 Extracting the Contents of JAR
16.7.4 Manifest Files
16.7.4.1 Modifying a Manifest File
16.7.4.2 Application Bundled in JAR
16.8 Remote Method Invocation
16.8.1 RMI Networking Model
16.8.1.1 Stub and Skeleton
16.8.2 Creating an RMI Application
16.8.2.1 Server Class
16.8.2.2 Executing RMI Server and Client
16.9 Introduction to EJB
16.9.1 Types of EJB
16.9.1.1 Entity Bean
16.9.1.2 Session Beans
16.9.1.3 Message-Driven Beans
16.9.2 EJB Architecture
16.10 Hello World - EJB Example
Summary
Exercises
Features of the Book
Appendices
Appendix A: Lab Manual - Java Lab Exercises
A.1 Introduction, Compiling, and Executing a Java Program
A.2 Program with Data Types and Variables
A.3 Program with Decision Control Structures: if, nested-if, etc.
A.4 Program with Loop Control Structures: do, while, for, etc.
A.5 Program on Usage of switch-case and if Conditional Statements
A.6 Program with Classes and Objects
A.7 Copy Constructor and Constructor Overloading
A.8 A Program on Function Overloading
A.9 Implementing Inheritance
A.9.1 Single Inheritance
A.9.2 Multiple Inheritance
A.9.3 Multilevel Inheritance
A.9.4 Use of Abstract Classes
A.10 Implementing Interfaces
A.10.1 Developing User-Defined Interfaces and Implementation
A.10.2 Use of Predefined Interfaces
A.11 Handling Strings
A.12 Implementing Packages
A.13 Implementing Wrapper Classes
A.14 Exception Handling Mechanism in Java
A.14.1 Handling Predefined Exceptions
A.14.2 Handling User-Defined Exceptions
A.15 Concept of Threading
A.15.1 Creation of Thread in Java Applications
A.15.2 Multithreading
A.16 Working with Files
A.17 Implementing Generics
Appendix B: Interview Questions
Index
#
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X