Database Reference
In-Depth Information
we were using lots of classes from the oracle.sql package , we could import them all with the shorthand
statement import oracle.sql.* . Because MyRef is in the same package as MyApp , we do not need to
import MyRef , even though we do refer to it in MyApp .
Also notice that, inside the class definition (between the curly brackets) of MyApp , we have declared
two member classes: one instance (copy) of ARRAY that we will refer to as myArray , and one instance of
MyRef , which we will refer to as myRef . Notice that Java is case sensitive: compare myRef with MyRef .
I will be using the terms member and instance frequently. Briefly, in object-oriented parlance, an
object that is created in computer memory is an instance of whatever kind of class it is; we call the
creation of objects instantiation. The object that is created by another object and referenced therein is
called a member of the object that created it.
Byte Code Compilation and the Java Virtual Machine
I have already used the word compile, and you will see it a lot in this topic. In Java, you will write human-
readable code and place your code in files with a .java extension on the filename. In order to run the
code, it first needs to be compiled. The compile step creates a file that humans cannot read with a .class
extension. This .class file cannot be executed by the computer operating system; it is in byte-code
format. Class files are run by the Java Runtime Environment (JRE) executable, java.exe.
The Java runtime creates a Java Virtual Machine (JVM) in computer memory that can interpret and
run the byte code. The value of having a JVM read and run the byte code is that, in most cases, the byte
code can be written once, run anywhere-a fundamental goal of the Java language. You write it and
compile it wherever it is convenient for you, the developer, and then place it on any computer with a
compatible JVM to be run: in a workstation, server, browser, cell phone, or web server. The JVM handles
all the specifics of talking to the operating system and to the hardware.
We will see the power of this concept in our code, which we will write, compile, and run on our
workstation. We will then load it onto an Oracle database (actually, we will store it in the database), and
have the Oracle JVM run it also in Oracle.
Using the Java Compiler
The JDK has a number of command-line utilities in the bin subdirectory. One of these is the primary Java
compiler, javac.exe. Another is the primary Java executable for running applications, java.exe.
To compile Java code, you execute javac.exe, passing the name of the Java code file as a parameter,
like this (assuming your command prompt is in the directory javadev/mypkg ):
javac MyApp.java
You must include the .java extension on the code file name. This command will find the file
MyApp.java in the current directory and, if successful, it will place a compiled Java file named
MyApp.class in the current directory. This is true whether or not MyApp is in a package. If MyApp.java
refers to other compiled classes that are not in the current directory, then they must be found along the
CLASSPATH (for example, the compiler can find oracle.sql.ARRAY when ojdbc6.jar is listed in the
CLASSPATH ).
If there are other Java code files referred to by MyApp that can be found along the CLASSPATH , and the
code has not been compiled or has been updated since the last compilation, then javac.exe will compile
those classes also. The referenced code will be compiled and the compiled class file will be placed in the
same directory with the referenced Java code file. For example, MyRef.class will be placed in the same
directory as MyRef.java .
Additionally, you can compile multiple Java classes or all in a specific directory by specifying a
wildcard, like this:
 
Search WWH ::




Custom Search