Prince Pascal or Jester Java: Who will be king?

Abstract

With the explosion of the WWW, a new playing piece came into the picture. This is the two-year-old programming language Java, developed by Sun MicroSystems.

With this came concepts like OOP and Dynamic Web pages. The question is how will this influence you?

This presentation will look at what Java is, how it differs from JavaScript and Pascal and what the future will be for Java at Universities.

1. Introduction

Java is a new computer programming language. There are probably newer programming languages, but no other programming language "grew up" as fast as Java did. As one can expect Java might, and probably already went, through a few teething phases. But Java is growing daily.

Table 1 reflects some popular computer languages that developed since the start of the Third Computer Generation. If one compares Java with these mature programming languages, one would see that Java could be used for any of these application fields, with the extra benefit of security and platform non-specific execution.

Table 1 [Fry75, Bly83, Lev78, Shel90, and Dei97]
LanguageYear releasedOriginal purpose
FORTRAN1957Scientific applications
COBOL1960Commercial applications
BASIC1964Simplified FORTRAN
Pascal1968Educational training
C1972System software
C++Early 1980sOOP
Java1995Appliance control

The question might arise whether Java is capable to replace all these languages? The answer is "No". Not yet.

2. History of Java

Everything started at Sun MicroSystems in 1991 with Project Green, a project in which James Gosling developed a C and C++ based language to program and control consumer electronic devices. The language was called Oak, but had to change after it was discovered that an existing language was already called Oak. After some thought and consideration, the name Java was suggested, while a group of Sun people visited a local coffee place.

But Project Green was almost scrapped when a major contract was awarded to another company. In 1993 the WWW became very popular with the creation of Mosaic and Sun saw the possibility that Java could be used in Web pages. Java was developed further and on 23 May 1995 Sun announced that Netscape "... intends to license Sun's Java programming language to implement in the Netscape Navigator browser". [Dei97], [Sun95] Many complete tutorials on Java are already available on the Internet. One of these is maintained by Sun themselves. [Sun97a]

After its birth Java took the world by storm. Table 2 gives search results for a search of the word "java". Recently Java News Network stated that there are 177 published Java books, 195 Java books being written, 267 foreign language books on Java giving a total of 638 books worldwide. [JNN97] At this stage there are between 150 and 200 books on C++.

Table 2
Search EngineResult
Altavista3 187 820 documents
Hotbot587 357 matches
Lycos147 236 results
Netscape131 832 pages
Webcrawler46 030 documents
Magellan29 092 results
Yahoo3 407 sites, 48 categories
Lycos61 results

One factor that influenced the popularity of Java is the fact that the Java Development Kit is available from Sun, for free. [Sun97b]

3. The Java Language

Design specifications

Java consists of the best properties of various languages. In the design of the language the following design goals were followed:

The language should be ...

The syntax of C and C++ was used to make the language familiar to a large proportion of the programming population.

Using object-orientation ensured that the systems developed could easily be modified and made use of the software engineering principle of "code reuse".

By removing pointers and verifying code before it is executed, the designers made sure that a system written in Java was reliable and robust. Depending on the machine on which a Java program is executed, the program can be forbidden to read from or write to a local disk.

Concurrency is part of Java, giving it the potential to run more than one thread at a time.

Although Java programs can be developed on various programming platforms, the resulting code follows the "Write Once, Run Anywhere" rule. This means that a system like Corel Office for Java can be executed on a Win 95, a PowerPC or Unix system.

Java environment

To develop a Java program, the programmer follows the following steps:

The process of executing the program includes the following steps:

The process of compiling Java code does not produce platform specific machine code, but rather bytecode, which is the "machine code" of a Virtual Java Machine. The Virtual Java Machine is supplied by either a browser, like Netscape, Internet Explorer, Hot Java or Appletviewer or a standalone Java interpreter. [Dei97]

Resulting Code

The Java program being written can either be an applet or an application. An applet is a small program that can be embedded into an HTML-page and will be executed in the browser from where the HTML-page is viewed. The application is a program that is executed without making use of a browser, it is interpreted much in the same fashion as a Basic program (java <filename>.class).

This means that an HTML-document explaining concepts, for example Newton's Laws, can invoke a program to either demonstrate a concept or test the concept.

The resulting execution is relative slow, compared to Pascal and C++, because the code is interpreted. Some Just In Time compilers (JITs) can be found for certain platforms. This compiles the bytecode to platform specific machine code and then executed. When JITs are better developed and integrated into systems, the performance of Java programs will be in the same order than that of Pascal and C++.

Difference between Java and JavaScript

