image

Contents

Foreword

Acknowledgments

Introduction

1   Introduction to Java

Why Java?

So What Is Java?

Java Virtual Machine

Features of Java

Small

Simple

Object Oriented

Compiled and Interpreted

Platform Independent

Robust and Secure

Multithreaded

Dynamic

Java’s Evolution

JDK 1.0 (January 23, 1996): Codename Oak

JDK 1.1 (February 19, 1997)

J2SE 1.2 (December 8, 1998): Codename Playground

J2SE 1.3 (May 8, 2000): Codename Kestrel

J2SE 1.4 (Feb 6, 2002): Codename Merlin

J2SE 5.0 (Sept 30, 2004): Codename Tiger

Java SE 6 (Dec 11, 2006): Codename Mustang

Java SE 7 (July 7, 2011): Codename Dolphin

Summary

2   Arrays

Arrays

Declaring Arrays

Creating Arrays

Accessing and Modifying Array Elements

Initializing Arrays

Initializing at Runtime

Initializing Using Array Literals

The for-each Loop

Multidimensional Arrays

Two-dimensional Arrays

Initializing Two-dimensional Arrays

Looping Using the for-each Construct

N-dimensional Arrays

Nonrectangular Arrays

Runtime Initialization

Initialization Using Array Literals

A Few Goodies

Determining the Array Length

Cloning an Array

Finding Out the Class of an Array

Summary

3   Classes

Object-Oriented Programming (OOP) Concepts

OOP Features

OOP Benefits

The Class

Defining a Class

Declaring a Point Class

Using Classes

Accessing/Modifying Fields

The Class Example Program

Declaring Methods

Memory Representation of Objects

Information Hiding

Encapsulation

Declaring Constructors

Default Constructor

Rules for Defining a Constructor

Source File Layout

The package Statement

The import Statement

Directory Layout and Packages

Summary

4   Inheritance

Why Inheritance?

What Is Inheritance?

Defining Single-level Inheritance

Capturing Multilevel Inheritance

Writing a Multilevel Inheritance Program

Polymorphism

Creating a Heterogeneous Collection of Objects

A Program That Demonstrates a Heterogeneous Collection

Detecting the Object Type

Typecasting Rules on Inheritance Hierarchies

Preventing Method Overriding

Preventing Subclassing

Summary

5   Object Creation and Member Visibility

Instantiating a Subclass

The Object-Creation Process

Calling the super Constructor

Method Overloading

Rules of Method Overloading

Creating a Copy Constructor

Invoking Constructors: Summary

The final Keyword

The final Classes

The final Methods

The final Variables

The final Variables of the Class Type

Important Points Related to the final Keyword

Understanding Member Visibility Rules

The public Modifier

The private Modifier

The protected Modifier

The Default Modifier

A Few Rules on Inheriting

Summary

6   Static Modifier and Interfaces

The static Keyword

The Static Fields

The Static Methods

The Static Initializers

Interfaces

A Real-life Example of an Interface

Understanding Interface Syntax

Understanding Interfaces Through an Example

Extending Interfaces

Implementing Multiple Interfaces

Combining Interfaces

A Few Important Points on Interfaces

Abstract Classes

Summary

7   Nested Classes

Nested Classes

Why Use Nested Classes?

Classifications of Nested Classes

Demonstrating the Use of Inner Classes

Accessing an Inner Class from the Outside

Accessing Shadowed Variables

Important Points to Note

Member Classes

Local Classes

Defining an Inner Class within Method Scope

A Few Important Points on Local Classes

Anonymous Classes

Creating Anonymous Classes

Restrictions on the Use of Anonymous Classes

Compiled Anonymous Classes

Guidelines on Using Anonymous Classes

Summary

8   Exception Handling

What Is an Exception?

Error Types

The Non-fatal Errors

The try-catch Statements

Classifying Exceptions

Combining Exception Handlers

How Runtime Matches catch Blocks

The finally Statement

Guidelines on the Use of the finally Block

Rules for Using the try/catch/finally Block

The try-with-resources Statement

Checked/Unchecked Exceptions

The throws Construct

Throwing Multiple Exceptions

User-defined Exceptions

The throw Statement

Re-throwing Exceptions

Difference Between the throw and throws Keywords

The final Re-throw in Java SE 7

Declaring Exceptions in Overridden Methods

Printing a Stack Trace

Asynchronous Exceptions

Guidelines for Using Exceptions

Summary

9   Java I/O

Input/Output Streams

The I/O Class Hierarchy

The Byte Streams

Determining File Length

The InputStream Methods

The OutputStream Class

File Copy Utility

The OutputStream Methods

Character Streams

File Viewer Utility

Buffered Readers/Writers

Binary Versus Character Streams

Chaining Streams

The Line Count Program

File Concatenation

Accessing the Host File System

The Directory Listing Program

Filtering the Directory Listing

Reading/Writing Objects

Summary

10   Advanced I/O

The Byte-Oriented Stream Classes

The PushbackInputStream Class

