Nav-Bar 

What is Java?


Java Zone Index Page Search the Java Zone Site Java Dictionary

View the Tutorials Archive

What is Java? Java syntax and general style guide How to get Java running
Links to relevant sites

Email me

Introduction

Java's main aim is to be a platform independant programming language. It has undergone many revisions since its first release, and is currently up to version 1.2

If you've programmed C or C++ before you'll be at home with java - in fact, it should't take you long to pick it up at all. Java is based on the C language but has got rid of many of the more obscure and dangerous commands (such as 'goto'). One of the things you'll notice gone is pointers. They're still there in essence, but it's possible to program Java without acknowledging them at all. Where C allowed you free access to memory and the OS, Java is much more restricted.

One of the main reasons it has caught on is because many web browsers (such as Internet Explorer and Netscape) have Java interpreters built in, and so java programs can be included on web pages. The structure of java is such that certain security measures can be taken when a Java program is run on a web page to ensure the program doesn't carry viruses or read information off the hard drive etc. Java programs that run on web pages are referred to as "Java Applets", and normal java programs (running independently of browsers) are "Java Applications".
Note that Java applets running on web pages are not the same as "Javascript".

This site doesn't deal with Javascript at all, so you'll have to look elsewhere for that. All you need to know is that Javascript comprises of a script written "inside" the web page (as text) which doesn't require a Java interpreter but is very limited in its use. Java applets are compiled pieces of code stored as separate files on the web site which are executed by certain HTML tags on the web page. 

You'll be abe to find out more on java applets when the Java applet tutorial appears. Up until then the tutorials will be only concerned with Java applications. You'll need to understand how to program standard Java Applications before you venture into applets anyway, so it's no great loss.

How does it work?

To write a Java program all you need is a text editor. You have to ensure that when you save the file it is as pure text and not formatted (ie. in Microsoft Word format). On a PC, the Notepad.exe program will be fine. You might be tempted to use a Visual Java environment, although I'd advise against it whilst you're learning. Visual development environments are fine for designing graphical front ends for your programs, but for simple Java applications they tend to get in the way.

If you haven't got the Java Development Kit (JDK) installed on your system, go to the Links section of this site to see where to download it from.

Java is in its design an "interpreted" language. That means your programs are first read by an interpreter and then converted to machine code which your computer can understand. This is important for Java's aim to be platform independant. Thus the Java programs you write will run on any computer platform that has a Java interpreter - be it a UNIX system, a PC or an Apple Macintosh.

The text file you write that is a java program (usually named with the suffix .java) is first compiled (by you) into a "class" file. So if you wrote a program in a text editor and called it "Hello.java", once it has been compiled a file called "Hello.class" will be created. It is this "class" file that is read by the java interpreter. When you distribute your Java programs, you only need to provide the relevant class files you have created, keeping your source code (the .java files) tucked away. So going back to the case of applets, only the .class files need to be uploaded to sites for the applets to work.

A program written and compiled on a PC will thus work on any computer that has a java interpreter, just as a java program can be written and compiled on any platform.

To compile a java program, presuming you're using a command line version of Java (which I will for these tutorials), the command is:

     javac ProgramName.java

This will compile the text file called "ProgramName.java" which contains your source code, and output a file called "ProgramName.class". (Presuming no errors occur during the compilation). To run your program you only need the class file. The command to run a program through the java interpreter is:

     java ProgramName

Notice that the suffix ".class" is omitted. All java program files (including applets) have the ".class" suffix and so you don't include it when running the java interpreter. If you do include it you'll receive an error message.

See Getting Java Working if you have any difficulties running Java.
 

4-2-99