Introduction
The Java language is relatively new, and can be seen as an object oriented improvement on the C++ language. It contains many of the best features of the C++ language, as well as retaining much of the syntax, but Java builds on the object oriented side by adding some new features of its own.
Based on the write once, run everywhere philosophy first proposed by Sun Microsystems, Java can be compiled into several formats, each of which we shall discuss in this article.
We shall also look at some tools that you will need before experimenting on your own, and take our first tentative steps with the language before moving on, in future articles, to explore its power more fully.
Java and Java Script
Java is not the same as Java Script. Although the language syntax is very similar, Java Script is an interpreted language that is provided by browser manufacturers to allow web pages some level of interactivity.
In simple terms, Java Script is the Java language, some specific objects that the browser will understand (such as the 'document'), which the script can interact with.
Java, however, is a complete implementation, with classes to interact with the operating system (Windows, Linux, MacOS), and support for other functions that Java Script does not come with.
Java Target Files
Unlike other languages, Java is designed to be run on any platform that supports a 'Virtual Machine'. This VM takes bytecode and can interpret it efficiently; in the same way that a web browser can turn plain text into a visually rewarding experience.
There are three types of target : the Class file, which needs the VM to be run in, the Applet, which can be run inside a browser or other sandbox, and the executable, which can be run on the operating system without any additional support.
The Java Toolset
To play with Java, you will need a compiler and a Java Virtual Machine (JVM). The compiler will turn the source code into a class file, that can be run inside the JVM or an applet that can be run in a browser.
We shall be looking at examples that are run in a JVM, or browser, and not ones that are taken the final step, and turned into native executables.
A list of tools and services is at the end of this article, along with a little comment on each, and our suggestions on how to get started.
Next Steps
Here is the first piece of Java code that we will compile and execute:
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
}
}
Simply cut and paste the code into a text file, and use your compiler to create a class file based upon it. Hint : the easiest way is to submit the file to the online JXXX compiler service (see below), and download the resulting .class file.
Then, open a command window in the folder where you stored your .class file, and type:
java HelloWorldApp
Do not enter the .class extension. Marvel at the results, or go here if it didn't quite go according to plan!
Next time - we take apart this simple piece of Java code, and try to figure out what it all means.
Links
The Java Runtime Environment that you will need to run all your applications, supports Windows, Solaris and Linux. Mac users will need to ask me for further guidance...
For those who can't or don't want to go through the rigmarole of installing one of the free java download sets like MinGW or GCC, this service will compile your files for you, into several target types.
The Borland JBuilder Foundation
This is a free version of the Borland JBuilder suite, which we shall use as our development platform for future Java experiments and learning experiences.
Part of the GCC toolkit - only for the serious programmer in you.
A reasonably easy to install version of GCC, plus binaries for Windows.
Free Java Compiler and Java Download Collection
The rest of the field - compilers, interpreters and other free java downloads, courtesy of The Free Country.
Join the Conversation