Java - Right Way or No Way?

Java as a portable language.

Java is a high level language with some really nice features. It was produced at SUN around 1992 by James Gosling and others (via other names) by as a "write once, run anywhere" object oriented language using an intermediate "byte code" form, a tokenised format that is run by a Java Virtual Machine (JVM). The idea is that the byte codes always have the same meaning, and provided you have a JVM for your computer, then any Java program in byte code format will run.

Java avoids many of the bug inducing features of C++ by leaving out operator overloading, head files, structures, unions, multi-dimensional arrays, templates and pointers. A lot of C++ bugs like memory leaks come from fancy pointer manipulation.

The Java Virtual Machine has an execution engine, a just in time compiler, a byte code verifier, a garbage collector, base classes and debug interfaces. Base classes are platform independent APIs. Garbage collection is easier and automatic due to the lack of pointers. However lack of pointers make Java a worse match to CPUs that use index registers heavily.

A JVM is actually an interpreter. As a result, as far as I can tell, Java runs really lousy on every machine. Not only are you emulating the Java instruction set, you are also emulating the entire Java Virtual Machine. True, machines will get faster, but as far as I can see, Java will always run 10 to 20 times slower than optimised code (which may or may not be critical in your particular application).

One possiblity is to use a Java native language compiler (if one is available for your target system). However this then loses any possibility of having a portable executable, and Java becomes little more than an "easier to use" version of C++.

I also don't know that Java has ever been as portable as enthusiasts have been telling me. There are lots of Java revision levels, there are lots of libraries. It seems to me that 100% pure Java applications tend to crash or not work well when you move them to a different platform.

There also appeared (at one time) to be a vast number of different versions of Java. PersonalJava was going to be a leaner consumer oriented one. EmbeddedJava, intended to fit in small computers. Well, it needed a megabyte before your application went in. A small computer might have 1k to 64k, and to be blunt there are better languages than Java for small computers. JavaCard, an API for smart cards. I can't see the sense of that one, as 8 bit processors can easily handle processing smart cards, and Java won't run on such small cheap CPUs. In many of the announcements, Java isn't a technology, it is a marketing term.

Java is far too large. Not the byte code; that is fairly compact. The Java Virtual Machine, with its libraries, seems to be around eight megabytes on PCs. That is far too large to support on the 8 MB Psion I tend to use, and is too large for most embedded computer applications where memory space is always tight.

Are there any good things about Java? Certainly are. It handles memory management well, and cleans up after itself. Threads are also cleaner. Exception handling is good, so it doesn't crash as often as some languages.

It isn't virus proof. Javasoft documentation warns: Users must be wary of executing any code that does not come from trustworthy sources. Who would trust code downloaded from the Web?

Java is not a standard. No standards body has ratified it. However a number of vendors provide Java products, and what Java does is considered by a consortia of Java vendors, so to some extent it acts like a standard. You can replace one implementation with another.

I grabbed a half dozen books on it, but the more I looked, the less compelling I found using it. So these days I don't even have the JVM on any of my computers.

I hope you have enjoyed