📄 tij0008.html
字号:
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>finally</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
work in Java; when you should throw exceptions and what to do when you catch
them. In addition, you’ll see Java’s standard exceptions, how to
create your own, what happens with exceptions in constructors, and how
exception handlers are located.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Chapter
10:
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B><I>
The
Java IO system
</I></B></FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Theoretically,
you can divide any program into three parts: input, process, and output. This
implies that IO (input/output) is a pretty important part of the equation. In
this chapter you’ll learn about the different classes that Java provides
for reading and writing files, blocks of memory, and the console. The
distinction between “old” IO and “new” Java 1.1<A NAME="Index5"></A>
IO will be shown. In addition, this section examines the process of taking an
object, “streaming” it (so that it can be placed on disk or sent
across a network) and reconstructing it, which is handled for you in Java
version 1.1. Also, Java 1.1’s compression libraries, which are used in
the Java ARchive file format (JAR), are examined.
</FONT><a name="OLE_LINK9"></a><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Chapter
11:
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B><I>
Run-time
type identification
</I></B></FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Java
run-time type identification (RTTI) lets you find the exact type of an object
when you have a handle to only the base type. Normally, you’ll want to
intentionally ignore the exact type of an object and let Java’s dynamic
binding mechanism (polymorphism) implement the correct behavior for that type.
But occasionally it is very helpful to know the exact type of an object for
which you have only a base handle. Often this information allows you to perform
a special-case operation more efficiently. This chapter explains what RTTI is
for, how to use it and how to get rid of it when it doesn’t belong there.
In addition, the Java 1.1
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><I>reflection</I></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
feature is introduced.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Chapter
12:
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B><I> Passing
and returning objects
</I></B></FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Since
the only way you talk to objects in Java is through “handles,” the
concepts of passing an object into a function and returning an object from a
function have some interesting consequences. This chapter explains what you
need to know to manage objects when you’re moving in and out of
functions, and also shows the
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>String</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
class, which uses a different approach to the problem.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Chapter
13:
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B><I> Creating
windows and applets
</I></B></FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Java
comes with the
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><I>Abstract</I></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><I>Window
Toolkit
</I></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
(AWT), which is a set of classes that handle windowing in a portable fashion;
these windowing programs can either be applets or stand-alone applications.
This chapter is an introduction to the AWT and the creation of World Wide Web
applets. We’ll also look at pros and cons of the AWT and the GUI
improvements introduced in Java 1.1. The important “Java Beans”
technology is introduced. This is fundamental for the creation of
Rapid-Application Development (RAD) program-building tools. Finally, the new
Java 1.2 “Swing” library is introduced – this provides a
dramatic improvement in UI components for Java.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Chapter
14
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B><I>:
Multiple
threads
</I></B></FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Java
provides a built-in facility to support multiple concurrent subtasks, called
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><I>threads</I></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">,
running within a single program. (Unless you have multiple processors on your
machine, this is only the
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><I>appearance</I></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
of multiple subtasks.) Although these can be used anywhere, threads are most
powerful when trying to create a responsive user interface so, for example, a
user isn’t prevented from pressing a button or entering data while some
processing is going on. This chapter looks at the syntax and semantics of
multithreading in Java.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Chapter
15:
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B><I>Network
programming
</I></B></FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">All
the Java features and libraries seem to really come together when you start
writing programs to work across networks. This chapter explores communication
across the Internet, and the classes that Java provides to make this easier. It
also shows you how to create a Java applet that talks to a
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><I>common
gateway interface
</I></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">(CGI)
program, shows you how to write CGI programs in C++ and covers Java 1.1’s
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><I>Java
DataBase Connectivity
</I></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
(JDBC) and
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><I>Remote
Method Invocation
</I></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
(RMI).
</FONT><a name="OLE_LINK13"></a><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Chapter
16:
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B><I>Design
patterns
<a name="OLE_LINK12"></a></I></B></FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">This
chapter introduces the very important and yet non-traditional
“patterns” approach to program design. An example of the design
evolution process is studied, starting with an initial solution and moving
through the logic and process of evolving the solution to more appropriate
designs. You’ll see one way that a design can materialize over time.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Chapter
17:
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B><I>Projects
</I></B></FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">This
chapter includes a set of projects that build on the material presented in this
book, or otherwise didn’t fit in earlier chapters. These projects are
significantly more complex than the examples in the rest of the book, and they
often demonstrate new techniques and uses of class libraries.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">There
are subjects that didn’t seem to fit within the core of the book, and yet
I find that I discuss them during seminars. These are placed in the appendices.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Appendix
A:
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B><I>Using
non-Java code
</I></B></FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">A
totally portable Java program has serious drawbacks: speed and the inability to
access platform-specific services. When you know the platform that you’re
running on, it’s possible to dramatically speed up certain operations by
making them
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><I>native
methods
</I></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">,
which are functions that are written in another programming language
(currently, only C/C++ is supported). There are other ways that Java supports
non-Java code, including CORBA. This appendix gives you enough of an
introduction to these features that you should be able to create simple
examples that interface with non-Java code.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><I>Appendix</I></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
B:
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B><I>Comparing
C++ and Java
</I></B></FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">If
you’re a C++ programmer, you already have the basic idea of
object-oriented programming, and the syntax of Java no doubt looks very
familiar to you. This makes sense because Java was derived from C++. However,
there are a surprising number of differences between C++ and Java. These
differences are intended to be significant improvements, and if you understand
the differences you’ll see why Java is such a beneficial programming
language. This appendix takes you through the important features that make Java
distinct from C++.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Appendix
C:
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B><I>Java
programming guidelines
</I></B></FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">This
appendix contains suggestions to help guide you while performing low-level
program design and writing code.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Appendix
D:
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B><I>Performance</I></B></FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">This
will allow you to find bottlenecks and improve speed in your Java program.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Appendix
E:
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B><I>A
bit about garbage collection
</I></B></FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">This
appendix describes the operation and approaches that are used to implement
garbage collection.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Appendix
F:
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B><I>Recommended
reading
</I></B></FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">A
list of some of the Java books I’ve found particularly useful.
</FONT><a name="_Toc312373773"></a><a name="_Toc375545181"></a><a name="_Toc408018375"></a><P></DIV>
<div align="right">
<a href="tij_c.html">Contents</a> | <a href="tij0007.html">Prev</a> | <a href="tij0009.html">Next</a>
</div>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -