Java Programming Language Additional Material SL-275-SE6 Rev G D61750GC10 Edition 1.0 D62603
Copyright 2007, 2009, Oracle and/or its affiliates. All rights reserved. Disclaimer This document contains proprietary information, is provided under a license agreement containing restrictions on use and disclosure, and is protected by copyright and other intellectual property laws. You may copy and print this document solely for your own use in an Oracle training course. The document may not be modified or altered in any way. Except as expressly permitted in your license agreement or allowed by law, you may not use, share, download, upload, copy, print, display, perform, reproduce, publish, license, post, transmit, or distribute this document in whole or in part without the express authorization of Oracle. The information contained in this document is subject to change without notice. If you find any problems in the document, please report them in writing to: Oracle University, 500 Oracle Parkway, Redwood Shores, California 94065 USA. This document is not warranted to be error-free. Sun Microsystems, Inc. Disclaimer This training manual may include references to materials, offerings, or products that were previously offered by Sun Microsystems, Inc. Certain materials, offerings, services, or products may no longer be offered or provided.oracle and its affiliates cannot be held responsible for any such references should they appear in the text provided. Restricted Rights Notice If this documentation is delivered to the U.S. Government or anyone using the documentation on behalf of the U.S. Government, the following notice is applicable: U.S. GOVERNMENT RIGHTS The U.S. Government s rights to use, modify, reproduce, release, perform, display, or disclose these training materials are restricted by the terms of the applicable Oracle license agreement and/or the applicable U.S. Government contract. Trademark Notice Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. AMD, Opteron, the AMD logo, and the AMD Opteron logo are trademarks or registered trademarks of Advanced Micro Devices. Intel and Intel Xeon are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. UNIX is a registered trademark licensed through X/Open Company, Ltd.
This page intentionally left blank.
This page intentionally left blank.
Table of Contents About This Book...Preface-xi Goals... Preface-xi Book Map...Preface-xii Typographical Conventions...Preface-xiii Additional Conventions...Preface-xiv The NetBeans IDE 5.5...1-1 Objectives... 1-1 The Netbeans IDE 5.5 Release... 1-2 Downloading the NetBeans IDE... 1-2 NetBeans IDE Resources... 1-2 Help System... 1-3 Launching the NetBeans IDE... 1-4 Shutting Down the NetBeans IDE... 1-5 Increasing the Font Size of the IDE... 1-5 Using the Update Center of the IDE... 1-5 Java Development...2-1 Objectives... 2-1 Java Application Projects... 2-2 Project Types... 2-2 Creating Projects... 2-2 Opening Projects... 2-3 Building Projects... 2-3 Cleaning Projects... 2-4 Running Projects... 2-4 Main Project... 2-5 Project Source Folders... 2-5 Modifying Project Libraries... 2-6 Closing a Project... 2-7 Deleting a Project... 2-7 Adding Ant Targets to a Project... 2-7 Executing Customized Ant Targets... 2-8 Setting the Main Class... 2-8 v
Setting Arguments... 2-9 Setting the Virtual Machine Options... 2-10 Java Packages... 2-11 Creating Java Packages... 2-11 Modifying Java Packages... 2-11 Renaming Packages... 2-11 Deleting Packages... 2-12 Compiling Java Packages... 2-12 Java Classes... 2-13 Java Class Types... 2-13 JUnit Test Classes... 2-14 Empty Test... 2-14 Creating Java Classes... 2-14 Opening Java Classes... 2-15 Modifying Java Classes... 2-15 Adding Fields... 2-15 Adding Properties... 2-16 Renaming Fields... 2-18 Encapsulating Fields... 2-19 Removing Fields... 2-20 Adding Methods... 2-21 Refactoring Methods... 2-21 Removing Methods... 2-21 Overriding Methods... 2-22 Adding Constructors... 2-22 Adding Static Initializers... 2-23 Calling an Enterprise Bean... 2-23 Adding Database Lookup Code to a Java Class File... 2-23 Sending a JMS Message to a Message-Driven Bean... 2-24 Compiling Java Classes... 2-24 Executing Java Programs... 2-24 Main Classes... 2-25 JUnit Test Classes... 2-25 Copying Java Classes... 2-25 Moving Java Classes... 2-26 Copying Existing Resources... 2-27 Terminating a Running Process... 2-28 XML Files... 2-29 Creating XML Files... 2-29 Opening XML Files... 2-29 Checking and Validating XML Files... 2-30 Other Files... 2-31 File Types... 2-31 Creating New Files... 2-31 Opening Files... 2-31 Creating Folders... 2-32 vi The Netbeans IDE Tool Reference
Deleting Files... 2-32 Copying Files and Folders... 2-32 Moving Files and Folders... 2-32 Java EE Development...3-1 Objectives... 3-1 Enterprise Application Projects... 3-2 Creating Enterprise Application Projects... 3-2 Configuring Deployment Descriptors... 3-3 Editing the Standard Application Deployment Descriptor... 3-3 Editing the SJSAS-Specific Application Deployment Descriptor... 3-4 Adding Build Packages... 3-4 Building Java EE Applications... 3-5 Verifying Java EE Applications... 3-5 Deploying Java EE Applications... 3-6 Undeploying Java EE Applications... 3-6 Configuring Java EE Resources... 3-7 Configuring Connection Pools... 3-7 Creating a Connection Pool Resource... 3-7 Registering a Connection Pool Resource... 3-8 Configuring JDBC Resources... 3-8 Creating a JDBC Resource... 3-9 Registering a JDBC Resource... 3-9 Configuring JMS Resources... 3-10 Creating a JMS Resource... 3-10 Registering a JMS Resource with the Sun Java System Application Server... 3-10 Deleting a JMS Resource from the EJB Module... 3-11 Removing a JMS Resource From the Sun Java System Application Server... 3-11 Web Modules... 3-12 Web Application Projects... 3-12 Creating a Web Application Project... 3-12 Servlets... 3-14 Creating Servlets... 3-14 Deleting Servlets... 3-15 Creating JavaServer Pages... 3-16 Editing JSP Pages... 3-17 HTML Files... 3-17 Web Application Listeners... 3-18 Creating Listener Classes... 3-18 Deleting Listener Classes... 3-19 Filter Classes... 3-19 Creating Filters... 3-19 vii
Deleting Filters... 3-20 Web Application Frameworks... 3-20 Adding Frameworks... 3-20 Struts Action Classes... 3-23 Creating Struts Action Classes... 3-23 Deleting Struts Action Classes... 3-24 Struts ActionForm Beans... 3-25 Creating Struts ActionForm Beans... 3-25 Deleting Struts ActionForm Beans... 3-26 Web Deployment Descriptors... 3-26 Opening the Standard Deployment Descriptor... 3-26 General Configuration... 3-27 Servlet Configuration... 3-28 Filter Configuration... 3-31 Page Configuration... 3-33 Reference Configuration... 3-35 Security Configuration... 3-36 XML Editor... 3-38 Sun Java System Application Server Web Deployment Descriptor... 3-38 Opening the Sun Java System Application Server Web Deployment Descriptor... 3-39 EJB Modules... 3-41 Creating EJB Modules... 3-41 Session Beans... 3-42 Creating Session Beans... 3-42 Adding Business Methods... 3-42 Removing Methods... 3-44 Entity Classes... 3-44 Creating Persistence Units... 3-44 Creating Entity Classes... 3-45 Creating Entity Classes From a Database... 3-46 Message-Driven Beans... 3-47 Configuring EJB Deployment Descriptors... 3-48 Creating the Standard EJB Deployment Descriptor... 3-48 Opening the Standard EJB Deployment Descriptor... 3-48 The XML Editor... 3-49 The Sun EJB Deployment Descriptor... 3-49 Web Services... 3-50 Creating an Empty Web Service... 3-50 Creating a Web Service From a WSDL File... 3-51 Adding Operations to a Web Service... 3-52 Refreshing Web Services... 3-52 Editing Web Service Attributes... 3-52 Testing Web Services... 3-53 Creating WSDL Files... 3-53 viii The Netbeans IDE Tool Reference
Creating Web Service Clients... 3-54 Calling a Web Service Operation... 3-55 Refreshing Web Services and Clients... 3-55 Message Handlers... 3-55 Creating Message Handlers... 3-55 Configuring Message Handlers... 3-56 Deployment Descriptor Settings... 3-56 Server Resources...4-1 Objectives... 4-1 Java EE Application Servers... 4-2 Registering Application Servers... 4-2 Starting the Application Servers... 4-3 Examining Application Servers... 4-3 Configuring Application Servers... 4-4 ORB Settings... 4-4 Stopping Application Servers... 4-5 Examining Server Log Files... 4-5 Classpath Settings... 4-5 Adding JVM Machine Options... 4-6 Modifying SOAP Message Security Settings... 4-6 Administering Security... 4-7 Adding a File Realm User... 4-7 Administering the Java Message Service... 4-7 Creating Physical Destinations... 4-7 Deploying to a Server... 4-7 Deploying WAR Files... 4-8 Deploying EJB JAR Files... 4-8 Deploying EAR Files... 4-8 Databases... 4-9 Starting the Java DB Database... 4-9 Creating a Java DB Database... 4-9 Modifying the Java DB Database Location... 4-10 Stopping the Java DB Database... 4-10 Adding JDBC Drivers... 4-10 Connecting to Databases... 4-11 Interacting with Databases... 4-11 Executing SQL Queries... 4-12 Capturing Database Schemas... 4-12 NetBeans 5.5 Keyboard Shortcuts... A-1 Keyboard Shortcuts... A-2 ix
Java EE Annotation Reference...B-1 Resource Annotations...B-2 EJB Annotations...B-3 Bean-Type Annotations...B-3 Transaction and Security Annotations...B-3 Callback Annotations...B-4 Interceptor Annotations...B-4 x The Netbeans IDE Tool Reference