Chapter 12: Java in the Oracle Database

Overview

Java, both a programming language and a platform developed by Sun Microsystems Inc., is a powerful tool for creating applications and application components at every level of a distributed architecture. Sun designed Java to be simple to learn, architecture neutral, object oriented, robust, secure, and multithreaded. Because Java is well suited for distributed application development, and has gained wide acceptance by the developer community, Oracle has made a strategic commitment to Java in the database, application server, and integrated development environments.

With a typical programming language, developers either compile a source program into native machine code, or execute the source program using an interpreter. With native machine code, a compiled program runs as fast as possible on the target platform, but it will not run on other platforms. Conversely, an interpreted program requires the overhead of an interpreter to run the program upon each invocation, and consequently runs slower than a binary executable. However, the interpreted program is portable to other platforms that support the interpreter. Java provides write once, run anywhere platform independence coupled with high performance because it is both compiled and interpreted.

The Java compiler reads source program instructions and creates a platform-independent program of Java bytecodes called a class file. The Java Virtual Machine (JVM) on the target platform interprets the class files at run time. Because of the overhead of the JVM, the performance of executing Java class files is inherently slower than the speed of executing native machine code. Early JVM implementations were very slow, but fortunately, vendors today design their JVM implementations for high performance. The benefits of platform-independence and increased security gained with Java outweigh the additional run-time cost.

Java packages consist of a group of related Java classes, which is similar to a schema in the Oracle database. Classes in Java are similar to packages in the database. Methods are similar to program units ”i.e., procedures and functions in PL/SQL. The JVM includes many packaged classes, including the core language classes (in the java.lang package), the input/output classes (in the java.io package), relational database access classes (in the java.sql package), and so forth. Java platforms are differentiated by which packages are included in the platform.

One of the earliest uses of Java was to run programs and animated graphics within static web pages using applets. Because the client browser downloads the applet from the web server, and early implementations of the JVM were less efficient resulting in long interpretation times, Java earned a reputation of being slow. Today, most Java development is on the application and database tiers. In addition, significant improvements in JVM performance have enabled Java to prove itself as a capable language and platform for mission-critical application development. Application-tier Java uses include Enterprise JavaBeans (EJBs), servlets, JavaServer Pages (JSPs), and the SQL for Java (SQLJ) precompiler. The database tier allows the use of Java to develop stored procedures as an alternative to Procedural Language extension to Structured Query Language (PL/SQL). Because this book focuses on server-side development, this chapter only describes the use of Java in the application and database tiers.

This chapter does not teach you how to program in Java, as there are a multitude of books and tutorials dedicated to the various ways developers can write Java applications and application components. Rather, this chapter describes how to employ Java to develop server-side applications using the Oracle database and application server.

Because this book teaches Oracle web development and is aimed primarily at developers, it is assumed that most readers are Oracle developers and are already knowledgeable in programming PL/SQL. For PL/SQL programmers who are new to Java, this chapter starts with a section describing the basics of Java, and includes a comparison of the syntax and features of PL/SQL to Java. Programmers already comfortable with programming in Java can skip the introduction, or review the section to reinforce their knowledge.

Specifically, this chapter covers the following topics:

  • Getting started with Java

  • Java for the PL/SQL Developer

  • Oracle s Java Virtual Machine (JVM)

  • Java Database Connectivity (JDBC)

  • SQLJ

  • Java Stored Procedures

  • DBMS_JAVA package

  • Oracle Business Components for Java (OC4J): servlets, JavaServer Pages (JSPs), and Enterprise JavaBeans (EJBs)

There are many aspects of the Java programming language and entire books (often 1,000+ pages in length) have been written about them. While it is impossible to devote space to all of these technologies, we have made every effort to discuss what we feel are the most prevalent topics related to Oracle-based Java application development. This chapter discusses the fundamentals of the Java language. Chapter 14, is a listing of resources you can use to enhance your Java knowledge.



Oracle Application Server 10g Web Development
Oracle Application Server 10g Web Development (Oracle Press)
ISBN: 0072255110
EAN: 2147483647
Year: 2004
Pages: 192

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net