Java programming language is platform-independent language that means a Java program will run on any type of computer.

You may wonder how is this achieved? The answer lies in the fact that any Java program requires the computer it is running on to also be running a special program called a Java Virtual Machine (JVM). This JVM is able to run a Java program for the particular computer on which it is running.

For example, you can get a JVM for a PC running Windows; there is a JVM for a MacOS, and one for a Unix or Linux box. There is a special kind of JVM for mobile phones; and there are JVMs built into machines where the embedded software is written in Java.

We saw earlier that conventional compilers translate our program code into machine code. This machine code would contain the particular instructions appropriate to the type of computer it was meant for. Java compilers do not translate the program into machine code instead they translate it into special instructions call Java Byte Code. Java byte code, which, like machine code, consists of 0s and 1s, contains instructions that are exactly the same irrespective of the type of computer. It is universal, whereas machine code is specific to a particular type of computer. The job of the JVM is to translate each byte code instruction for the computer it is running on, before the instruction is performed.

There are various ways in which a JVM can be installed on a computer. In the case of some operating systems a JVM comes packaged with the system, along with the Java libraries, or packages, (pre-compiled Java modules that can be integrated with the programs you create) and a compiler. Together the JVM and the libraries are known as the Java Runtime Environment (JRE). If you do not have a JRE on your computer (as will be the case with any Windows operating system), then the entire Java Development Kit (JDK), comprising the JRE, compiler and other tools, can be downloaded from Oracle, the owners of the Java platform.

Integrated Development Environments (IDEs)

It is very common to compile and run your programs by using a special program called an Integrated Development Environment (IDE). An IDE provides you with an easy-to-use window into which you can type your code; other windows will provide information about the files you are using; and separate window will be provided to tell you of your errors.

Not only does an IDE do all these things, it also lets you run your programs as soon as you have compiled them. It is perfectly possible to compile and run Java programs without the use of an IDE but not nearly so convenient. You would do this from a command line in a console window. The source code that you write is saved in the form of a simple text file which has a .java extension. The compiler that comes as part of the JDK is called javac.exe, and to compile a file called, for example, MyProgram.java, you would write at the command prompt:
  • javac MyProgram.java : This would create a file called MyProgram.class, which is the compiled file in Java byte code. The name of the JVM is java.exe and to run the program you need to type java MyProgram.
  • java MyProgram : To start off with however, we strongly recommend that you use an IDE such as NetBeans or Eclipse.

Java Applications

Java applications can run on a computer, on such devices as mobile phones and game consoles, or sometimes can be embedded into an electronic device. In the last case, you would probably be unaware of the fact that the software is running at all, whereas in the former cases you would be seeing output from your program on a screen and providing information to your program via a keyboard and mouse, via a touch screen, or via a joystick or game controller.

The screen that provides output from your program, and prompts you to enter information, is known as the user interface. There are two principal types of user interface:
  • text based
  • graphics based 

With text based user interfaces, information is displayed simply as text with no pictures. Text based programs make use of the keyboard for user input. Text based programs are known as console applications

You can probably more accustomed to running programs that have a graphical user interface (GUI). Such interfaces allow for pictures and shapes to be drawn on the screen (such as text boxes and buttons) and make use of the mouse as well as the keyboard to collect user input.

Eventually we want all your programs to have graphical interfaces, but these obviously require a lot more programming effort to create than simple console applications.