OracleAS 10g R3: Java Programming

Similar documents
Oracle 10g: Java Programming

E Oracle 10g Java Bootcamp I v1

Fundamentals of the Java Programming Language

Java Programming Language

Oracle WebCenter Content 11g: Content Server Customization Student Guide - Volume I

Oracle 11g: XML Fundamentals

Oracle BPM 10g R3 Programming 1 Essentials

Oracle Forms Developer 10g: Move to the Web

Oracle Warehouse Builder 10g: New Features

OracleAS 10g R3: Build J2EE Applications II

Using Java - for PL/SQL and Database Developers Student Guide

Oracle Database 10g: Using OLAP

"Charting the Course... Java Programming Language. Course Summary

Oracle Database 10g: SQL Fundamentals I

MySQL Performance Tuning

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Oracle Database 11g: SQL Fundamentals I

This page intentionally left blank

Oracle Hyperion Data Relationship Management Administration Activity Guide

Business Component Development with EJB Technology, Java EE 5

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

Oracle Database 10g: PL/SQL Fundamentals

Java EE Patterns. Student Guide - Volume 1. SL-500 Rev C.0.1. D61856GC10 Edition 1.0 D62465

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

Oracle Data Integrator: Administration and Development Volume I Student Guide

Oracle Database 10g: PL/SQL Fundamentals

Oracle Warehouse Builder 10g: Administration

Oracle Warehouse Builder 10g: Implementation Part 2

Oracle Application Server 10g R2: Administration II

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

Oracle Data Integrator 11g: Advanced Integration and Development Student Guide

Oracle BI 11g R1: Build Repositories

Murach s Beginning Java with Eclipse

Oracle WebCenter Sites 11g for Developers

Oracle Application Express: Administration Student Guide

E Oracle 10g Java Bootcamp II v1

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

1 OBJECT-ORIENTED PROGRAMMING 1

Course Description. Learn To: : Intro to JAVA SE7 and Programming using JAVA SE7. Course Outline ::

Oracle Data Integrator 11g: Integration and Administration Student Guide - Volume I

Oracle BI Publisher 10g R3: Fundamentals

Core Java SYLLABUS COVERAGE SYLLABUS IN DETAILS

Oracle Application Server 10g R3: Administration

WA1278 Introduction to Java Using Eclipse

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Oracle BI Publisher 11g R1: Fundamentals

Oracle Database 10g: Data Guard Administration

Oracle Data Modeling and Relational Database Design Volume I Student Guide

Oracle VM Administration: Oracle VM Server for x86 Student Guide

Oracle Database 11g: SQL Tuning Workshop. Student Guide

Oracle WebLogic Server 12c: JMS Administration Student Guide

Siebel 8.1.x Fundamentals Student Guide

MyProgram m i ng Lab. get with the programming. Through the power of practice and immediate personalized

Contents. iii Copyright 1998 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1998, Revision B

Java Programming. Price $ (inc GST)

Oracle GoldenGate 11g: Advanced Configuration for Oracle Student Guide

Oracle Database 10g: New Features for Release 2 Overview Seminar

Introduction to Programming Using Java (98-388)

Oracle Service Bus 10g R3: Design & Integrate Services for SOA

Oracle Adaptive Access Manager: Administration Student Guide

Microsoft. Microsoft Visual C# Step by Step. John Sharp

Java Programming Course Overview. Duration: 35 hours. Price: $900

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

UNIX and Linux Essentials Student Guide

Oracle Communication and Mobility Server: Introduction Student Guide

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Oracle Database 10g: Implement and Administer a Data Warehouse

FOR BEGINNERS 3 MONTHS

Java SE 7 Programming Volume I Student Guide

SYLLABUS JAVA COURSE DETAILS. DURATION: 60 Hours. With Live Hands-on Sessions J P I N F O T E C H

Oracle Application Testing Suite: Introduction Student Guide

Java Training JAVA. Introduction of Java

Java 8 Programming for OO Experienced Developers

LTBP INDUSTRIAL TRAINING INSTITUTE

Java SE 7 Programming

Oracle VM Server for x86: Administration

[Course Overview] After completing this module you are ready to: Develop Desktop applications, Networking & Multi-threaded programs in java.

JOSE LUIS JUAREZ VIVEROS com) has a. non-transferable license to use this Student Guide

Week. Lecture Topic day (including assignment/test) 1 st 1 st Introduction to Module 1 st. Practical

Java Programming Training for Experienced Programmers (5 Days)

Java Programming with Eclipse

