Java
By Example
Clayton Walnum
C O N T E N T S
Introduction
Who This Book Is For●
Hardware and Software Requirements●
Compiling the Programs in This Book●
A Word to the Wise●
On to the Wonderful World of Java●
Chapter 1 Java Overview
The Java Story●
Introducing Java●
Java Programs●
The Java Developer's Kit●
Where Is Java?●
Example: Installing HotJava●
Example: Installing the JDK●
Summary●
Review Questions●
Review Exercises●
http://www.ngohaianh.info
Chapter 2 Running Java Applets
The Sample Java Applets
The Appletviewer Tool❍
Example: Running TicTacToe❍
The Animator Applet❍
The BarChart Applet❍
Other Demo Applets❍
●
Adding Applets to an HTML Document
Optional Attributes for Applets❍
Applet Parameters❍
Non-Java Browsers❍
Example: A Java-Powered Home Page❍
●
Summary●
Review Questions●
Review Exercises●
Chapter 3 Applets and the Internet
Local and Remote Applets
Local Applets❍
Remote Applets❍
●
Clients and Servers●
Security●
Example: Your Pages on the Web●
Summary●
Review Questions●
Review Exercises●
Chapter 4 Object-Oriented Programming Concepts
From Switches to Objects●
An Obvious, Yet Brilliant, Solution●
Object-Oriented Programming●
http://www.ngohaianh.info
Encapsulation❍
Classes as Data Types❍
Inheritance❍
Polymorphism❍
Example: Encapsulation, Inheritance, and Polymorphism❍
Summary●
Review Questions●
Review Exercises●
Chapter 5 Constants and Variables
Constants●
Variables●
Naming Constants and Variables●
Example: Creating Your Own Identifiers●
Data Types
Integer Values❍
Floating-Point Values❍
Character Values❍
Boolean Values❍
●
Variable Scope
Example: Determining a Variable's Scope❍
●
Summary●
Review Questions●
Review Exercises●
Chapter 6 Simple Input and Output
Windows and Graphics●
Displaying Text in an Applet
Example: Creating and Running Applet1❍
How Applet1 Works❍
●
Getting Input from the User
How Applet2 Works❍
●
http://www.ngohaianh.info
Example: Retrieving text from a TextField control❍
How Applet3 Works❍
Displaying Numerical Values●
Summary●
Review Questions●
Review Exercises●
Chapter 7 Math Operators
The Addition Operator
Example: Using the Addition Operator❍
Example: Multiple Additions❍
●
The Subtraction Operator
Example: Using the Subtraction Operator❍
Example: Multiple Subtractions Using Mixed Data Types❍
Example: Casting a Result to a Different Data Type❍
●
The Multiplication Operator
Example: Multiplication and Data Types❍
●
The Division Operator
Example: Integer Versus Floating-Point Division❍
●
The Modulo Operator●
The Increment Operator●
The Decrement Operator●
Example: Using Mathematical Calculations in an Applet
How Applet5 Works❍
●
The Order of Operations
Example: Order of Operations❍
Example: More Order of Operations❍
Example: Still More Order of Operations❍
Example: One Last Order of Operations❍
●
Summary●
Review Questions●
Review Exercises●
http://www.ngohaianh.info
Chapter 8 Expressions
Types of Expressions●
Expressions Within Expressions●
Comparison Operators
Example: Using Comparison Operators❍
●
Logical Operators
Example: Using Logical Operators❍
Example: Using Multiple Logical Operators❍
Example: Combining Different Comparison and Logical Operators❍
●
Writing Logical Expressions●
Order of Operations●
Summary●
Review Questions●
Review Exercises●
Chapter 9 The if and switch Statements
Controlling Program Flow●
Program Flow and Branching●
The if statement
Example: The Form of an if Statement❍
Multiple if Statements❍
Multiple-Line if Statements❍
The else Clause❍
Example: Using the if Statement in a Program❍
●
The switch Statement
Example: Using the break Statement Correctly❍
Example: Using the switch Statement in a Program❍
●
Summary●
Review Questions●
Review Exercises●
http://www.ngohaianh.info