Register your product to gain access to bonus material or receive a coupon.
8193D-2
More hardcore Java technology for experienced programmers!
Over 250,000 programmers have relied on Core Java to master the fundamentals of Java technology. Now, this expanded second volume provides developers the comprehensive guide they need to solve real-world problems and is an indispensable companion to Core Java 2, Vol. I-Fundamentals, (0-13-766957-7). Completely revised and updated, the new edition features coverage of the advanced features and libraries of the Java 2 Platform and even more of the source code examples that have won universal praise for Core Java.
This volume includes new sections on multithreading in Swing programs, JDBC2, CORBA, the drag-and-drop mechanism, and the Java 2 security model, as well as three completely new chapters. A new advanced Swing chapter covers the complex GUI components for trees and tables as well as sliders, progress meters, tool bars, and tool tips. Also, a new chapter, "Collections," explores the design of the Java collections framework and shows how to use the fundamental data structures that the standard Java library supplies. In addition, the new "Advanced AWT" chapter shows how to use the Java 2D™ API to produce high-quality drawings.
Inside Core Java 2, Volume II-Advanced Features:
About the CD-ROM
CD-ROM includes complete source code examples from the book, the Java 2 SDK, Standard Edition, v 1.2.2, and trial versions of useful Java-based tools.
To facilitate your work with Core Java 2, we are making available for download the code examples for the books below:
Click here for a sample chapter for this book: 0130819344.pdf
1. Multithreading.
What Are Threads? Using Threads to Give Other Tasks a Chance. Running and Starting Threads. Running Multiple Threads. Thread Properties. Thread States. Moving Out of a Blocked State. Dead Threads. Interrupting Threads. Thread Priorities. Selfish Threads. Thread Groups. Synchronization. Thread Communication Without Synchronization. Synchronizing Access to Shared Resources. Object Locks. The Wait and Notify Methods. Deadlocks. Why the Stop and Suspend Methods Are Deprecated. Animation. The Runnable Interface. Loading and Displaying Frames. Using a Thread to Control the Animation. Timers. Daemon Threads. Threads and Swing. Using Pipes for Communication Between Threads.
Collection Interfaces. Separating Collection Interfaces and Implementation. Collection and Iterator Interfaces in the Java Library. Concrete Collections. Linked Lists. Array Lists. Hash Sets. Tree Sets. Maps. The Collections Framework. Views and Wrappers. Bulk Operations. Interfacing with Legacy APIs. Algorithms. Sorting and Shuffling. Binary Search. Simple Algorithms. Writing Your Own Algorithms. Legacy Collections. The Hashtable Class. Enumerations. Property Sets. Bit Sets.
Connecting to a Server. Implementing Servers. Serving Multiple Clients. Sending E-mail. URL Connections. Retrieving Information from a Remote Site. Posting Form Data. CGI Scripts and Servlets. Sending Data to a Web Server. Harvesting Information from the Web. Applet Security. Proxy Servers. Testing the WeatherReport Applet.
The Design of JDBC. Typical Uses of JDBC. The Structured Query Language. Installing JDBC. Basic JDBC Programming Concepts. Database URLs. Making the Connection. Executing Action Commands. Querying with JDBC. Advanced SQL Types (JDBC 2). Populating a Database. Batch Updates (JDBC 2). Executing Queries. Metadata. Scrollable and Updatable Result Sets. Scrollable Result Sets (JDBC 2). Updatable Result Sets (JDBC 2).
Introduction to Remote Objects: The Roles of Client and Server. Remote Method Invocations. Stubs and Parameter Marshalling. Dynamic Class Loading. Setting Up Remote Method Invocation. Interfaces and Implementations. Locating Server Objects. The Client Side. Preparing for Deployment. Deploying the Program. Parameter Passing in Remote Methods. Passing Nonremote Objects. Passing Remote Objects. Using Remote Objects in Sets. Cloning Remote Objects. Inappropriate Remote Parameters. Using RMI with Applets. Java IDL and CORBA. The Interface Definition Language. A CORBA example. Implementing CORBA Servers.
Trees. Tables. A Simple Table. Table Models. Cell Rendering and Editing. Working with Rows and Columns. Styled Text Components. Sliders and Progress Meters. Sliders. Progress Bars. Progress Monitors. Monitoring the Progress of Input Streams. Tool Bars and Tool Tips. Tool Tips. Component Organizers. Split Panes. Tabbed Panes. Desktop Panes and Internal Frames.
The Rendering Pipeline. Shapes. Areas. Strokes. Paint. Coordinate Transformations. Clipping. Transparency and Composition. Rendering Hints. Image Manipulation. Accessing Image Data. Filtering Images. Printing. Printing Single Sheets. Printing Multiple Pages. Print Preview. The Clipboard. Classes and Interfaces for Data Transfer. Transferring Text. Building a Transferable. Building an Image Transferable. Using the ImageSelection Class. Transferring Java Objects via the System Clipboard. Drag and Drop. Drop Targets. Drag Sources.
Why Beans? The Bean-Writing Process. The BDK and the BeanBox. Using the BeanBox. Building an Image Viewer Application via Beans. Naming Patterns for Bean Properties and Events. Bean Property Types. Simple Properties. Indexed Properties. Bound Properties. Constrained Properties. Adding Custom Bean Events. Property Editors. Writing a Property Editor. Going beyond Naming Patterns-Building a BeanInfo Class. FeatureDescriptor Objects. Customizers. Writing a Customizer Class. The Bean Context. Advanced Uses of Introspection. Finding Sibling Beans. Using Bean Context Services.
Class Loaders. Writing Your Own Class Loader. Bytecode Verification. Security Managers and Permissions. Java 2 Platform Security. Security Policy Files. Custom Permissions. Implementing a Permissions Class. A Custom Security Manager. The java.security Package. Message Digests. Digital Signatures. Authentication. The X.509 Certificate Format. Generating Certificates. Signing Certificates. Code Signing. Signing JAR Files. Deployment Tips. Software Developer Certificates.
Locales. Numbers and Currencies. Date and Time. Text. Collation (Ordering). Text Boundaries. Message Formatting. Choice Formats. Character Set Conversion. International Issues and Source Files. Resource Bundles. Locating Resources. Placing Resources into Bundles. Graphical User Interface Localization. Localizing an Applet.
Calling a C Function from the Java Programming Language. Working with the printf Function. Numeric Parameters and Return Values. Using printf for Formatting Numbers. String Parameters. Calling sprintf in a Native Method. Accessing Object Fields. Accessing Static Fields. Signatures. Calling Java Methods. Nonstatic Methods. Static Methods. Constructors. Alternative Method Invocations. Arrays. Error Handling. The Invocation API. A Complete Example: Accessing the Windows Registry. An Overview of the Windows Registry. A Java Platform Interface for Accessing the Registry. Implementing the Registry Access Functions as Native Methods.
The book you have in your hands is the second volume of the fourth edition of Core Java. The first edition appeared in early 1996, the second in late 1996, and the third in 1997/1998. The first two editions appeared in a single volume, but the second edition was already 150 pages longer than the first, which was itself not a thin book. When we sat down to work on the third edition, it became clear that a one-volume treatment of all the features of the JavaTM platform that a serious programmer needs to know was no longer possible. Hence, we decided to break up the third edition into two volumes. In the fourth edition, we again organized the material into two volumes. However, we rearranged the materials, moving streams into volume 1 and collections into Volume 2.
The first volume covers the essential features of the language; this volume covers the advanced topics that a programmer will need to know for professional software development. Thus, as with the first volume and the previous editions of this book, we still are targeting programmers who want to put Java technology to work on real projects.
Please note: If you are an experienced developer who is comfortable with the new event model and advanced language features such as inner classes, you need not have read the first volume in order to benefit from this volume. (While we do refer to sections of the previous volume when appropriate and, of course, hope you will buy or have bought Volume 1, you can find the needed background material in any comprehensive introductory book about the Java platform.)
Finally, when any book is being written, errors and inaccuracies are inevitable. We would very much like to hear about them. Of course, we would prefer to hear about them only once. For this reason, we have put up a web site at http://www.horstmann.com/corejava.html with an FAQ, bug fixes, and workarounds. Strategically placed at the end of the bug report web page (to encourage you to read the previous reports) is a form that you can use to report bugs or problems and to send suggestions for improvements to future editions.
The chapters in this book are, for the most part, independent of each other. You should be able to delve into whatever topic interests you the most and read the chapters in any order.
Chapter 1 covers multithreading, which enables you to program tasks to be done in parallel. (A thread is a flow of control within a program.) We show you how to set up threads and how to make sure none of them get stuck. We put this knowledge to practical use by example, showing you the techniques needed to build timers and animations.
The topic of Chapter 2 is the collections framework of the Java 2 platform. Whenever you want to collect multiple objects and retrieve them later, you will want to use a collection that is best suited for your circumstances, instead of just tossing the elements into a Vector
. This chapter shows you how to take advantage of the standard collections that are prebuilt for your use.
Chapter 3 covers one of the most exciting APIs in the Java platform: the networking API. Java makes it phenomenally easy to do complex network programming. Not only do we cover this API in depth, we also discuss the important consequences of the applet security model for network programming.
Chapter 4 covers JDBCTM, the Java database connectivity API. We show you how to write useful programs to handle realistic database chores, using a core subset of the JDBC API. Please note that this is not a complete treatment of everything you can do with the rich JDBC API. (A complete treatment of the JDBC API would require a book almost as long as this one.)
Chapter 5 covers remote objects and Remote Method Invocation (RMI). This API lets you work with Java objects that are distributed over multiple machines. We also show you where the rallying cry of "objects everywhere" can realistically be used.
Chapter 6 contains all the Swing material that didn't make it into volume 1, especially the important but complex tree and table components. We show the basic uses of editor panes and the Java technology implementation of a "multiple document" interface. Again, we focus on the most useful constructs that you are likely to encounter in practical programming, since an encyclopedic coverage of the entire Swing library would fill several volumes and would only be of interest to dedicated taxonomists.
Chapter 7 covers the Java 2D API that you can use to create realistic drawings. The chapter also covers some advanced features of the Abstract Windowing Toolkit (AWT) that seemed too specialized for coverage in Volume 1 but are, nonetheless, techniques that should be part of every programmer's toolkit. These features include printing and the APIs for cut-and-paste and drag-and-drop. We actually take the cut-and-paste API one step further than Sun Microsystems itself did: We show you how to cut and paste serializable Java objects between different programs in the Java programming language via the system clipboard.
Chapter 8 shows you what you need to know about the component API for the Java platform-JavaBeansTM. You will see how to write your own beans that other programmers can manipulate in integrated builder environments. (We do not cover the various builder environments that are designed to manipulate beans, however.) The JavaBeansTM component technology is an extraordinarily important technology for the eventual success of Java technology because it can potentially bring the same ease of use to user interface programming environments that ActiveX controls give to the millions of Visual Basic programmers. Of course, since these components are written in the Java programming language, they have the advantage over ActiveX controls in that they are immediately usable across other platforms and capable of fitting into the sophisticated security model of the Java platform.
In fact, Chapter 9 takes up that security model. The Java platform was designed from the ground up to be secure, and this chapter takes you under the hood to see how this design is implemented. We show you how to write your own class loaders and security managers for special-purpose applications. Then, we take up the new security API that allows for such important features as signed classes.
Chapter 10 discusses a specialized feature that we believe can only grow in importance: internationalization. The Java programming language is one of the few languages designed from the start to handle Unicode, but the internationalization support in the Java platform goes much further. As a result, you can internationalize Java applications so that they not only cross platforms but cross country boundaries as well. For example, we show you how to write a retirement calculator applet that uses either English, German, or Chinese-depending on the locale of the browser.
Chapter 11 takes up native methods, which let you call methods written for a specific machine such as the Microsoft Windows API. Obviously, this feature is controversial: Use native methods, and the cross-platform nature of the Java platform vanishes. Nonetheless, every serious programmer writing Java applications for specific platforms needs to know these techniques. There will be times when you need to turn to the operating system's API for your target platform when you are writing a serious application. We illustrate this by showing you how to access the registry functions in Windows.
A Java object is an object that is created by a program that was written in the Java programming language.
A Java application is a program that was written in the Java programming language and that is launched by a Java virtual machine (that is, a virtual machine for the Java platform).
Cay S. Horstmann teaches at San Jose State University. In addition to co-authoring the best-selling Core Java, he has written two books on C++/object-oriented development, and is a columnist for C++ Report and Java Report.
View the updates and bug reports for Volumes 1 and 2 of Core Java, Fourth Edition (Java 2).