Analytics: Server Architect (Siebel 7.7)

Java SE 7 Programming

JAVA. Duration: 2 Months

Core Java Contents. Duration: 25 Hours (1 Month)

Java SE7 Fundamentals

Shell Programming for System Administrators Student Guide

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

Object-Oriented Analysis and Design Using UML

Oracle Content Server 11g: Administration

Oracle GoldenGate 11g: Fundamentals for SQL Server Student Guide

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

Java SE 8 Programming

Oracle TimesTen 6.0: Core Concepts and Administration Volume I - Student Guide

Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3. Course Code: GK1965. Overview

5/23/2015. Core Java Syllabus. VikRam ShaRma

Oracle Identity Manager 11g: Essentials

Java 1.8 Programming

Transcription:

OracleAS 10g R3: Java Programming Volume I Student Guide D18382GC20 Edition 2.0 April 2007 D50171

Authors Patrice Daux Kate Heap Technical Contributors and Reviewers Ken Cooper C Fuller Vasily Strelnikov Ronald Treep Editor Richard Wallis Graphic Designer Rajiv Chandrabhanu Publishers Srividya Rameshkumar Veena Narasimhan Copyright 2007, Oracle. All rights reserved. Disclaimer This document contains proprietary information 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 where your use constitutes "fair use" under copyright 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. Restricted Rights Notice If this documentation is delivered to the United States Government or anyone using the documentation on behalf of the United States 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, JD Edwards, PeopleSoft, and Siebel are registered trademarks of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Contents Preface I Introduction Objectives I-2 Course Overview I-3 1 Introducing the Java and Oracle Platforms Objectives 1-2 What Is Java? 1-3 Key Benefits of Java 1-5 Object-Oriented Approach 1-7 Platform Independence 1-8 Using Java with Enterprise Internet Computing 1-9 Using the Java Virtual Machine 1-11 How Does the JVM Work? 1-13 Benefits of Just-In-Time (JIT) Compilers 1-15 Implementing Security in the Java Environment 1-17 Deployment of Java Applications 1-19 Using Java with Oracle 10g 1-20 Java Software Development Kit 1-21 Using the Appropriate Development Kit 1-22 Integrated Development Environment 1-23 Exploring the JDeveloper Environment 1-24 Oracle10g Products 1-26 Summary 1-27 2 Defining Object-Oriented Principles Objectives 2-2 Modeling 2-4 Classes and Objects 2-5 An Object s Attributes Maintain Its State 2-6 Objects Have Behavior 2-8 Objects Are Modeled As Abstractions 2-9 Defining Object Aggregation: Composition 2-11 Donut Diagram 2-13 Guided Practice: Spot the Operations and Attributes 2-14 iii

Collaborating Objects 2-15 Objects Interact Through Messages 2-17 Classes 2-19 Identifying a Class 2-21 Comparing Classes and Objects 2-22 Encapsulation 2-24 Inheritance 2-25 Using the Is-a-Kind-of Relationship 2-26 Polymorphism 2-27 UML Diagram for OrderEntry 2-29 Summary 2-30 Practice 2 Overview: Working with Object-Oriented Principles 2-31 Order Entry System: Partial UML Class Model 2-34 3 Basic Java Syntax and Coding Conventions Objectives 3-2 Toolkit Components 3-4 Java Packages 3-5 Documenting Using Java SE 3-6 Annotations 3-7 Contents of a Java Source File 3-8 Naming Conventions 3-9 More About Naming Conventions 3-11 Defining a Class 3-13 Rental Class: Example 3-14 Creating Code Blocks 3-16 Defining Java Methods 3-17 Example of a Method 3-18 Declaring Variables 3-19 Examples of Variables in the Context of a Method 3-20 Rules for Creating Statements 3-21 Compiling and Running a Java Application 3-22 CLASSPATH Variable 3-23 Classpath Use Examples 3-24 Summary 3-25 Practice 3: Overview 3-26 4 Exploring Primitive Data Types and Operators Objectives 4-2 Keywords and Reserved Words 4-4 iv