Where Java is a programming language, JavaScript is a macro language, developed by Netscape. JavaScript is also object-oriented, but is interpreted from the source code and not from compiled code. This means that Java is faster than JavaScript.

One must not compare these two against one another to decide which one to use, but rather use them together to get maximum effect.

4. Java and Pascal

Pascal is a procedural language, consisting out of data types and records with procedures and functions to manipulate these types and records. Pascal is case insensitive.

Java, on the other hand, is an object-oriented language, containing only objects. These objects contain data types and methods (procedures and functions) to manipulate itself. Java is case sensitive.

An Example

The following Pascal program, Java applet and Java application do exactly the same:

Pascal
Program Example;
Begin
  Writeln("Hi there!)
End.
Java applet
import java.awt.Graphics; // "uses" Abstract Windowing Toolkit
import java.applet.Applet; // Program will be an applet
public class Example extends Applet {
  public void paint(Graphics g) {
    g.drawString("Hi there!", 40,15); // 40 pixels from the left and 15 pixels from the top
  }
}
Java application
import java.io.*; // all Input/Output methods
public class Example {
  public static void main ( String args[] )
  {
    System.out.println("Hi there!");
  }
}

One more Example

Assume one wants to write a program to print reports at the end of each quarter. For children in the high school the program must produce a report in the normal form (name, subjects, marks and remarks). If a child is in the primary school, the program must generate a "playful" type of report, containing pictures, funny faces, golden and silver stars.

In Pascal a program to implement this could contain two different procedures to print the report. An IF or CASE statement will be needed to decide which procedure to execute. Something like the following:

if Child.Grade < 6
  then PrintPrimaryReport(Child)
  else PrintSecondaryReport(Child);

Using the object-oriented capabilities of Java will result in something like the following:

Create a class Child for a child, containing personal detail of the child and an abstract method to print the report (method is defined but not implemented).

Create a class PChild for a primary child, inherit fields and methods from Child, add the subjects and implement the printing method.

Create a class SChild for a secondary child, inherit fields and methods from Child, add the subjects and implement the printing method.

Create the objects isPChild and isSChild and an object isChild.

To print the primary report, execute the following:

isChild = isPChild;
isChild.PrintReport();

To print the secondary report, execute the following:

isChild = isSChild;
isChild.PrintReport();

Here the encapsulation (combining records and functions into one object), inheritance and polymorphism (deciding at run-time which method must be executed) of object-orientation is clearly being used.

5. Java's future at Universities

The future of Java at Universities was one of the topics discussed during a recent conference of the Southern African Computer Lecturer's Association. No single conclusion could be reached on this topic. The University of Pretoria changed their prerequisite for B.Sc. (Computer Science). From 1998 a student must have Computer Studies as a matric subject and Java will be the language for first year students. Other universities feel that Java is not suitable for first years, but must be lectured in the second year. Some people even felt that Java might be a "flash in the pan" and a "computer fashion" which will change after a few years.

Professor Doug Lea from the Computer Science Department of the State University of New York at Oswego feels "I really cannot think of any good pedagogical reason not to use Java in a Computer Science program" [Lea97]. He goes further and motivates that by using Java you can introduce more about programming, design, and problem solving.

6. Conclusion

In the near future Java will not disappear from the computer screen. It will either develop further or a similar programming language will develop out of it. As more and more books become available, expertise increase and be more available, one can expect that school pupils will also start to explore these new fields.

It is worthwhile to start learning Java.

References

[Bly83] Bly, R.W., A Dictionary of Computer Words, Banbury Books Inc, 1983

[Dei97] Deitel, H.M. and Deitel, P.J., Java How to Program, With and introduction to Visual J++, Prentice Hall, 1997

[Free96] Freeman, A. and Ince, D., Active Java, Object-Oriented Programming for the World Wide Web, Addison-Wesley, 1996

[Fry75] Fry, T.F., Computer Appreciation 2nd edition, Newnes-Butterworths, 1975

[JNN97] Java News Network, 1997

[Lea97] Some Questions and Answers about using Java in Computer Science Curricula, 1997

[Lev78] Leventhal, L.A., Introduction to Microprocessors: Software, Hardware, Programming, Prentice-Hall Inc, 1978

[Shel90] Shelly et.al., Computer Concepts, Boyd & Fraser Publishing Company, 1990

[Sun95] NETSCAPE TO LICENSE SUN'S JAVA PROGRAMMING LANGUAGE, Sun MicroSystems, 1995

[Sun97a] The Java Tutorial Object-Oriented Programming for the Internet, Sun MicroSystems, 1997

[Sun97b] Downloading Java Development Kit Version 1.1.4, Sun MicroSystems, 1997