Tuesday, May 20, 2008

Introduction to Java

Welcome to our first lesson in Java programming. This lesson provides a brief historical background to Java and its fundamental differences to traditional programming languages as C and C++.

In June 1991 James Gosling created a programming language. The language was created as a part of the Green Project of Sun Microsystems. Initially the language was called Oak, reflecting an oak tree that stood outside Gosling's office. Unfortunately the trademark lawyers rejected the used of this name. It came to the point when the lack of a name was the main reason preventing the shipping of the language. In a rush to find a proper name, a dozen employees spent an afternoon yielding out random words. These words were ranked, and the sorted list was sent to the trademark lawyers. The fourth suggestion on the list passed the lawyers test and became the name of the newborn programming language, Java.

The first public implementation of Java, named Java 1.0, became available in 1995. Since launch the average performance of Java programs has increased. Todays public implementation, Java 1.6, perform comparable with C and C++. The whole Java implementation have been available under the terms of the GNU General Public License (GPL) since 8. May 2007, except for a relative small portion of code which Sun did not hold the copyright of.

The Java maskot, Duke
The Java maskot, Duke

From its beginning an important feature of Java can be summed up in Suns slogan Write once, run anywhere (WORA), reflecting Javas platform independence. That is, a program written in Java should run similarly, or ideally identically, on any supported platform and hardware. This is achieved by the fact that most Java compilers code the Java language file only halfway, to a code called Java bytecode. This bytecode is run on a virtual machine (VM) which interprets and executes the Java bytecode.

Java suffered, and in some circuits still suffers, from a reputation of poor performance because of the need for interpretion of the Java bytecode or a convertion to native machine code. The performance of Java is dependent on the virtual machine that is used to execute the Java bytecode. As previously noted, new virtual machines perform comparable to some of the most efficient programming languages as C and C++. In general the difference in performance between the languages varies, each of the languages is out-performing the other on spesific tasks. In real life programs benchmarks shows that there is typically little to no performance difference.

For completeness it should be mentioned that there exists compilers, such as The GNU Compiler for the Java (GCJ), which is capable of coding Java source code or Java bytecode to native machine code. When compiled to native machine code no interpretion or futher convertion is needed, as is the case for most traditional languages as C and C++, but this is of course performed at the expense of the Javas platform independence.

Looking aside from platform independence and performance efficiency, Java offers a class library consisting of million of codelines, which is, as mentioned, currently released under the GPL. This library, which for each new Java version is being updated and optimized, provides a solid foundation that can and should be used in every Java program. In most other programming languages no such library is present, the only library one can rely on, apart from custom implemented libraries and the libraries some compilers provide, is the general library of the operation system in use. These library is generally much smaller than the class library Java offers, resulting in the need of fewer items to be coded. In addition, most programmers, and especially beginners, often find Java easier to use. Indeed, it could be argued that Java in general is easier to use, since the combination of its library and its syntax tend to give Java source code much fewer codelines, as a rough estemate compared to C or C++, half the number of lines are needed in the Java source code compared to the same program written i C or C++. Of course, patriotic C or C++ programmers will probably argue that their custom libraries is only created once, so the number of codelines need for future programs is less (with the use of these old custom libraries). Keeping in mind that Javas library consist of million of codelines, it is left to the reader to persuade this argument.

We conclude the discussion noting that there are applications where a spesific programming language will have its clear advantages. In addition, the choice of programming language will often depend on the programmers previous experience, since this often defines the programmers way of thinking. However, either if you are new to programming or are ready to change your language, Java should be given a good chance to be your language of choice.

_______________________________________________________
Further reading and sources:
James Gosling commenting on the question How was Java named?
GCJ Homepage
Java pulling ahead? Java versus C++
Jake2, a port of Quake2 game engine, benchmarks

1 comments:

Anonymous said...

Wow! Great post! Whoever wrote this must be a genius! I wish I was that smart! "Andreas," that must be the future name of the president! All hailt to this man! Wow....