Variable Types 4-5 Primitive Data Types 4-7 Variables 4-9 Declaring Variables 4-10 Local Variables 4-11 Defining Variable Names 4-12 Numeric Literals 4-13 Nonnumeric Literals 4-15 enum 4-17 Operators 4-18 Categories of Operators 4-19 Using the Assignment Operator 4-20 Working with Arithmetic Operators 4-21 More About Arithmetic Operators 4-22 Guided Practice: Declaring Variables 4-23 Examining Conversions and Casts 4-25 Incrementing and Decrementing Values 4-27 Relational and Equality Operators 4-28 Conditional Operator (?:) 4-29 Logical Operators 4-30 Compound Assignment Operators 4-31 Operator Precedence 4-32 More About Operator Precedence 4-33 Concatenating Strings 4-34 Summary 4-35 Practice 4 Overview: Exploring Primitive Data Types and Operators 4-36 5 Controlling Program Flow Objectives 5-2 Basic Flow Control Types 5-3 Using Flow Control in Java 5-4 if Statement 5-5 Nested if Statements 5-6 Guided Practice: Spot the Mistakes 5-7 switch Statement 5-8 More About the switch Statement 5-10 Looping in Java 5-11 while Loop 5-13 do while Loop 5-14 for Loop 5-15 v

More About the for Loop 5-16 Guided Practice: Spot the Mistakes 5-17 break Statement 5-18 continue Statement 5-19 Summary 5-20 Practice 5 Overview: Controlling Program Flow 5-21 6 Building Applications with Oracle JDeveloper (10.1.3.2.0) Objectives 6-2 Oracle JDeveloper (10.1.3.2.0) 6-3 Oracle JDeveloper (10.1.3.2.0) Environment 6-4 Applications 6-6 Projects 6-8 Creating JDeveloper Items 6-10 Creating an Application 6-11 Project Properties: Specifying Project Details 6-13 Project Properties: Selecting Additional Libraries 6-14 Adding a New Java SE 6-15 Directory Structure 6-16 Exploring the Skeleton Java Application 6-17 Finding Methods and Fields 6-18 Supporting Code Development with Profiler and Code Coach 6-19 New Code Editor Features 6-21 Customizing JDeveloper (10.1.3.2.0) 6-23 Refactoring 6-24 JDeveloper Help System 6-27 Obtaining Help on a Topic 6-28 Oracle JDeveloper Debugger 6-29 Breakpoints 6-31 Debugger Windows 6-33 Stepping Through a Program 6-34 Watching Data and Variables 6-35 Summary 6-36 Practice 6 Overview: Building Java with Oracle JDeveloper 6-37 7 Creating Classes and Objects Objectives 7-2 Java Classes 7-3 Comparing Classes and Objects 7-4 Creating Objects 7-5 vi

new Operator 7-6 Primitive Variables and Object Variables 7-7 null Reference 7-8 Assigning References 7-9 Declaring Instance Variables 7-10 Accessing public Instance Variables 7-11 Defining Methods 7-12 Calling a Method 7-14 Specifying Method Arguments: Examples 7-15 Returning a Value from a Method 7-17 Calling Instance Methods 7-18 Encapsulation in Java 7-19 Passing Primitives to Methods 7-20 Passing Object References to Methods 7-21 Class Variables 7-22 Initializing Class Variables 7-23 Class Methods 7-25 Guided Practice: Class Methods or Instance Methods 7-26 Examples in Java 7-27 Java Packages 7-28 Grouping Classes in a Package 7-29 Setting the CLASSPATH with Packages 7-30 Access Modifiers 7-32 Summary 7-34 Practice 7 Overview: Creating Classes and Objects 7-35 8 Object Life Cycle and Inner Classes Objectives 8-2 Overloading Methods 8-4 Using the this Reference 8-6 Initializing Instance Variables 8-7 Constructors 8-8 Defining and Overloading Constructors 8-10 Sharing Code Between Constructors 8-11 final Variables, Methods, and Classes 8-12 Reclaiming Memory 8-13 finalize() Method 8-14 Inner Classes 8-16 Static Inner Class 8-17 Member Inner Class 8-18 vii

Local Inner Class 8-19 Anonymous Inner Class 8-20 Calendar Class 8-22 Summary 8-24 Practice 8 Overview: Object Life Cycle Classes 8-25 9 Using Strings and the StringBuffer, Wrapper, and Text-Formatting Classes Objectives 9-2 Strings in Java 9-3 Creating Strings 9-4 Concatenating Strings 9-5 Performing Operations on Strings 9-6 Performing More Operations on Strings 9-7 Comparing String Objects 9-8 Producing Strings from Other Objects 9-10 Producing Strings from Primitives 9-11 Producing Primitives from Strings 9-12 Wrapper Class Conversion Methods 9-13 Changing the Contents of a String 9-14 Formatting Classes 9-16 SimpleDateFormat Class 9-17 MessageFormat Class 9-18 DecimalFormat Subclass 9-19 Guided Practice 9-20 Regular Expressions 9-22 Streams 9-25 Sets of I/O Classes 9-26 Byte I/O Streams 9-27 Character I/O Streams 9-28 The Basics: Standard Output 9-29 OutputStream and PrintStream 9-30 Formatted Output 9-31 The Basics: Standard Input 9-32 Scanner API 9-34 Object Serialization 9-35 Serialization Streams, Interfaces, and Modifiers 9-38 Summary 9-39 Practice 9 Overview: Using Strings and the StringBuffer, Wrapper, and Text-Formatting Classes 9-40 viii

