CS 451 Programming Paradigms
Java Introduction

Java's Origins

Java was created in 1991 by Patrick Naughton and James Gosling.

They wanted a language that was small, to be used for consumer devices and which supported tight, portable code. Moreover they hoped for a language that could be used for distributed applications which would have open standards, as would the language itself.

They resurrected Nicklaus Wirth's design for UCSD Pascal, using a virtual machine.

file.java --> Java Compiler --> bytecodes | 4 | 2 | 17 | ... -->

         virtual machine (executes bytecodes) -->  specific architecture

At that time there was no market for their product.

Then browsers for the WWW were becoming hot, and they brought up issues not encountered in the workstation world, such as

So they built a browser that intrepreted bytecodes, as with the language they had designed after UCSD virtual-machine based Pascal.

In 1995 Netscape released a Java-enabled browser, and the explosion of use currently underway with Java began.


Java's Philosophy

Look carefully at sources of bad coding and bugs from C++ and other languages. Then add features (or delete them) to deal with these. They did a large number of studies and determined the following important sources of problems (among others):

The importance of using studies of language use in practice cannot be stressed too much. Java was the first language to rely so heavily on this kind of empirical evidence for guiding the language design choices.


Java's White Paper Buzzwords

A white paper was published describing the qualities that this new language was to have. Each one is discussed in turn in what follows.

SIMPLE

It is generally agreed that simplicity is achieved in Java, with a few exceptions such as the switch statement which retains the same form as in C/C++. It is not likely that a full-power general-purpose high-level language can be without any sublety.

OBJECT-ORIENTED

Java is a good object-oriented language. The elimination of multiple inheritance is a controversial one. It is based on the results of the aforementioned studies, which indicated that over 90% of the time multiple inheritance was used in the service of code organization not related to actual inherited attributes or behavior. Moreover it is usually used incorrectly.

For example, you may have objects that have their own behavior (interaction in a simulation let's say) but which you also want to have graphical (visual/windowing) behavior. Typically the objects are made to inherit from both. A new mechanism called INTERFACES can provide this functionality and organization without the complexity of inheritance.

DISTRIBUTED

ROBUST AND RELIABLE

SECURE

ARCHITECTURE NEUTRAL

PORTABLE

INTERPRETED

HIGH-PERFORMANCE

MULTITHREADED

DYNAMIC


Possible Misconceptions


Details of Using Java

Applets are used with browsers. The details of their creation differs just somewhat from regular applications. Often used to download code, to offload computation to other machines, or for "content handlers".

Applications are standalone.

To compile a .java file that contains at least one Java class, use the Java compiler (javac). This will create a file of the same name with the final extension changed from .java to .class. This file contains the bytecodes for the virtual machine. To run a java program simply execute the virtual machine (java) on the file that contains the function "main". Do not include an extension on that file when you give it as the argument to the virtual machine. For example,

22% javac Item.java Queue.java Test.java

23% ls

Item.java Item.class Queue.java Queue.class Test.java Test.class

24% java Test

... execution commences ...

To use a java program in a browser, create an applet. You then create an HTML file that contains links to the applet code. Finally you can link that HTML file into any other HTML file. See the text for more details on this procedure.

If you wish to view an applet without using a browser, again create the HTML file that contains links to the applet code and execute the following:

appletviewer <your HTML file>.html


Details of Java Design


Summary of Major Differences from C++


[ Back to CS451: The JAVA Segment ]