Comprehensive Problem Solver
a ia &
( rina
Dalat as econ ey
Stoica a Cancer(Original English Language Edition GCopyrightby Paraglyph Press, USA.
‘This book may not be duplicated in any way without the express writen consent of the
‘publisher, except inthe form of brief excerpts or quotations for the purpose of review. The
information contained herein is forthe personal use ofthe reader and may not be incorporated
in any commercial programs, other books, databases, orany kind of software without written
consent of the publisher. Making copies of this book or any portion thereof for any purpose
‘otherthan your ownisa violation of copyright laws.
‘This edition has been published by arrangement with the Paraglyph Press, Inc. 2246 E.
Myrtle Avenue, Phoenix Arizona 85202, USA and published in India by Dreamtech Press,
9A, Ansari Road, Daryagan), New Delhi-110002.
Limits of Liabitity/diselaimer of Warranty : The author and publisher have used their best
«efforts in preparing this book. Paraglyph Press, USA and the author makes no representation.
(or Warranties with respect to the accuracy or completeness of the contents of this book, and’
specifically disclaim any implied warranties of merchantability or fitness for any particular
‘purpo se. There are no Warranties which extend beyond the descriptions contained in this
paragraph. No warranty may be created or extended by sales representatives ar written sales
materials. The accuracy and completeness of the information provided herein and the
‘opinions stated herein are not guaranteed or warranted to produce any particular results, and
the advice and strategies contained herein may not be suitable for every individual. Neither
Paragtyph Press, USA, nor author shall be liable forany loss profit or any other commercial
damages, including but not limited t special, incidental, consequential or other damages.
‘Trademarks : All brand names and product names used in this book are trademarks,
registered trademarks, or trade names of their respective holders, Paraglyph Press is not
‘associated with any productor vendor mentionedin this book.
: 2008
Manufactured By: Brijbasi Act Press L1d., Okhta, Phaseelt, New DelhiContents at a Glance
idling.
adio Buttons, and LayOUuts......:cucssieeue
and Scroll Panes: ws ja B45,CHAPTER 15
‘Swing: Applets, Applications, and Pluggable Look and Feel ....
CHAPTER 16
‘Swing: Text Fields, Buttons, Toggle Buttons, Checkboxes, and Radio Buttons...
CHAPTER 417
‘Swing: Viewports, Scrolling, Sliders, Lists, Tables, and Trees...
CHAPTER 48
Swing: Combo Boxes, Progress Bars, Tooltips, Separators, and Choosers.
Swing: Menus and Toolba
CHAPTER 21
‘Swing: Windows, Desktop Panes, Inner Frames, and Dialog Boxes ..
CHAPTER 22
Images and Animation
CHAPTER 23
i ound
Java and XML: Using the Document Object Mode!
CHAPTER 25
Java and XML: Using the Simple API for XML.
CHAPTER 28
Collection 1147
CHAPTER 27
Creating Packages, Interfaces, JAR Files, and Annotations
CHAPTER 28
Working with Java Beans......
CHAPTER 29
Talking to Database...
CHAPTER.30
JDBC in Action..
CHAPTER 31
Understanding RMI.
CHAPTER 32
Understanding Serviet Programming...
APPENDIX: A
Generic Types...
APPENDIX: B
Java Keywords..
wtTable of Contents
Java Appears.
All about Bytecodes ..
Java Security
Java Programs
Is it Java 2 (JDK 5 or JDK 1.5)?
Immediate Solutions
‘Getting and Installing Java.. cere eet)
What about GLASSPATH? te
‘What was new in Java 2, version 1.4 2.10
Novel Pipeline Architecture 10
Providing Hardware Acceleration for Offscreen Images... u
‘Supplying Pluggable Image /O Framework. wa
™ Print S
Assistance for float and double Image Types. uv
Public Bidi Algorithm. ui
Aiding Font Rasterizer for TrueType Hinting ierrasraeieg
(Oman ia
Help from OpenType Font Table 12
Numeric Shaping Support 12
Enhanced Gomplex-Layout Support in GlyphVector: 12
Absolute Porter-Duff Support. 12Table of Contents
Methods for Checking if Font has a Transform...
Improved Equality Methods for FontRenderContext ..
What has been deprecated in Java 2, version 1.42.
What's new in Java 2, version 5.
Caching Entire Bufferedimages . 7
Methods Related to Hardware Acceleration of Ima
Hardware-Accelerated Rendering Using OpenGL
Solaris OpenGL Notes ....
Notes on Linux OpenGL...
Microsoft Windows OpenGL-based Pipeli
‘Support for CUPS Printers— Solaris and Linux
Bicubic Interpolation Assistance... . .
Generate Fonts from Files and Str@QMS wuts
Better Text Rendering Performance and Reliability
Rendering.
Muttingual Text
What has been Deprecated in Java 2, version 1.57
What is sSP*
What is J2EE*
‘What are Application Servers (Tomcat, Jrun, WebSphere, WebLogic, etc.)?
What is JSF?
What is J2ME?.
What is Sts?
Subfolders created by JDK... sss
Writing Code: Creating Code Files...
Writing Code: Knowing Java's Reserved Words.
Writing Code: Creating an Application.
public class app
‘[Link] printin(“Hello from Java!”
Compiling Code.
Compiling Code: Using Command-Line Options
Cross-Compilation Options.
Compiling Code: Checking for Deprecated Methods.
Rumning Code..
Running Code: Using Command-Line Options
Basic Skills: Commenting Your Code ...... 3
Basic Skils: Import Java Packages and Classes, ss 35,
Basie Skills: Finding Java Classes with CLASSPATI
Creating Applets
Running Windowed Applications...Table of Contents
61
axenersenensB
63
Declaring Character Variables...
Declaring Boolean Variables.
Initializing Variables.
Dynamic initialisation.
Converting between Data Types.
Casting to New Data Types
Declaring One-Dimensional Arrays..
Greating One-Dimensional Arrays
Initializing One-Dimensional Arrays.
Dectaring Multi-dimensional Arrays
Greating Multi-dimensional Arrays.
initialising Mult-dimensional Arrays.
Creating Irregular Multi-dimensional Arrays.Table of Contents
Getting Characters and Substrings.
Searching for and Replacing Strin
Changing Case in Strings
Formatting Numbers in Strings
The StringBuffer Class.
Greating String Buffers...
Getting and Setting String Buffer Lengths and Capacitie
Setting Characters in String Buffers...
‘Appending and inserting Using String Buffers...
Deleting Text in String Buffers.
Replacing Text in String Buffers ..
Wrapper class...
Autoboxing and Unboxing of Primitive Types.
Varargs Fundamental:
‘Overloading Varargs Methods..
‘Ambiguity in Varargs ...
CHAPTER 3
Operators, Conditionals, and Loops...
In Depth
Operators. -
Conditional 408
LOOPS oes 409
Immediate Solutions
Operator Precedence...
Incrementing and Decrementing: ++ and
Unary Not: ~ And t
Multiplication and Division; * and /.
Shift Operators: >>, >>>, and <<
Relational Operators: >, >=, <, <=, ==, and
Bitwise and Bitwise Logical And, Xor, and Or: &. *, and.
Logical 6 and |}
The if-then-else Operator: ?:
Assignment Operators: = and foperator]é..
Using the Math Clas
Changes in the Math Class ....
Class StrictMath,
Comparing Strings...
The if Statement.
The else Statement ....cscsscsnssssnsnssnsssonssinusssnsssinsuauissassssssssnusiaisstusssssasssansssususssasssassssonnsasssuassssess 12
(Nested if Statements 2D
villTable of Contents
The if-else Ladders 129
The switch Statement ao
The while Loop..
The do-while Loop. 134
The for Loop..
The for-each Loop
‘Supporting for-each in Your Own Ciass.
‘A (Poor) Solution... sl
Significance of for-each
Nested Loops.
Using the break Statement.
Using the continue Statement .
Debugging .
immediate Solutions ~
Declaring and Creating Objects.
Declaring and Defining Classes.
Creating Instance Variables.
Setting Variable Access.
Creating Glass Variables
Creating Methods...
Setting Method Access.
Passing Parameters to Methods
‘Command-Line Arguments Passed to main.
Retuming Values from Methods
Creating Class Methods...
Creating Data Access Methods ..
Creating Constructors...
Passing Parameters to Constructors.
‘A Full Class Example.
Understanding Variable Scope.
Using Recursion
Garbage Collection and Memory Management
‘Avoiding Circular References eu.
Garbage Collection and the finalize MethodTable of Contents
Overloading Methods...
Overloading Constructors.
Passing Objects to Methods
Passing Arrays to Methods
Using the this Keyword
Returning Objects from Methods.
Returning Arrays from Method:
New Classes Added to Java Lang.
Nesting try Statements
Using Finally Clause
‘Throwing Exceptions..
Creating a Custom Exception ..
Debugging Java Program:
(CHAPTER 5
Inheritance, Inner Classes, and Interfaces
dn th
Why Inheritance?
Why Interfaces?
Why Inner Classes’
dmmediate Solutions
Creating a Subclass...
Access Specifiers and inheritance.
Calling Superciass Constructors.
Creating Multilevel Inheritance.
Handling Multilevel Constructors
Dynamic Method Dispatch (Runtime Polymorphism)
Creating Abstract Classes ...
‘Stopping Overriding with final
‘Stopping Inheritance with final
Creating Constants with final .
Is-a vs. Has-a Relationshi
‘The Java Object Ciass.
Using Interfaces for Multiple Inheritance.
New interfaces added to Java Lang
The Readable (ntertA0e AT
The Appendable Interface a
The Hterable (nttiTable of Contents
(Creating Iterable Objects ... 247
‘Creating Inner Classes .. 250
‘Creating Anonymous Inner Classes 251
CHAPTER 6
AWT: Applets, Applications, and Event Handling. 253
in Depth :
‘The Abstract Windowing Toolkit 255
Applets.. 256
Applications 257
Handling Events. 258
Immadiate Solutions
Using the Abstract Windowing Toolkit. w 259
‘Creating Applets.
Using the