Getting Started with Java

The Java compiler is part of the Java Software Development Kit (SDK), formerly known as the Java Development Kit (JDK). The Java interpreter and JVM are part of the Java Run-time Environment (JRE). Both the Java SDK and JRE for various hardware platforms are available as a free download from http://java.sun.com.

Tip  

If you have access to a computer running an Oracle 8i Database or later, or an Oracle 9i Application Server or later, you may already have the software development kit available to you. To determine if the Java SDK was included in the Oracle installation, look for the jdk directory below the Oracle installation directory. If the jdk directory exists, ensure that <ORACLE_HOME>/ jdk/bin is in your executable search path .

Even if you have the Java compiler and run-time environment available, Sun s Java web site contains a wealth of information including the entire API specification for each release, tutorials and tools to assist in developing Java programs, and sample programs.

Note  

Even though the software development kit is now the Java SDK, some developers and manuals, including the Oracle documentation, still refer to the software development kit as the JDK.

J2EE, J2SE, and J2ME Platforms

When selecting the version of the Java SDK to download, you need to choose between the J2EE, J2SE, and J2ME platforms. Each of these three editions contains a different set of packages, or APIs, to develop Java programs. The first two characters , J2, stand for Java platform 2, which includes versions 1.2 and later of the Java SDK, and the fourth character, E, simply stands for Edition. The third character, E, S, or M, determines which libraries the download includes.

J2EE is the Enterprise Edition that contains the most libraries, and supports building enterprise- class server-side applications. J2SE is the Standard Edition that contains the tools to develop Java applets and applications. J2ME is the Micro Edition that contains a highly optimized run-time environment for deploying applications to consumer products such as cellular phones, Personal Digital Assistants (PDAs), and car navigation systems. If you are unsure which platform to choose, select the J2SE platform as it contains all of the tools you need to start learning Java.

Installing and Testing the Installation

Installing the Java SDK is as simple as running the downloaded executable file and following the installation prompts for both Windows and Unix platforms. For Unix platforms, first turn on the executable bit using the chmod +x command before running the downloaded executable file, and upon the completion of the installation, add the <INSTALL>/bin directory to your class path. The class path is an environment variable named CLASSPATH where Java programs search for dependent objects. For Unix installations, the class path is typically set in a run code script such as .profile or . cshrc , and for Windows installations the class path is set using the System Properties within the Control Panel.

To test the installation, create a small Java program named Hello.java using your favorite text editor. Do not worry if you do not understand all of the pieces of this program at this time; this step is only to verify the installation of the Java SDK.

 public class Hello {    public static void main(String[] args) {       System.out.println("hello, world");    } } 

At a command prompt, compile the program into Java bytecodes using the Java compiler javac.

 prompt> javac Hello.java 

If there are no errors, the compiler writes a class file named Hello.class in the same directory as your source code file. Test your JVM by running the Java interpreter java using the new class file. Note that you do not include the .class extension when running the interpreter.

 prompt> java Hello hello, world 

Running the class file on any JVM produces the same results. For example, if the class file was created on a Windows platform, you can perform a binary transfer of the file to a Unix platform and run the same java command using the same class file, and the program will run perfectly .

Checking the Java Virtual Machine Version

You can verify the version of the JVM installed by passing the “version parameter to the interpreter:

 prompt> java version java version "1.3.1_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01) Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode) 

There is no equivalent parameter for the Java compiler.

Integrated Development Environments

As shown in the installation test, all that you need to develop and compile a Java program is a text editor and the Java compiler. Once you become comfortable developing Java applications, you will most likely want to use an Integrated Development Environment (IDE) to simplify program development. IDEs provide useful features such as syntax highlighting, quick access to different source files, wizards to create template code for common program types, an interactive debugger, and source code control. IDEs will even point out errors in your program, such as not catching exceptions or mismatched braces, before you attempt to compile the program.

There is no shortage of capable IDEs to assist in your Java development, and Oracle s JDeveloper is a powerful IDE described in Chapter 13.



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