Well, it's an island in East Indies, isn't it?
Ha ha, very funny. I'm glad we've got that "island in the East Indies" joke over and done with. Seriously, though, it is a computer programming language, which is used to create two different types of programs - called "applets" and "applications". I will go into these in more detail later.
Java was originally developed by the Sun Corporation (makers of Sun computer workstations). It is a compiled language. This means that you write the program in a text file (called the source code). This is then passed to a program called the Java compiler, which then turns it into a form that the computer can understand.
In fact, the resulting file (called a class file) can't run on the computer as such. In fact, you need another program called the Java interpreter, which takes your class file, and makes it do its stuff. This means that if you want to run a program that was written in Java, you have to make sure that your program is Java enabled. If you have a recent version of a web browser on your computer (either Netscape Navigator or Internet Explorer will do), then it will have the Java interpreter built into it, and should be able to run the Java applets with no problem. If not, then you will have to make sure that the Java interpreter is present somewhere on your machine.
You will need two programs - the Java compiler and the Java interpreter (or a web browser). Fortunately, these can be downloaded (quite legally) from the Sun web site, which is www.sun.com. What you need to look for is the Java Development Kit, or JDK. There are several versions available - any one will do. There should be instructions on the web site to download and set up the programs - just follow them.
When you have downloaded the software, you will need a way of running it. When you have written a program (let's call it myprog.java - all Java source code files end in the extension .java), you need to do the following:
, or by using the Run option from the Start menu. Either way, you will need to run the following command:
javac myprog.java
This runs the Java compiler (hence the letter "c") and tells it to compile the myprog.java program. It may produce (a large number of) errors, in which case you should go back and fix them (or just say "stuff it!").
The HTML tag that I used to include that applet on the web page was
<applet code="little.class" width="150" height="150"></applet>Note that the width and the height of the applet are specified in pixel values, and the applet HTML tag must end with </applet>.
java myprog.class
This tutorial mainly concentrates on how to write applets. However, I have dedicated one section to writing applications.
Java is very similar to the programming languages C++ and JavaScript (and it won't have escaped your attention that I have written a guide to both C++ and JavaScript). If you have a thorough understanding of C++, then you should be able to move easily onto Java. Movement from JavaScript to Java is considerably harder. If you have programmed mainly in JavaScript, or you have only a little knowledge of C++, then Java will take more getting used to. However, once you have got over the initial hurdle, then the actual programming (the statements inside the classes) should be fairly easy.
The parts of Java that are identical to JavaScript and C++ are the following. I have included links to each section:
C++ |
JavaScript |
|
if ... else statements |
||
switch statements |
||
Loops |