Manual java

Solo disponible en BuenasTareas
  • Páginas : 243 (60587 palabras )
  • Descarga(s) : 0
  • Publicado : 19 de enero de 2012
Leer documento completo
Vista previa del texto
Essentials of the Java Programming Language
A Hands-On Guide

by Monica Pawlan

copyright ® 1995-99 Sun Microsystems, Inc.
As used in this document, the terms “Java™ virtual machine” or “Java VM” mean a virtual machine for the Java platform.

i

Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix Acknowledgementsx 1: Compiling and Running a Simple Program . . . . . . . . . . . . . . . . . . . 1 Covered in This Lesson 1 A Word About the Java Platform 2 Setting Up Your Computer 3 Writing a Program 3 Compiling the Program 3 Interpreting and Running the Program 4 Code Comments 5 Double Slashes 5 C-Style Comments 5 Doc Comments 5 API Documentation 6 Setting the CLASSPATH Environment Variable on a Windowsplatform 6 Exercises 6 More Information 7 2: Building Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Covered in This Lesson 9 Application Structure and Elements 9 Fields and Methods 12 Constructors 14 To Summarize 16 Exercises 16 More Information 16 3: Building Applets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Coveredin This Lesson 17 Application to Applet 18 Run the Applet 19 Applet Structure and Elements 19 Extending a Class 20 Behavior 21 Appearance 22 Packages 23

ii Exercises 24 More Information 24 4: Building a User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Covered in This Lesson 25 Project Swing APIs 26 Import Statements 27 Class Declaration 28 Instance Variables29 Constructor 29 Action Listening 31 Event Handling 31 Main Method 32 Exercises: Applets Revisited 33 Summary 34 More Information 35 5: Building Servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Covered in This Lesson 37 About the Example 38 HTML Form 39 Servlet Code 40 Class and Method Declarations 41 Method Implementation 42 JavaServer Pages Technology43 HTML Form 43 JSP Page 44 Exercises 45 More Information 45 6: File Access and Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Covered in This Lesson 47 File Access by Applications 48 Constructor and Instance Variable Changes 48 Method Changes 49 System Properties 51 File.separatorChar 52 Exception Handling 52 File Access by Applets 54 Granting Applets Permission 56Restricting Applications 57 File Access by Servlets 57 Exercises 59 More Information 59

iii Code for This Lesson 60 FileIO Program 60 FileIOAppl Program 62 FileIOServlet Program 64 AppendIO Program 65 7: Database Access and Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Covered in This Lesson 69 Database Setup 70 Create Database Table 70 Database Access by Applications 70Establishing a Database Connection 71 Final and Private Variables 72 Writing and Reading Data 73 Database Access by Applets 74 JDBC Driver 74 JDBC-ODBC Bridge with ODBC Driver 76 Database Access by Servlets 78 Exercises 78 More Information 79 Code for This Lesson 79 Dba Program 79 DbaAppl Program 81 DbaOdbAppl Program 83 DbaServlet Program 85 8: Remote Method Invocation. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . 87 Covered in This Lesson 88 About the Example 88 Program Behavior 88 File Summary 90 Compile the Example 91 Start the RMI Registry 93 Start the Server 93 Run the RMIClient1 Program 94 Run the RMIClient2 Program 95 RemoteServer Class 96 Send Interface 97 RMIClient1 Class 97 actionPerformed Method 97 main Method 98 RMIClient2 Class 98 actionPerformed Method 98 mainMethod 99 Exercises 99

iv More Information 100 Code for This Lesson 100 RMIClient1 Program 100 RMIClient2 Program 101 RemoteServer Program 103 Send Interface 103 9: Socket Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Covered in This Lesson 105 What are Sockets and Threads? 106 About the Examples 106 Example 1: Client-Side Behavior 107 Example 1:...
tracking img