Lab #6, the first Java lab can be done after reading this tutorial.

Why Java?

Java began life as a programming language for software for consumer electronics- devices such as toasters, and microwaves. Most research went into building small, reliable, safe, long lived, processor independent, real-time, and distributed systems. C++ was insufficient because it was processor dependent. A program written in C or C++ must be compiled for a particular computer chip. When a new chip comes out, the program must be recompiled. The complexity of C and C++ makes it extremely difficult to write reliable software.

Then the World Wibe Web happened, and the Java developers realized that an architectural-neutral language like Java would be ideal for programming on the internet. A program could run on all of the different types of computers connected to the internet.

What is Java?

In "The Java Language: A White Paper," Sun describes Java as follows:

Java: A simple, object-oriented, distributed, interpreted, robust,
secure, architecture-neutral, portable, high-performance,
multithreaded, and dynamic language.

One downside is that Java runs slower than native C or C++. However, Java code will run unaltered (!) on any other Java platform, like Solaris, HPUX, Mac, Windows 95/NT, Linux, SGI, and OS/2. Furthermore, just-in-time compilers and Java-chips are being developed that will eliminate the performance gaps.

Java eliminates:

  • pointer arithmetic
  • structs
  • typedefs
  • unions
  • operator overloading
  • need to free memory
  • Java provides:

  • null pointer checking
  • array bounds checking
  • exceptions
  • unions
  • automatic garbage collection
  • portable, single compilation
  • a genuine object language
  • Java, the Language

    Before we look at some Java programs and try to compile them, let's first look at the language and syntax a bit closer.

    Java Programs

    Java programs come in two varieties: stand-alone applications and applets.

    A stand-alone application has a main (like C and C++) method. A Java applet is a Java program that can be embedded in another application. An applet has no main method, and is designed to run in a Java compliant browser, like HotJava, Appletviewer, or Netscape.

    JDK

    Now that we know all this information, let's try it ourselves! Before we can proceed, we need to get the Java Developers Kit (JDK) from Sun and install it.

    JDK is available at http://java.sun.com/java.sun.com/products/JDK/index.html.
    Documentation for JDK is available in two forms: on-line and downloadable.

    The 1.0.2 release of the Java Developers Kit contains (for a description see):

  • Java Applet Viewer
  • Java Compiler
  • Java Interpreter
  • Java Debugger API and Prototype Debugger
  • Java Applet Upgrade Utilty
  • JDK is available on these platforms (for deatils see http://java.sun.com/devcorner.html):

  • SPARC Solaris (2.3 or later)
  • Intel x86 Solaris
  • Windows NT/95 (Intel x86)
  • Macintosh 7.5
  • Java Lab 1


    Java Home
    Lectures
    Labs