Enterprise Java Where, How, When (and When Not) to Apply Java in Client/Server Business Environments Jeffrey Savit Sean Wilcox Bhuvana Jayaraman McGraw-Hill j New York San Francisco Washington, D.C. Auckland I Bogota Caracas Lisbon London Madrid Mexico City I Milan Montreal New Delhi San J u a n Singapore j Sydney Tokyo Toronto
CONTENTS Preface XIII Chapter 1 Revolutions Leading to Java The Promise of a Networked Computer Computing Before the Web Impersonal Computing Personal Computing Computing in the Home Evolution of Personal Computing to LANs Distributed Client/Server Computing Limitations of the First Wave of Client/Server Applications UNIX, TCP/IP, and the Birth of the Internet Protocols for the World Network Internet Before the Web 2 3 3 4 5 6 6 9 11 12 13 Chapter 2 The World Wide Web The Web's Birth Moving Past Publishing - Web Client/Server Limitations of the Web Model Control of the Screen, Keyboard, and Mouse Pull Technology Security Transaction State Connectionless Connections Very Thin Clients Reasons to Brew Java 15 16 18 20 21 21 22 22 23 24 24 Chapter 3 Java, the Next Step in Network Computing Java Orientation Language Evolution for Modern Computing Java Features 25 27 27 29 Chapter 4 Basic Java Components The Java Development Kit (JDK) Downloading and Installing the JDK JDK Installation on Windows 33 34 35 35
JDK Installation on UNIX 37 Adjust Environmental Variables 38 Network Installation 39 JDK Compatibility 39 What's in the JDK 40 javac, The Java Compiler 40 The Java Interpreter, Java 42 The Java Runtime Environment, jre 43 The Appletviewer 44 The Java Debugger, jab 44 The Java Virtual Machine 46 Other Ways To Run Java 46 JDK Summary 49 Java Language Basics 51 Java Program Organization 52 Java Applications 52 Java Applets 55 Statements 57 Block Statements 58 Control Statements 58 The if-eise Statement 59 The switch Statement 60 The for Statement 61 The while Statement 62 The do-while Statement 62 try and catch 63 Data Types 63 Primitive Data Types 64 Type Conversions 66 Reference Data Types 67 Java Memory Management 69 Expressions 73 Operators 73 Arithmetic Operators 74 Autoincrement and Autodecrement 75 Bitwise Operators 75 Assignment 76 Relational Operators 77 Boolean Operators 77
VII Chapter 6 Object-Oriented Programming in Java 79 What Is Object-Oriented Programming? A Universe of Classes and Objects Classes and Objects in Programming Defining a Class Creating an Object [Using the new Keyword) Variables and Methods Instance and Class Variables Instance and Class Methods Accessing Variable and Methods A Simulation Example The Four Vowels of Object-Oriented Conceptsa, e, i, and o Abstraction Encapsulation Inheritance Overriding An Object-Oriented First Step A Simulation Program Single versus Multiple Inheritance Interfaces Packages 80 81 82 82 83 84 84 85 85 86 87 87 88 89 90 91 91 96 97 98 Chapter 7 The Java 1.1 API and Event-Handling Model 101 The Java Toolbox 102 Java.lang 102 Wrapper Classes 102 Java.lang.String and StringBuffer 104 j ava.lang.thread 105 java.util 106 java.awt 107 Graphical Components 109 j ava.i o 110 The File Class 111 Random Access Files 112 Buffered I/O 112 The Java 1.1 Event-Handling Model 114 Java's Previous Event-Handling Model 115 The Java 1.1 Delegation Model 116
Sources of Events 117 Event Listeners 117 Event Types 118 Delegation Model Example 119 Caveats Regarding the 1.1 Java Developer's Kit 122 Chapter 8 The Java Process Model Multiprogramming Definitions Threads: The Fabric of Java Extending the Thread Class Implementing the Runnable Interface Safe Parallelism Thread Priorities and the JVM Scheduler Threadgroups The ThreadBaker The LazyThread Class The addpressedo Method The deletepressedo Method Threads That Share Resources ThreadBaker2 - The Shared Resource Version 123 125 125 126 127 129 132 133 133 134 135 136 138 139 Chapter 9 Java Integrated Development Environments 143 IDE Advantages and Disadvantages 144 Symantec Cafe and Visual Cafe 144 Creating a Java Applet with Cafe 145 Debugging with Symantec Cafe 150 Microsoft Visual J++ 1.0 152 Creating a Java Program with Visual J++ 152 Debugging with Visual J++ 157 IBM's VisualAge for Java 158 Sun's Java Workshop 159 Chapter 10 Java for Net-Centric Programming Working with URLs Absolute and Relative URLs URLs and Exception Handling Parsing URLs URL Connection Reading and Writing URLs 165 166 166 167 168 168 170
IX Sockets Implementing a TCP Client Program Implementing a TCP Server Program Supporting Multiple Clients Datagrams - Implementing a Client Program Implementing a Datagram Server Program Servlets Servlets Compared to Other Technologies Java Server-Side Framework and Architecture Servlet Security and Access Rights Servlet Applications 172 173 175 177 178 179 180 181 182 183 183 Chapter 11 A Test Drive with Java A Learning Exercise - A Simple Drawing Applet Intraday Stock Charting Summary of Techniques in IChart Java Telephone Directory Client 189 190 193 201 202 Chapter 12 Java Database Connectivity JDBC JDBC Overview JDBC and ODBC JDBC URLs API Overview The DriverManager Class Driver Types Connection Class Statement Class Statement Object PreparedStatement Object CallableStatement Object ResultSet Object SQLException Object JSQL 209 210 210 210 212 212 217 217 218 219 225 227 231 234 235 Chapter 13 Beyond Basic Java Java Generic Library JGL) Containers JGL Algorithms JGL Function Objects JGL Iterators 239 240 240 244 245 247
NetRexx NetRexx Merges Rexx and Java NetRexx Type and Name System Using NetRexx Other NetRexx Features Decimal Arithmetic for Commercial Applications 251 252 253 254 257 260 Chapter 14 Advanced Java Client/Server Marimba's Castanet System Castanet System Castanet Outlook Java Beans JavaBeans and CORBA JavaBeans and ActiveX Component Object Model (COM) Comparing JavaBeans and ActiveX Choosing between JavaBeans and ActiveX Java Remote Method Invocation (RMI) RMI Architecture RMI Implementation Java Platform for the Enterprise Java Enterprise System Management Services Java Enterprise Application Services Enterprise JavaBeans 265 266 266 268 268 269 270 271 272 275 275 276 277 282 283 283 284 Chapter 15 Java Security 287 The World Became More Difficult 288 Applets That Go Bump in the Night and Other Risks 288 Types of Threats 289 Applet Security 289 Java Security Implementation 291 Java Language Safety 292 The Class Loader 293 The Byte-Code Verifier 294 The Security Manager 296 Breaches in Java Security 297 Forged E-mail 299 Denial of Service and Antagonism 300 Managing Applet Security 300 Safe Java at Home 300
XI Eating Out - Java Obtained over the Internet Stay on Top of Security News Theft of Intellectual Property Cryptographic Security for Electronic Commerce Crytography Concepts Java Security API What the Security API Provides Signed Applets Using JAR Files 301 302 302 304 306 308 309 309 Chapter 16 The Network Computer a Java Machine Reducing the Cost of Computing Sun's JavaStation and IMetra J JavaOS Other Network Computers IBM's Network Station Oracle's NCI Subsidiary Microsoft's Response to the NC What Is an NC After All? What's Old Is New Again Internet Appliances Interpreted Execution Performance Sun's picojava I How Fast, Did You Ask? Obstacles to the NC 317 319 320 321 323 323 323 323 324 324 325 325 326 327 328 Chapter 17 Conclusions: Java for Enterprise Computing 331 Java Limitations 332 Java and Requirements for IS Providers 335 Index 339