The SequenceInputStream Class

The PrintStream Class

The Character-Oriented Stream Classes

The CharArray Reader/Writer Classes

The Console Class

The StreamTokenizer Class

The Object-Oriented Streams

The Externalizable Interface

Nested Objects Serialization

Versioning Objects

Summary

11 Enums, Autoboxing, and Annotations

Typesafe Enumerations

Creating Integer Patterns for Enumerations

The enum Type

Serializing enum Types

Autoboxing

Wrapper Classes

A Few Additions in J2SE 5.0

Autoboxing/Unboxing

Annotations

Built-in Annotations

Declaring Annotations

Annotating an Annotation

Summary

12 Generics

Generics

What Are Generics?

Why Do We Need Generics?

A Sample Generics Program

Type Safety

Creating a Parameterized Stack Type

Declaration Syntax

A Generic Stack Class

Examining Intermediate Code

Testing the Stack Class

Bounded Types

Using Wildcards

Bounded Wildcards

Raw Types

More on Generic Types

Class with Two Generic Parameters

Casting Types

Comparing and Assigning Generic Types

Generic Methods

Declaring Generic Interfaces

Restrictions in Generics

Creating Arrays

Instantiating Type Parameters

Use of the static Keyword

Summary

13 Event Processing and GUI Building

Event Processing Model

Delegation Event Model

The Event Source

The Event Listener

Event Processing Sequence

Registering on Multiple Event Sources

Multiple Event Types

Building a GUI

Creating the User Interface

Demonstrating the Button Control

Demonstrating the Edit Control

Demonstrating the List Box Control

Summary

14 Creating Layouts

Layout Managers

Types of Layout Managers

Building the GUI

How Do Layout Managers Work?

Using Layout Managers

BorderLayout

Using NetBeans to Build the GUI

FlowLayout

CardLayout

GridLayout

GridBagLayout

BoxLayout

Tabbed Dialog Box

Advanced Layout Managers

Summary

15 Graphics and User Gestures Processing

What Is an Applet?

Creating Your First Applet

Running the Applet

Using AppletViewer

Understanding Applet Life-cycle Methods

Processing Mouse Events

Creating Popup Menus

Customizing the Drawing Color

Processing Keyboard Events

Summary

16 Collections

What Is the Java Collections Framework?

Benefits of the Collections Framework

What the Collections Framework Offers

The Collections Framework Interfaces

The Collections Framework Classes

List

Optional Operations of the List Interface

Set

Queue

Map

Algorithms

Summary

17 Threads

Processes and Threads

Thread States

JVM Threading Implementations

Daemon Versus Non-Daemon Threads

Creating Threads

Creating Your First Threaded Application

Creating Non-Daemon Threads

Thread Class Constructors

Static Methods of Thread

Some Essential Operations on Thread

Thread Synchronization

Bucket Transfers

Producer/Consumer Problem

Object Locks

When to Synchronize

The Deadlock

Solutions to Deadlock

Summary

18 Blocking Queues and Synchronizers

Blocking Queues

Characteristics of Blocking Queues

The BlockingQueue Interface

Implementations of the BlockingQueue Interface

Stock-trading System

The LinkedTransferQueue Example

Synchronizers

Semaphores

Barriers

Countdown Latches

Phaser

Exchangers

Summary

19 Callables, Futures, Executors, and Fork/Join

Callables and Futures

The Callable Interface

The Future Interface

How Callable and Future Work

Using Callables in Parallelizing Large Tasks

The FutureTask Class

Creating Cancellable Tasks

Executors

Creating a Thread Pool for Scheduled Executions

The ScheduledExecutorService Class

Demonstrating Scheduled Task Execution

Obtaining the Results of the First Completed Execution

Demonstrating the ExecutorCompletionService Class

Fork/Join Framework

The ForkJoinPool Class

The ForkJoinTask Class

Sorting an Enormous Array of Floats

Thread-safe Collections

The ThreadLocalRandom Class

Summary

20 Network Programming

Networking

Simple Home Page Reader

The URL Class

The URLConnection Class

Webpage Reader

The HttpCookie Class

Spying for Cookies

Echo Server Application

Testing the Echo Server Application

Serving Multiple Clients

Serving Simultaneous Clients

Running the EchoMultiServer Application

Testing the EchoMultiServer Application

Writing a File Storage Server Application

A Cloud Storage Server

A Cloud Store Client

Testing the File Upload/Download Utility

The InetAddress Class

Broadcasting Messages

Writing a Stock Quotes Server

Writing the Stock Trader Client

Running the Server and Client

Support for SCTP

Summary

21 Utility Classes

The String Class

A Few Important Methods

Practical Demonstration of String Methods

Comparing Strings

Creating Formatted Output

The Calendar Class

The GregorianCalendar Methods

The Local Time Converter Application

Introspection and Reflection

The Class Class

The Method Class

The Class Browser Application

The Introspection Test Application

The Class Browser

Disadvantages

What’s Next?

Summary

Index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.63.87