Home Page Icon
Home Page
Table of Contents for
3. Java Programming
Close
3. Java Programming
by Laura Lemay, Rogers Cadenhead
Sams Teach Yourself Java™ 6 in 21 Days
Copyright
Dedication
About the Authors
Acknowledgments
We Want to Hear from You!
Reader Services
Introduction
How This Book Is Organized
Who Should Read This Book
Conventions Used in This Book
1. The Java Language
1. Getting Started with Java
The Java Language
History of the Language
Introduction to Java
Selecting a Development Tool
Object-Oriented Programming
Objects and Classes
Attributes and Behavior
Attributes of a Class of Objects
Behavior of a Class of Objects
Creating a Class
Running the Program
Organizing Classes and Class Behavior
Inheritance
Creating a Class Hierarchy
Inheritance in Action
Single and Multiple Inheritance
Interfaces
Packages
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
2. The ABCs of Programming
Statements and Expressions
Variables and Data Types
Creating Variables
Naming Variables
Variable Types
Data Types
Class Types
Assigning Values to Variables
Constants
Comments
Literals
Number Literals
Boolean Literals
Character Literals
String Literals
Expressions and Operators
Arithmetic
More About Assignment
Incrementing and Decrementing
Comparisons
Logical Operators
Operator Precedence
String Arithmetic
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
3. Working with Objects
Creating New Objects
Using new
What new Does
A Note on Memory Management
Accessing and Setting Class and Instance Variables
Getting Values
Changing Values
Class Variables
Calling Methods
Nesting Method Calls
Class Methods
References to Objects
Casting and Converting Objects and Primitive Types
Casting Primitive Types
Casting Objects
Converting Primitive Types to Objects and Vice Versa
Comparing Object Values and Classes
Comparing Objects
Determining the Class of an Object
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
4. Lists, Logic, and Loops
Arrays
Declaring Array Variables
Creating Array Objects
Accessing Array Elements
Changing Array Elements
Multidimensional Arrays
Block Statements
if Conditionals
switch Conditionals
for Loops
while and do Loops
while Loops
do-while Loops
Breaking Out of Loops
Labeled Loops
The Conditional Operator
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
5. Creating Classes and Methods
Defining Classes
Creating Instance and Class Variables
Defining Instance Variables
Class Variables
Creating Methods
Defining Methods
The this Keyword
Variable Scope and Method Definitions
Passing Arguments to Methods
Class Methods
Creating Java Applications
Helper Classes
Java Applications and Command-line Arguments
Passing Arguments to Java Applications
Handling Arguments in Your Java Application
Creating Methods with the Same Name, Different Arguments
Constructor Methods
Basic Constructor Methods
Calling Another Constructor Method
Overloading Constructor Methods
Overriding Methods
Creating Methods That Override Existing Methods
Calling the Original Method
Overriding Constructors
Finalizer Methods
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
6. Packages, Interfaces, and Other Class Features
Modifiers
Access Control for Methods and Variables
Default Access
Private Access
Public Access
Protected Access
Comparing Levels of Access Control
Access Control and Inheritance
Accessor Methods
Static Variables and Methods
Final Classes, Methods, and Variables
Variables
Methods
Classes
Abstract Classes and Methods
Packages
Using Packages
Full Package and Class Names
The import Declaration
Class Name Conflicts
A Note About Classpath and Where Classes Are Located
Creating Your Own Packages
Picking a Package Name
Creating the Folder Structure
Adding a Class to a Package
Packages and Class Access Control
Interfaces
The Problem of Single Inheritance
Interfaces and Classes
Implementing and Using Interfaces
Implementing Multiple Interfaces
Other Uses of Interfaces
Creating and Extending Interfaces
New Interfaces
Methods Inside Interfaces
Extending Interfaces
Creating an Online Storefront
Inner Classes
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
7. Exceptions, Assertions, and Threads
Exceptions
Exception Classes
Managing Exceptions
Exception Consistency Checking
Protecting Code and Catching Exceptions
The finally Clause
Declaring Methods That Might Throw Exceptions
The throws Clause
Which Exceptions Should You Throw?
Passing On Exceptions
throws and Inheritance
Creating and Throwing Your Own Exceptions
Throwing Exceptions
Creating Your Own Exceptions
Combining throws, try, and throw
When and When Not to Use Exceptions
When to Use Exceptions
When Not to Use Exceptions
Bad Style Using Exceptions
Assertions
Threads
Writing a Threaded Program
A Threaded Application
Stopping a Thread
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
2. The Java Class Library
8. Data Structures
Moving Beyond Arrays
Java Structures
Iterator
Bit Sets
Vectors
Looping Through Data Structures
Stacks
Map
Hash Tables
Generics
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
9. Working with Swing
Creating an Application
Creating an Interface
Developing a Framework
Displaying a Splash Page
Creating a Component
Adding Components to a Container
Working with Components
Image Icons
Labels
Text Fields
Text Areas
Scrolling Panes
Check Boxes and Radio Buttons
Combo Boxes
Lists
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
10. Building a Swing Interface
Swing Features
Setting the Look and Feel
Standard Dialog Boxes
Confirm Dialog Boxes
Input Dialog Boxes
Message Dialog Boxes
Option Dialog Boxes
Using Dialog Boxes
Sliders
Scroll Panes
Toolbars
Progress Bars
Menus
Tabbed Panes
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
11. Arranging Components on a User Interface
Basic Interface Layout
Laying Out an Interface
Flow Layout
Box Layout
Grid Layout
Border Layout
Mixing Layout Managers
Card Layout
Using Card Layout in an Application
Grid Bag Layout
Designing the Grid
Creating the Grid
Cell Padding and Insets
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
12. Responding to User Input
Event Listeners
Setting Up Components
Event-Handling Methods
Working with Methods
Action Events
Focus Events
Item Events
Key Events
Mouse Events
Mouse Motion Events
Window Events
Using Adapter Classes
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
13. Using Color, Fonts, and Graphics
The Graphics2D Class
The Graphics Coordinate System
Drawing Text
Improving Fonts and Graphics with Antialiasing
Finding Information About a Font
Color
Using Color Objects
Testing and Setting the Current Colors
Drawing Lines and Polygons
User and Device Coordinate Spaces
Specifying the Rendering Attributes
Fill Patterns
Setting a Drawing Stroke
Creating Objects to Draw
Lines
Rectangles
Ellipses
Arcs
Polygons
Drawing Objects
Drawing a Map
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
14. Developing Swing Applications
Java Web Start
Using Java Web Start
Creating a JNLP File
Supporting Web Start on a Server
Additional JNLP Elements
Security
Descriptions
Icons
Improving Performance with SwingWorker
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
3. Java Programming
15. Working with Input and Output
Introduction to Streams
Using a Stream
Filtering a Stream
Handling Exceptions
Byte Streams
File Streams
File Input Streams
File Output Streams
Filtering a Stream
Byte Filters
Buffered Streams
Console Input Streams
Data Streams
Character Streams
Reading Text Files
Writing Text Files
Files and Filename Filters
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
16. Serializing and Examining Objects
Object Serialization
Object Output Streams
Object Input Streams
Transient Variables
Checking an Object’s Serialized Fields
Inspecting Classes and Methods with Reflection
Inspecting and Creating Classes
Working with Each Part of a Class
Inspecting a Class
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
17. Communicating Across the Internet
Networking in Java
Opening a Stream over the Net
Sockets
Socket Servers
Designing a Server Application
Testing the Server
The java.nio Package
Buffers
Byte Buffers
Character Sets
Channels
Network Channels
Nonblocking Socket Clients and Servers
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
18. Accessing Databases with JDBC
Java Database Connectivity
Database Drivers
The JDBC-ODBC Bridge
Connecting to an ODBC Data Source
Retrieving Data from a Database Using SQL
Writing Data to a Database Using SQL
Moving Through Resultsets
JDBC Drivers
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
19. Reading and Writing RSS Feeds
Using XML
Designing an XML Dialect
Processing XML with Java
Processing XML with XOM
Creating an XML Document
Modifying an XML Document
Formatting an XML Document
Evaluating XOM
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
20. XML Web Services
Introduction to XML-RPC
Communicating with XML-RPC
Sending a Request
Responding to a Request
Choosing an XML-RPC Implementation
Using an XML-RPC Web Service
Creating an XML-RPC Web Service
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
21. Writing Java Servlets and Java Server Pages
Using Servlets
Developing Servlets
Using Cookies
Using Sessions
JSP
Writing a JSP Page
Using Expressions
Using Scriptlets
Using Declarations
Creating a Web Application
JSP Standard Tag Library
Summary
Q&A
Quiz
Questions
Answers
Certification Practice
Exercises
Appendixes
A. Using the Java Development Kit
Choosing a Java Development Tool
Installing the Java Development Kit
Windows Installation
Configuring the Java Development Kit
Using a Command-line Interface
Opening Folders in MS-DOS
Creating Folders in MS-DOS
Running Programs in MS-DOS
Correcting Configuration Errors
Setting the PATH on Windows 98 or Me
Setting the Path on Windows NT, 2000, or XP
Using a Text Editor
Creating a Sample Program
Compiling and Running the Program in Windows
Setting Up the CLASSPATH Variable
Setting the CLASSPATH on Windows 98 or Me
Setting the Classpath on Windows NT, XP, 2000 or 2003
Troubleshooting Your Kit Installation
B. Programming with the Java Development Kit
An Overview of the JDK
The java Interpreter
The javac Compiler
The appletviewer Browser
The javadoc Documentation Tool
The jar Java File Archival Tool
The jdb Debugger
Debugging Applications
Debugging Applets
Advanced Debugging Commands
Using System Properties
C. This Book’s Website
What’s on the CD-ROM
Windows Installation Instructions
UNIX and UNIX-like Installation Instructions
Bonus Material on the Companion CD-ROM
Bonus Article: Choosing Java
Java’s Past, Present, and Future
Interactive Web Programming
Java Grew from a Little Oak
Versions of the Language
Java’s Outlook
Why Choose Java
Java Is Object-Oriented
Java Is Easy to Learn
Java Is Platform Neutral
Bonus Chapter: Writing Java Applets
How Applets and Applications Are Different
Applet Security Restrictions
Choosing a Java Version
Creating Applets
Applet Methods
Initialization Method
Start Method
Stop Method
Destroy Method
Paint Method
Writing an Applet
Including an Applet on a Web Page
The Applet Tag
Other Attributes
Loading an Applet
Putting Applets on the Web
Java Archives
Passing Parameters to Applets
Running Applets with Java Web Start
Bonus Chapter: Regular Expressions
Introduction to Pattern Matching
The CharSequence Interface
Using Regular Expressions
Looking for a Match
Splitting Strings with Patterns
Patterns
Matches
Bonus Article: Where to Go from Here: Java Resources
Other Books to Consider
Sun’s Official Java Site
Java Class Documentation
Other Java Websites
This Book’s Official Site
Café au Lait
Workbench
Java Weblogs
InformIT
Java Review Service
JavaWorld Magazine
Gamelan: Earthweb’s Java Directory
Java Newsgroups
Internet Relay Chat
Job Opportunities
Inside Front Cover
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
14. Developing Swing Applications
Next
Next Chapter
15. Working with Input and Output
Part 3. Java Programming
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset