Learning Java with JBuilder.pdf

(3784 KB) Pobierz
Learning Java with JBuilder
Learning Java ® with JBuilder
VERSION 4
Borland ®
JBuilder
Inprise Corporation
100 Enterprise Way, Scotts Valley, CA 95066-3249
22973898.002.png
Refer to the file DEPLOY.TXT located in the JBuilder 4 redist directory of your JBuilder product for a complete list of
files that you can distribute in accordance with the JBuilder License Statement and Limited Warranty.
Inprise may have patents and/or pending patent applications covering subject matter in this document. The
furnishing of this document does not give you any license to these patents.
Apache Software Foundation conditions and disclaimer
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.
The end-user documentation included with the redistribution, if any, must include the following acknowledgment:
“This product includes software developed by the Apache Software Foundation (http://www.apache.org/).”
Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party
acknowledgments normally appear.
The names “Apache” and “Apache Software Foundation” must not be used to endorse or promote products
derived from this software without prior written permission. For written permission, please contact
apache@apache.org.
Products derived from this software may not be called “Apache”, nor may “Apache” appear in their name, without
prior written permission of the Apache Software Foundation.
THIS SOFTWARE (Tomcat) IS PROVIDED “AS IS” AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE
FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
C OPYRIGHT © 1997, 2000 Inprise Corporation. All rights reserved. All Inprise and Borland brands and product names
are trademarks or registered trademarks of Inprise Corporation. Other product names are trademarks or registered
trademarks of their respective holders.
Printed in the U.S.A.
JBE0040WW21000 1E0R0800
0001020304-9 8 7 6 54321
D3
22973898.003.png
Contents
Chapter 1
Introduction 1-1
Contacting Borland developer support . . . . . 1-2
Online resources . . . . . . . . . . . . . . . . . . 1-2
World Wide Web . . . . . . . . . . . . . . . . 1-2
Borland newsgroups . . . . . . . . . . . . . . 1-3
Usenet newsgroups . . . . . . . . . . . . . . 1-3
Documentation conventions . . . . . . . . . . . 1-3
Java language support . . . . . . . . . . . . . . . 3-6
Learning more about JBuilder . . . . . . . . . . . 3-7
The JBuilder documentation set . . . . . . . . 3-7
Learning more about Java . . . . . . . . . . . . . 3-8
Chapter 4
Using the editor 4-1
Completing code with CodeInsight. . . . . . . . 4-3
Using code templates . . . . . . . . . . . . . . . . 4-4
Keymaps for editor emulations . . . . . . . . . . 4-5
Cursor movement . . . . . . . . . . . . . . . . 4-5
Selection . . . . . . . . . . . . . . . . . . . . . 4-7
Editing text . . . . . . . . . . . . . . . . . . . . 4-8
Clipboard. . . . . . . . . . . . . . . . . . . . 4-10
Search and replace. . . . . . . . . . . . . . . 4-10
Buffers and Files . . . . . . . . . . . . . . . . 4-11
Compile and Debug . . . . . . . . . . . . . 4-11
CodeInsight . . . . . . . . . . . . . . . . . . 4-12
Code Templates . . . . . . . . . . . . . . . . 4-12
View and Help . . . . . . . . . . . . . . . . . 4-12
Part I
JBuilder Quick Start
Chapter 2
What’s new in JBuilder 4 2-1
Web Development . . . . . . . . . . . . . . . . . 2-1
JavaServer Pages and servlet support . . . . 2-2
XML support . . . . . . . . . . . . . . . . . . 2-2
InternetBeans Express . . . . . . . . . . . . . 2-2
Enterprise JavaBeans . . . . . . . . . . . . . . . 2-3
Application server support . . . . . . . . . . . . 2-4
Team development. . . . . . . . . . . . . . . . . 2-4
Version tracking and control . . . . . . . . . 2-4
OpenTools API . . . . . . . . . . . . . . . . . . . 2-5
User Interface changes . . . . . . . . . . . . . . 2-5
JBuilder IDE. . . . . . . . . . . . . . . . . . . 2-5
Wizards . . . . . . . . . . . . . . . . . . . . . 2-6
Editor . . . . . . . . . . . . . . . . . . . . . . 2-7
Keymaps . . . . . . . . . . . . . . . . . . . 2-7
Search and Save . . . . . . . . . . . . . . . 2-8
Running and Debugging . . . . . . . . . . . . . 2-8
Database tools . . . . . . . . . . . . . . . . . . . 2-9
JDataStore . . . . . . . . . . . . . . . . . . . . 2-9
JDBC Explorer improvements . . . . . . . . 2-10
Using JBuilder’s online help . . . . . . . . . . . 2-10
How to get Help . . . . . . . . . . . . . . . . 2-10
Chapter 5
Automating application
development 5-1
Using wizards . . . . . . . . . . . . . . . . . . . . 5-1
Using the object gallery . . . . . . . . . . . . . . 5-2
Additional JBuilder tools. . . . . . . . . . . . . . 5-3
Working with projects . . . . . . . . . . . . . . . 5-4
Saving projects . . . . . . . . . . . . . . . . . . 5-4
Using the Project wizard . . . . . . . . . . . . 5-5
Project wizard: Step 1 . . . . . . . . . . . . 5-5
Project Wizard: Step 2 . . . . . . . . . . . . 5-6
Project Wizard: Step 3 . . . . . . . . . . . . 5-7
Displaying project files . . . . . . . . . . . . . 5-8
Setting project properties . . . . . . . . . . . . 5-9
Managing projects . . . . . . . . . . . . . . . 5-10
Opening projects . . . . . . . . . . . . . . 5-10
Adding and removing files . . . . . . . . 5-10
Saving and closing projects . . . . . . . . 5-11
Renaming projects and files . . . . . . . 5-11
Working with multiple projects . . . . . 5-12
Creating JavaBeans . . . . . . . . . . . . . . . . 5-13
Working with applets. . . . . . . . . . . . . . . 5-14
Using the Applet wizard . . . . . . . . . . . 5-14
Chapter 3
Introducing JBuilder 3-1
What is JBuilder?. . . . . . . . . . . . . . . . . . 3-1
Introducing the AppBrowser . . . . . . . . . . . 3-2
AppBrowser design view . . . . . . . . . . . 3-4
AppBrowser message pane in
debugger view . . . . . . . . . . . . . . . . 3-5
Navigating in the AppBrowser . . . . . . . . 3-5
i
22973898.004.png
Chapter 6
Building a user interface 6-1
Using the UI designer . . . . . . . . . . . . . . . 6-2
Viewing a file . . . . . . . . . . . . . . . . . . 6-3
Adding and manipulating components . . . 6-3
Designing menus . . . . . . . . . . . . . . . . . 6-3
Setting component properties and events . . . . 6-4
Opening the Inspector . . . . . . . . . . . . . 6-5
Designing layouts with layout managers . . . . 6-5
Keywords . . . . . . . . . . . . . . . . . . . . 9-5
Statements . . . . . . . . . . . . . . . . . . . . 9-6
Code blocks . . . . . . . . . . . . . . . . . . . 9-6
Comments . . . . . . . . . . . . . . . . . . . . 9-7
Expressions. . . . . . . . . . . . . . . . . . . . 9-8
Operators . . . . . . . . . . . . . . . . . . . . . 9-8
Arithmetic operators . . . . . . . . . . . . 9-9
Logical operators. . . . . . . . . . . . . . 9-10
Comparison operators . . . . . . . . . . 9-10
Assignment operators . . . . . . . . . . . 9-11
Bitwise operators . . . . . . . . . . . . . 9-12
A special operator: The ?: operator . . . 9-12
Java’s data types . . . . . . . . . . . . . . . . . 9-13
Variables . . . . . . . . . . . . . . . . . . . . 9-13
Built-in data types . . . . . . . . . . . . . . . 9-14
Numeric data types . . . . . . . . . . . . 9-14
Boolean data types. . . . . . . . . . . . . 9-14
Character data types. . . . . . . . . . . . 9-15
Composite data types . . . . . . . . . . . . . 9-15
Arrays . . . . . . . . . . . . . . . . . . . . 9-15
Strings . . . . . . . . . . . . . . . . . . . . 9-16
Type casting . . . . . . . . . . . . . . . . . . 9-17
Implicit casting . . . . . . . . . . . . . . . 9-18
Scope rules . . . . . . . . . . . . . . . . . . . 9-18
Flow control structures . . . . . . . . . . . . . . 9-19
Loops . . . . . . . . . . . . . . . . . . . . . . 9-19
The while loop . . . . . . . . . . . . . . . 9-19
The do loop . . . . . . . . . . . . . . . . . 9-20
The for loop. . . . . . . . . . . . . . . . . 9-20
Loop control statements . . . . . . . . . . . 9-21
The break statement . . . . . . . . . . . . 9-21
The continue statement . . . . . . . . . . 9-22
Conditional statements . . . . . . . . . . . . 9-22
The if-else statement. . . . . . . . . . . . 9-22
The switch statement . . . . . . . . . . . 9-23
Summary. . . . . . . . . . . . . . . . . . . . . . 9-24
Chapter 7
Compiling and running
Java programs 7-1
Compiling Java programs. . . . . . . . . . . . . 7-1
Running Java programs . . . . . . . . . . . . . . 7-2
Debugging Java programs . . . . . . . . . . . . 7-3
Debugging . . . . . . . . . . . . . . . . . . . 7-4
Deploying Java programs . . . . . . . . . . . . . 7-5
Using the Archive Builder . . . . . . . . . . . 7-5
Deploying CORBA applications . . . . . . . 7-6
Deploying web-based applications. . . . . . 7-7
Running deployed programs . . . . . . . . . 7-7
Using command line tools . . . . . . . . . . . . 7-8
Chapter 8
Building distributed applications 8-1
Team development. . . . . . . . . . . . . . . . . 8-1
Java technologies. . . . . . . . . . . . . . . . . . 8-2
Building database applications . . . . . . . . . . 8-4
Developing international applications . . . . . 8-5
Internationalization features in JBuilder . . . 8-6
Part II
Getting Started with Java
Chapter 9
Java language basics 9-1
Java syntax . . . . . . . . . . . . . . . . . . . . . 9-1
Identifiers . . . . . . . . . . . . . . . . . . . . 9-2
Literals . . . . . . . . . . . . . . . . . . . . . . 9-3
Integer literals . . . . . . . . . . . . . . . . 9-3
Floating-point literals . . . . . . . . . . . 9-4
Boolean literals . . . . . . . . . . . . . . . 9-4
Character literals . . . . . . . . . . . . . . 9-4
String literals . . . . . . . . . . . . . . . . 9-5
Chapter 10
Object-oriented programming
in Java 10-1
Introduction to OOP . . . . . . . . . . . . . . . 10-1
Classes . . . . . . . . . . . . . . . . . . . . . . . 10-2
Declaring and instantiating classes . . . . . 10-2
Data members . . . . . . . . . . . . . . . . . 10-3
Class methods . . . . . . . . . . . . . . . . . 10-3
Constructors and finalizers. . . . . . . . . . 10-4
ii
22973898.005.png
Case study: A simple OOP example . . . . . 10-4
Class inheritance . . . . . . . . . . . . . . . . 10-6
Using this and super . . . . . . . . . . . . 10-8
Access modifiers . . . . . . . . . . . . . . . . 10-9
Access from within class’s package . . . . 10-9
Access outside of a class’s package . . . . 10-9
Accessor methods . . . . . . . . . . . . . . 10-10
Abstract classes . . . . . . . . . . . . . . . . 10-11
Polymorphism . . . . . . . . . . . . . . . . . . 10-13
Method overloading . . . . . . . . . . . . . 10-13
Using interfaces. . . . . . . . . . . . . . . . 10-13
Java packages. . . . . . . . . . . . . . . . . . . 10-17
The import statement . . . . . . . . . . . . 10-17
Declaring packages. . . . . . . . . . . . . . 10-18
Project options related to packages. . . . . 10-19
Summary . . . . . . . . . . . . . . . . . . . . . 10-19
The Thread API . . . . . . . . . . . . . . . . . . 12-5
Constructors . . . . . . . . . . . . . . . . . . 12-5
The start() method. . . . . . . . . . . . . . . 12-6
The sleep() method . . . . . . . . . . . . . . 12-6
The yield() method . . . . . . . . . . . . . . 12-6
The join() method . . . . . . . . . . . . . . . 12-6
A thread’s lifecycle . . . . . . . . . . . . . . . . 12-7
Making your code thread-safe. . . . . . . . . . 12-7
The synchronized keyword . . . . . . . . . 12-7
Monitors . . . . . . . . . . . . . . . . . . . . 12-8
Summary. . . . . . . . . . . . . . . . . . . . . . 12-9
Chapter 13
Serialization 13-1
Overview . . . . . . . . . . . . . . . . . . . . . 13-1
Why serialize? . . . . . . . . . . . . . . . . . . . 13-1
Serialization in JDK 1.1 . . . . . . . . . . . . . . 13-2
The Serializable interface . . . . . . . . . . . 13-2
Using output streams. . . . . . . . . . . . . . . 13-3
ObjectOutputStream methods . . . . . . . . 13-4
Using input streams . . . . . . . . . . . . . . . 13-4
ObjectInputStream methods . . . . . . . . . 13-6
Writing and reading object streams . . . . . . . 13-6
Summary. . . . . . . . . . . . . . . . . . . . . . 13-6
Chapter 11
The Java class libraries 11-1
Introduction . . . . . . . . . . . . . . . . . . . . 11-1
The Language package . . . . . . . . . . . . . . 11-2
The Object class . . . . . . . . . . . . . . . . 11-2
Type wrapper classes . . . . . . . . . . . . . 11-2
The Math class . . . . . . . . . . . . . . . . . 11-3
The String class . . . . . . . . . . . . . . . . . 11-4
The StringBuffer class . . . . . . . . . . . . . 11-5
The System class . . . . . . . . . . . . . . . . 11-6
The Utilities package . . . . . . . . . . . . . . . 11-6
The Enumeration interface . . . . . . . . . . 11-7
The Vector class . . . . . . . . . . . . . . . . . 11-7
The I/O package . . . . . . . . . . . . . . . . . . 11-9
Input stream classes . . . . . . . . . . . . . . 11-9
Output Stream classes . . . . . . . . . . . . 11-11
File classes. . . . . . . . . . . . . . . . . . . 11-12
The StreamTokenizer class . . . . . . . . . 11-13
Summary . . . . . . . . . . . . . . . . . . . . . 11-13
Chapter 14
Java Virtual Machine security 14-1
Overview . . . . . . . . . . . . . . . . . . . . . 14-1
Why is the Java VM necessary? . . . . . . . 14-2
What are the main roles of the JVM? . . . . 14-2
Java VM security . . . . . . . . . . . . . . . . . 14-3
The security model . . . . . . . . . . . . . . 14-3
The Java verifier . . . . . . . . . . . . . . 14-3
The Security Manager . . . . . . . . . . . 14-4
The class loader . . . . . . . . . . . . . . 14-5
Java’s safety as a language . . . . . . . . 14-6
What about Just-In-Time compilers? . . . . 14-6
Summary. . . . . . . . . . . . . . . . . . . . . . 14-7
Chapter 12
Threading techniques 12-1
Overview . . . . . . . . . . . . . . . . . . . . . . 12-1
Why are threads useful? . . . . . . . . . . . . 12-1
Why haven’t I heard of threads before? . . . 12-2
Creating a thread. . . . . . . . . . . . . . . . . . 12-2
Subclassing the Thread class . . . . . . . . . 12-2
Example: Implementing
countingThread . . . . . . . . . . . . . . 12-3
Implementing the Runnable interface . . . . 12-4
Chapter 15
Working with the native code
interface 15-1
Overview . . . . . . . . . . . . . . . . . . . . . 15-1
Using the JNI. . . . . . . . . . . . . . . . . . 15-1
Using the native keyword . . . . . . . . . . 15-2
Using the javah tool . . . . . . . . . . . . . . 15-3
Summary . . . . . . . . . . . . . . . . . . . . . 15-3
iii
22973898.001.png
Zgłoś jeśli naruszono regulamin