Image of Navigational Map linked to Home / Conetnts / Search The Java Puzzle

by Neville Franks - Soft As It Gets

Image of Line Break

Java Here, Java There, Java Everywhere!!

If you haven't heard of Java, you must have been living under a rock for the past six months. It seems that you can hardly turn a page of any mainstream computing publication without seeing some reference to Java. What I want to do in this article is talk about some of things Java is, and what it's not, and try to put this into a perspective that lets you decide whether to jump on the Java bandwagon or not.

For a start, Java is a lot more than just a language. It consists of three distinct parts:

And Java is more than just a language for the Internet! It's equally adept at producing stand-alone applications which are portable across operating systems.

A Portable, Secure Architecture Neutral Environment

One of Java's attractions is its ability to run applets or applications on many different platforms (without recompilation), and this is where the Java Virtual Machine comes in.

The JVM specification defines a processor independent instruction set for a virtual machine, and provides an interpreter to execute these instructions.

The concept of a virtual machine is nothing new, and those of you who go back far enough will remember UCSD Pascal and its P Code machine. Our programmers editor, ED for Windows, has a C interpreter at its core (see "Adding Extension Languages To Your Programs" DDJ, Sept. 1991), allowing users to easily extend and customise its behaviour.

It is important to note that the JVM specification is not tied to the Java language, and other languages including Ada 95 are being developed to run on it.

The JVM provides a security layer using bytecode verification to ensure that viruses cannot easily intrude. This is crucial for use on the Net, where programs are coming from who knows where.

The Language

We are told that Object Oriented Languages (OOL) are the way of the future and the Java language fits the mold nicely. Java is based in part on C/C++, Objective C, Smalltalk and a bit of Eiffel. It brings together the best features of these languages whilst leaving out the nastier stuff.

C++ is probably the most widely used OOL these days, but to be honest I've never been able to get into it. I've been writing in C every day for the past 15+ years, but have never been able to make the transition to C++.

About the time C++ came out I read Bertrand Meyer's book, "Object-Oriented Software Construction", which discussed Eiffel at some length and I think this ruined C++ for me. Eiffel was designed from day one as an OOL, whereas C++ always seemed to me like a whole lot of stuff glued on to C, stuff which never sat right with me. Mind you, judging by all the people around me using C++, I'm sure I'm the exception not the rule!

Anyway Java does seem right. The developers have removed most of what I didn't like from C++, retaining the good stuff and added impressive new capabilities like multithreading.

So where do Java and C++ differ? Well there are no pointers, no multiple inheritance, no operator overloading, no friends, no typedefs, #defines or preprocessor, no structures or unions, no functions, no goto, no automatic coercions and no new or delete (malloc/free in C).

If you look at C/C++ programming you will inevitably find large amounts of time spent tracking down problems with stray pointers and memory leaks. These types of problems simply don't exist with Java! Instead of the programmer doing memory management, Java provides its own garbage collection. There is still a new operator, but objects are freed by the system when they are deemed no longer required. Again garbage collection is nothing new and languages like Smalltalk have always had it.

Pointers are a major cause of problems in C/C++ code and can be extremely difficult to track down. Given that structures are gone, and arrays and strings are objects, arithmetic indicies can be used in their place. The run-time system checks all array indexing to ensure they are within bounds, so you no longer have to worry about dangling pointers trashing memory.

Another common C++ problem occurs whenever you add a new method or instance variable to a class. All classes which reference this class will need to be recompiled. Make files can be extremely cumbersome and you can spend a lot of time recompiling lots of code which in itself hasn't changed. This is termed the Fragile Superclass problem. Java solves this problem by compiling down to symbolic references which the interpreter resolves once, when classes are being linked. As the name resolution only occurs once at run-time, the hit on performance is small. So you can freely add new methods and instance variables without worrying about whether the changes impinge on other modules, or whether they need to be recompiled.

Java supports multithreading at the language level, and the Java libraries have been written to be thread safe. This enables applications to perform several tasks at once, like downloading a graphic or text file while doing some animation, and gives the user a richer more interactive environment.

You may be wondering whether Java will kill C++. Eventually I believe it will, but considering the large amount of C++ code out there presently I doubt this will happen any time soon.

The Libraries

The third piece of the Java puzzle are the Java Libraries. These provide a comprehensive set of classes and methods for creating cross-platform GUI applications.

In some respects these libraries are akin to the standard C/C++ libraries, but they go further to provide an Abstract Windowing Toolkit (AWT), enabling you to develop GUI applications which will run on any Windowing system that Java is ported to.

Again this may not seem like a major breakthrough as products like XVT, zApp, Zinc, etc., have been around for some time.

The difference here is that when you bring all three pieces of Java together you have a language and secure environment which, to my knowledge, is unmatched in its openness, portability and ready availability across platforms including the PC, Unix, and Mac.

The Downside

So what's the downside I hear you ask? Inevitably any new development environment will have problems and Java is not alone.

Programmers are not happy with various aspects of the AWT, some security flaws have been found (and fixed), applications which look fine under one OS don't always look so good on another, and right now Java programs are pretty slow. Of course these problems are being addressed but the performance issue is the most critical.

Fortunately the JVM was designed with on the fly compilation in mind, and several companies are working on this. Once a class has been downloaded and verified it can be compiled to run as native code for the target processor, instead of being interpreted. The speed improvement obtained from this just-in-time compilation should address the poor performance we are seeing right now.

It would also be interesting to see native code compilers for developers who are writing stand-alone Java applications.

Development Tools

Java development tools are starting to spring up. Some are being written in Java, like Sun's Java Workshop and Borland's Java Debugger, whilst others, such as our companies Universal IDE, ED for Windows and Symantecs Cafe, are being written in traditional compiled languages for optimal performance.

Like other OOL's Java has a complex class hierarchy. Therefore good class and method browsers and navigational aids, like being able to jump to the source file for any method or class, are highly desirable features to look for in an IDE.

Is Java Over-Hyped?

Personally I don't think so. Java is the most exciting language development I've seen come along in quite some time. Java's ability to run the same code unchanged across multiple platforms offers a range of exciting new opportunities for developers.

Java is not just for the Internet, but is equally at home in producing stand-alone (portable) applications. Sun are doing a great job at keeping Java open and listening to what we developers have to say. It's this level of openness which many developers find attractive.

Compared to C++, Java is a better language and has the potential to replace it over time.

Will VB-Script kill Java? Java is portable, shipping and has a lot of developers hot on its heels. VB-Script is none of these.

Links to sites with Java related information are available from our Web site at:

So my recommendation is, if you've got some spare time go ahead and learn Java. If you don't have any spare time, make some!

Copyright(c) Neville Franks 1996

Written by: Neville Franks
April 96

Image of arrow to previous article Image of arrow to next article
Image of Line Break