HAPPY BOOKSGIVING
Use code BOOKSGIVING during checkout to save 40%-55% on books and eBooks. Shop now.
Register your product to gain access to bonus material or receive a coupon.
Question 1: On Page 603 the following was stated: "System.in is an instantiation of java.io.InputStream" but the java.io.InputStream is an abstract class with the abstract method - abstract int read(). An abstract class can not be instantiated so how is it possible?
Solution 1: While you can't create an instance of InputStream, it's perfectly valid to have a variable of type "InputStream" like System.in. You aren't supposed to know how it is implemented, you just use the InputStream methods to access the object.
You can discover the real class, if you like, by doing the following:
System.out.println(System.in.getClass().getName());
In my Windows 2000 system, I get "java.io.BufferedInputStream", which means that System.in is actually a chain of input streams because BufferedInputStream is a FilterInputStream that just adds buffering capabilities to an existing stream.
While I can discover the real implementation class, it's a bad idea to make use of that. It may vary from implementation to implementation since the only requirement is that System.in be an InputStream.
You don't ever need to instantiate System.in anyway, it's always there. You can replace it, though. For example, if you want to replace System.in with the contents of a file, you can do this:
//---------------------------------------------------------
// Open myinput.txt
FileInputStream newIn = new FileInputStream("myinput.txt");
// Buffer it for better performance
BufferedInputStream buffIn = new BufferedInputStream(newIn);
// Replace System.in with the new stream
System.setIn(buffIn);
//-----------------------------------------------------------
Question 2: On page 42, it states that the JDK is on the CD-ROM. Where is it?
Solution 2: There is a typo on page 42. The JDK is not on the CD-ROM. You will have to download the JDK from the JavaSoft website: http://www.java.sun.com/products/jdk/1.2/
********SEE NOTE BELOW ABOUT JDK ON MAC*************
Special Edition Using Java 2 Platform is the complete programmer's tutorial/reference for Java 2 and related technologies. The book contains detailed descriptions of Sun's Java 2 standards, APIs, class libraries, and programming tools. Also includes coverage of Microsoft's Java SDK 2.0, AFC, and RNI products, ActiveX, CORBA, Java IDL, Joe, JavaBeans, and Enterprise JavaBeans. Over 20,000 lines of documented Java code show programmers the details of building sophisticated Java applications.
Introduction.
This Book Is for You. How This Book Is Organized. Conventions Used in This Book.
I. INTRODUCTION TO JAVA.
1. What Java Can Do for You.
The Many Types of Java Applications. Learning About the Java Language. The Java Development Kit. Java Applets. Java GUI Applications. Java Command Line Applications. Java Is Client/Server. How to Stay Current.
2. Java Design.
Java Is Interpreted. Java Is Object Oriented. The Java Virtual Machine. Security and the JVM. The Java API.
3. Installing the JDK and Getting Started.
Why You Need Sun's Java Development Kit to Write Java. More on How Java Is Both Compiled and Interpreted. Getting and Installing Sun's JDK. Installing a Downloaded JDK. Testing the Java Compiler and JVM. Installing IBM's Applet Developer's Kit for Windows 3.1.
4. JDK Tools.
JDK Tools Reference. AppletViewer. java, The Java Interpreter. javac, The Java Compiler. javap, The Java Disassembler. javah C-Header and Stub File Creation. The javadoc Tool (Documentation Generator). jdb, The Java Debugger. The CLASSPATH Environment Variable. Macintosh Issues. The Java Compiler. JavaH: C-Header File Generator.
II. THE JAVA LANGUAGE.
5. Obejct-Oriented Programming.
Object-Oriented Programming: A New Way of Thinking. A Short History of Programming. A Lesson in Objects. Objects as Multiple Entities. Organizing Code. Objects and How They Relate to Java Classes. Building a Hierarchy: A Recipe for OOP Design. Java Isn't a Magic OOP Bullet.
6. HelloWorld!: Your First Java Program.
HelloWorld Application. Understanding HelloWorld. HelloWorld as an Applet—Running in Netscape. Keywords. API.
7. Data Types and Other Tokens.
Java Has Two Data Types. Learning About boolean Variables. The Various Flavors of Integer. Operators. Character Variables. Floating-Point Variables. Arrays. Whitespace. Comments. Literals: Assigning Values. Creating and Destroying Objects.
8. Methods.
Parts of a Method. Blocks and Statements. Separators.
9. Using Expressions.
What Is an Expression? How Expressions Are Evaluated. Of Special Interest to C Programmers. Bitwise Operators. The Shift Operators. Type Conversions. Addition of Strings.
10. Control Flow.
Controlling the Execution. true and false Operators on Booleans. Logical Expressions. The Conditional Operator. Booleans in Control Flow Statements. Control Flow Functions. Iteration Statements. Jump Statements.
Chapter 11. Classes.
What Are Classes? Why Use Classes? Classes in Java. Declaring a Class. Constructors. Creating an Instance of a Class. Referring to Parts of Classes. Variables. Inner Classes. Packages. Improting Classes in Packages. Importing Entire Packages. Using a Class Without Importing It. Using Packages to Organize Your Code. Implicit Import of all java.lang Classes. Import of All java.lang Classes.
12. Interfaces.
What Are Interfaces? Creating an Interface. Implementing Interfaces. Using Interfaces from Other Classes. Exceptions.
13. Threads.
What Are Threads? Why Use Threads? How to Make Your Classes Threadable. The Great Thread Race. Understanding the GreatRace. Thread Processing. Try Out the Great Thread Race. Changing the Priority. A Word About Thread Priority, Netscape, and Windows. Synchronization. Speaking with a Forked Tongue. Changing the Running State of the Threads. Obtaining the Number of Threads That Are Running. Finding All the Threads That Are Running. The Daemon Property.
14. Writing an Applet.
Java's Children. Applets and HTML. Including a Java Applet in an HTML Page. Using Java Plug-in. Begin Developing Java Applets. Exploring the Life Cycle of an Applet. An Applet That Uses Controls.
15. Advanced Applet Code.
Using the PARAM Tag. Adding Images to an Applet. Adding Sound to an Applet. Using the Applet to Control the Browser. Putting It All Together.
16. JAR Archive Files.
Why JAR? When to Use JAR Archives. JAR Archives and Security. The java.util.zip Package. JAR File Format.
17. Applets Versus Applications.
Applications Explored. Advantages of Applications. Developing Java Applications. Converting an Applet to an Application. Packaging Your Applications in Zip Format. Converting an Application to an Applet.
18. Managing Applications.
Installing Applications. Maintaining Multiple Applications on the Same System.
III. USER INTERFACE.
19. java.awt: Components.
Building GUI with java.awt. Buttons. Using Buttons with the 1.1 Event Model. Labels. Check Boxes and Radio Buttons. Choices. Lists. Text Fields and Text Areas. Scrollbars. Canvases. Common Component Methods.
20. Exceptions and Events in Depth.
Java's Exceptions. Java's Error Classes. Java's Events. Event-Handling Techniques. Keyboard and Mouse Events. The 1.0 Event Model.
21. Containers and Layout Managers.
Organizing Components. Containers. Layout Managers. Container Basics. Panels. Frames. Dialogs. ScrollPanes. Layout Managers. Insets. The Null Layout Manager. Future Extensions from Sun.
22. Graphics.
Java Graphics. paint, Update, and repaint. The Graphics Class. The Polygon Class. Drawing Text. Drawing Modes. Drawing Images. The MediaTracker Class. Graphics Utility Classes. The Color Class. Clipping. Animation Techniques. Printing.
23. JFC—Java Foundation Classes.
Java Foundation Classes. JFC: A First Look. HelloWorld. Improving HelloWorld. Adding Buttons with JFC. Adding ToolTips and Icons. Using Pop-Up Menus. Borders. Check Boxes and Radio Buttons. Applying CheckBoxPanel to Change Text Alignment. Tabbed Panes. Sliders. Progress Bars.
24. Advanced JFC.
Model-View-Control—JFC's Design. Menus and Toolbars. Lists and Combo Boxes. Using Tables. Trees. Displaying HTML with JEditor. Creating Icons. JFC Applets.
25. Images.
Drawing Images to the Screen. Producers, Consumers, and Observers. Image Filters. Copying Memory to an Image. Copying Images to Memory.Color Models.
26. Java 2D Graphics.
The Graphics2D Object. Coordinates in Java 2D. Drawing Figures. Different Strokes. Custom Fills. Transformations. Drawing Text. Drawing Images. Transparency. Clipping.
IV. IO.
27. Files, Streams, and Java.
Streams: What Are They? The Basic Input and Output Classes. Handling Files. Using Pipes. Buffered Streams. Data Streams. Byte Array Streams. Char Array Streams. Conversion Between Bytes and Characters. The StringBufferInputStream. Object Streams. Other Streams. The StreamTokenizer Class.
28. Using Strings and Text.
Introducing Strings. Using the String Class. Using the StringBuffer Class. Using the StringTokenizer Class. Dealing with Fonts.
29. Using Internationalization.
Internationalization Scenario. What Is Internationalization? Java Support for Internationalization. Input-Output (I/O) for Internationalization. The New Package java.text. An Example: InternationalTest.
30. Communications and Networking.
Overview of TCP/IP. TCP/IP Protocols. Uniform Resource Locator (URL). Java and URLs.
31. TCP Sockets.
TCP Socket Basics. Creating a TCP Client/Server Application.
32. UDP Sockets.
Overview of UDP Messaging. Creating a UDP Server. Creating a UDP Client. Using IP Multicasting.
33. java.net.
The URL Class. The URLConnection Class. The HTTPURLConnection Class. The URLEncoder Class. The URLDecoder Class. The URLStreamHandler Class. The ContentHandler Class. The Socket Class. The ServerSocket Class. The InetAddress Class. The DatagramSocket Class. The DatagramPacket Class. Multicast Sockets.
34. Java Security in Depth.
What Necessitates Java Security? The Java Security Framework. Applet Restrictions. Java Security Problems. The Java Security API: Expanding the Boundaries for Applets. The Security API.
35. Object Serialization.
What Is Object Serialization? Object Serialization Example. Writing and Reading Your Own Objects. Customizing Object Serialization.
36. Remote Method Invocation.
What Is Remote Method Invocation? Creating an Applet Client. Creating a Custom Socket. Using the Activation Model.
37. Management API.
JMAPI Components. JMAPI Applets. Creating a Managed Object. The Admin View Module.
V. DATABASES.
38. Databases Introduced.
ODBC and JDBC. Relational Database Concepts. An ODBC Technical Overview. Advanced Client/Server Concepts.
39. JDBC: The Java Database Connectivity.
JDBC Overview. JDBC Implementation. The Connection Class. Metadata Functions. The SQLException Class. The SQLWarnings Class.
40. JDBC Explored.
Statements. ResultSet Processing Retrieving Results. Other JDBC Classes. JDBC in Perspective.
VI. COMPONENT-BASED DEVELOPMENT.
41. JavaBeans.
Self-Contained Components. Important Concepts in Component Models. The Basics of Designing a JavaBean. Creating and Using Properties. Using Events to Communicate with Other Components. Introspection: Creating and Using BeanInfo Classes. Customization: Providing Custom PropertyEditors and GUI Interfaces. Enterprise JavaBeans.
42. JavaIDL: A Java Interface to CORBA.
What Is CORBA? Sun's IDL to Java Mapping. Methods. Creating a Basic CORBA Server. Creating CORBA Clients with JavaIDL. Creating Callbacks in CORBA. Wrapping CORBA Around an Existing Object. Using CORBA in Applets.
43. Java—COM Integration.
A Significant Extension. A Brief Overview of COM. Defining COM Interfaces. Compiling an ODL File. Generating a GUID. Creating COM Objects in Java. Calling Java COM Objects from Visual Basic. Calling Java Objects from Excel. Calling COM Objects from Java.
VII. ADVANCED JAVA.
44. Java Media Framework.
What Is the Java Media Framework? Creating a Media Player. The States of the Player. Adding Controls to the Player. Controlling the Player Programmatically. Linking Multiple Players. Creating Your Own Media Stream. A Larger Application.
45. Commerce and Java Wallet.
Security Support with the JCC. Commerce Messages. Creating Cassettes.
46. Data Structures and Java Utilities.
What Are Data Structures? Collections. The Vector Class. The Hashtable Class. The Properties Class. The Stack Class. The Date Class. The BitSet Class. The StringTokenizer Class. The Random Class. The Observable Class.
47. java.lang.
The java.lang Packages. The Object Class. The Class Class. The Package Class. The String Class. The StringBuffer Class. The Thread Class. The ThreadGroup Class. The Throwable Class. The System Class. The Runtime and Process Classes. The Math Class. The Object Wrapper Classes. The Character Class. The Boolean Class. The Number Class. The Integer Class. The Long Class. The Byte Class. The Short Class. The Float Class. The Double Class. The Void Class. The java.math.BigInteger Class. The java.math.BigDecimal Class. Creating a BigDecimal. The ClassLoader Class. The SecurityManager Class. The Compiler Class.
48. Reflection.
What Is Reflection? Creating a Class Knowing Only the List of Constructors. Inspecting a Class for Its Methods. Using getDeclaredMethod() to Invoke a Method. Invoking Methods That Use Native Types as Parameters. Getting the Declared Fields of a Class.
49. Extending Java with Other Languages.
Native Methods, a Final Frontier for Java. The Case for "Going Native." JNI Highlights. Writing Native Methods. Accessing Object Fields from Native Methods. Accessing Java Methods from Native Methods. Accessing Static Fields. Accessing Static Methods. Exception Handling Within Native Methods.
50. Java Versus C(++).
Common Ancestry. Basic Java Syntax. The Structure of Java Programs. Java Data Types. Objects and Classes. Aggregates: Strings, Arrays, and Vectors. Class Hierarchies and Inheritance. Statements. Name Spaces.
VIII. DEBUGGING JAVA.
51. Debugging Java Code.
The Architecture of the sun.tools.debug Package. The JDB in Depth.
52. Understanding the .class File.
A Fundamental Measurement. Elements of the .class File. Definitions. The .class File Structure. So Now What Can I Do?
53. Inside the Java Virtual Machine.
Elements of the JVM.
IX. JAVASCRIPT.
54. Java Versus JavaScript.
Java and JavaScript. JavaScript Is Not Java. Interpreted Versus Compiled. Object Based Versus Object Oriented. Strong Typing Versus Loose Typing. Dynamic Versus Static Binding. Restricted Disk Access. Different Functionality (Scope Limitations) and Code Integration with HTML. Rapid Evolution Versus Relative Stability. Libraries. JavaScript and Java Integration.
55. Starting with JavaScript.
The Basics. Your First Script. Events. Using Event Handlers. Variables. Variable Names. Variable Scope. Literals. Expressions and Operators. Control Statements. Functions in JavaScript. Arrays. Built-In Functions. Objects. A Final Example.
X. JAVA RESOURCES.
56. Java Resources.
Web Sites. Newsgroups. Mailing Lists. Support for Porting Issues.
XI. APPENDIX.
Appendix A. What's on the CD-ROM.
Example Code from the Book. Third-Party Software. Bonus Software.
Index.