10 Reusing Code Objectives 10-2 Key Object-Oriented Components 10-3 Example of Inheritance 10-5 Specifying Inheritance in Java 10-7 Defining Inheritance with Oracle JDeveloper 10-9 Subclass and Superclass Variables 10-10 Default Initialization 10-11 Super() Reference 10-12 Super() Reference: Example 10-13 Using Superclass Constructors 10-14 Specifying Additional Methods 10-16 Overriding Superclass Methods 10-18 Invoking Superclass Methods 10-20 Example of Polymorphism in Java 10-21 Treating a Subclass As Its Superclass 10-22 Browsing Superclass References with Oracle JDeveloper 10-24 Hierarchy Browser 10-25 Acme Video and Polymorphism 10-26 Using Polymorphism for Acme Video 10-27 instanceof Operator 10-29 Limiting Methods and Classes with final 10-31 Ensuring Genuine Inheritance 10-33 Practice 10 Overview: Reusing Code with Inheritance and Polymorphism 10-34 JavaBeans 10-41 More About JavaBeans 10-42 Managing Bean Properties 10-43 Exposing Properties and Methods 10-44 JavaBeans at Design Time 10-45 Introspection with JavaBeans 10-46 JavaBeans at Run Time 10-47 Build and Use a JavaBean in JDeveloper 10-48 Summary 10-49 11 Arrays and Collections Objectives 11-2 Arrays 11-3 Creating an Array of Primitives 11-4 Declaring an Array 11-5 Creating an Array Object 11-6 ix

Initializing Array Elements 11-8 Creating an Array of Object References 11-9 Initializing the Objects in an Array 11-10 Using an Array of Object References 11-12 Going Through the Array Elements 11-13 Arrays and Exceptions 11-14 Multidimensional Arrays 11-15 Passing Command-Line Parameters to main() 11-16 Java Collections Framework 11-18 Collections Framework Components 11-20 ArrayList 11-21 Modifying an ArrayList 11-22 Accessing an ArrayList 11-23 Hashtable Class 11-24 Iterator Interface 11-25 Enhancements in Java SE 5.0 11-27 Summary 11-29 Practice 11 Overview: Using Arrays and Collections 11-30 12 Structuring Code by Using Abstract Classes and Interfaces Objectives 12-2 Abstract Classes 12-3 Creating Abstract Classes 12-5 Abstract Methods 12-6 Defining Abstract Methods 12-8 Defining and Using Interfaces 12-9 Examples of Interfaces 12-10 Creating Interfaces 12-11 Implementing Interfaces 12-13 Sort: A Real-World Example 12-14 Overview of the Classes 12-15 How the Sort Works 12-17 Sortable Interface 12-18 Sort Class 12-19 Movie Class 12-20 Using the Sort 12-21 Using instanceof with Interfaces 12-22 Summary 12-23 Practice 12: Overview 12-24 x

13 Throwing and Catching Exceptions Objectives 13-2 What Is an Exception? 13-3 Exception Handling in Java 13-4 Advantages of Java Exceptions: Separating Error-Handling Code 13-5 Advantages of Java Exceptions: Passing Errors Up the Call Stack 13-7 Advantages of Java Exceptions: Exceptions Cannot Be Ignored 13-8 Checked Exceptions, Unchecked Exceptions, and Errors 13-9 Handling Exceptions 13-11 Catching and Handling Exceptions 13-12 Catching a Single Exception 13-14 Catching Multiple Exceptions 13-15 Cleaning Up with a finally Block 13-16 Guided Practice: Catching and Handling Exceptions 13-17 Guided Practice: Catching and Handling Exceptions 13-18 Allowing an Exception to Pass to the Calling Method 13-19 Throwing Exceptions 13-20 Creating Exceptions 13-21 Catching an Exception and Throwing a Different Exception 13-22 Summary 13-23 Practice 13 Overview: Throwing and Catching Exceptions 13-24 14 Using JDBC to Access the Database Objectives 14-2 Java, Java EE, and Oracle 10g 14-3 Connecting to a Database with Java 14-4 Java Database Connectivity (JDBC) 14-5 Preparing the Environment 14-6 Steps for Using JDBC to Execute SQL Statements 14-7 Step 1: Registering the Driver 14-8 Connecting to the Database 14-9 Oracle JDBC Drivers: Thin-Client Driver 14-10 Oracle JDBC Drivers: OCI Client Driver 14-11 Choosing the Right Driver 14-13 Step 2: Obtaining a Database Connection 14-14 JDBC URLs 14-15 JDBC URLs with Oracle Drivers 14-16 Step 3: Creating a Statement 14-17 Using the Statement Interface 14-18 Step 4a: Executing a Query 14-19 xi

ResultSet Object 14-20 Step 4b: Submitting DML Statements 14-21 Step 4b: Submitting DDL Statements 14-22 Step 5: Processing the Query Results 14-23 Mapping Database Types to Java Types 14-24 Step 6: Cleaning Up 14-26 Basic Query Example 14-27 Handling an Unknown SQL Statement 14-28 Handling Exceptions 14-29 Transactions with JDBC 14-30 PreparedStatement Object 14-32 Creating a PreparedStatement Object 14-33 Executing a PreparedStatement Object 14-34 Maximizing Database Access with Connection Pooling 14-35 Connection Pooling 14-36 Summary 14-39 Practice 14 Overview: Using JDBC to Access the Database 14-40 15 User Interface Design: Swing Basics for Planning the Application Layout Objectives 15-2 AWT, Swing, and JFC 15-3 Swing Features 15-5 Lightweight and Heavyweight Components 15-7 Planning the UI Layout 15-8 Swing Containment Hierarchy 15-9 Top-Level Containers 15-11 Intermediate Containers 15-13 Atomic Components 15-15 Layout Management: Overview 15-16 Border Layout 15-18 GridBag Layout 15-19 GridBag Constraints 15-20 Using Layout Managers 15-22 Combining Layout Managers 15-24 Java Frame Classes 15-25 JPanel Containers 15-27 Internal Frames 15-29 Adding Components with Oracle JDeveloper 15-31 Creating a Frame 15-32 Adding Components 15-33 xii

Pluggable Look and Feel 15-35 Summary 15-37 Practice 15: Overview 15-38 16 Adding User Interface Components and Event Handling Objectives 16-2 Swing Components 16-3 Swing Components in JDeveloper 16-5 Invoking the UI Editor 16-7 Adding a Component to a Form 16-8 Editing the Properties of a Component 16-9 Code Generated by JDeveloper 16-10 Creating a Menu 16-12 Using the JDeveloper Menu Editor 16-13 Practice 16-1 Overview: Adding User Interface Components 16-14 UI for the Order Entry Application 16-15 Java Event Handling Model 16-21 Event Handling Code Basics 16-22 Event-Handling Process: Registration 16-23 Event-Handling Process: The Event Occurs 16-25 Event-Handling Process: Running the Event Handler 16-26 Using Adapter Classes for Listeners 16-27 Swing Model-View-Controller Architecture 16-28 Basic Text Component Methods 16-31 Basic JList Component Methods 16-32 What Events Can a Component Generate? 16-33 How to Define an Event Handler in JDeveloper 16-34 Default Event Handling Code Style Generated by JDeveloper 16-35 Completing the Event Handler Method 16-36 Summary 16-37 Practice 16-2 Overview: Adding Event Handling 16-38 17 Deploying Applications by Using Java Web Start Objectives 17-2 Java Web Start 17-3 Running a Web Start Application 17-4 Advantages of Web Start 17-5 Examining the JNLP File 17-6 Deploying Applications with JDeveloper 17-7 Creating the Deployment Profile File 17-8 Saving the Deployment Profile 17-9 xiii

Selecting Files to Deploy 17-10 Creating an Executable.jar File 17-11 Creating and Deploying the Archive File 17-12 Using JDeveloper to Deploy an Application for Java Web Start 17-13 Step 1: Generate Deployment Profiles and Archive Application 17-14 Step 2a: Start OC4J 17-15 Step 2b: Creating a Connection 17-16 Step 3: Use the Web Start Wizard to Create a JNLP File 17-17 Step 4: Archive and Deploy the Application to the OC4J Server 17-18 Summary 17-19 Appendix A: Practice Solutions Appendix B: Java Language Quick-Reference Guide Appendix C: Practice Solutions: Order Entry Application xiv