♦ A Java program can be written once and then run on many different devices. ♦ You do not write Java programs for Windows, Unix, a Palm PC or any other device. ♦ You write Java programs to run on a .. JVM (Java Virtual Machine)! |
The process of creating a program is as follows:
|
♦ JVM (Java Virtual Machine) is a set of specifications (not a program) on how to be executed a Java program. It is platform independent. ♦ JRE (Java Runtime Environment) is the implementation of the JVM for specific platform (eg. java.exe for Windows). It is responsible for executing the bytecode of your program (eg. Person.class) in the specific computer. It is platform dependant. ♦ JDK (Java Developer's Kit) - also known as SDK (Standard Developer's Kit) is JRE plus Tools (Compiler, Debugger etc) for creating and executing Java programs. It concerns the programmers and is platform dependant. ♦ JRE is what you would install if you just want to run Java programs. ♦ If you are actually going to write and run Java programs, you will only need to install the JDK (Java Developer's Kit). The JDK contains the JRE plus all the necessary development tools (mainly the Java compiler). |
♦ After installing the JDK you will need to set the PATH environment variable of your operating system, so that you can easily run the compiler and the JRE from the command line. ♦ The value, you need to add to the PATH, is the full name of the bin folder where the JDK installed (eg. "C:\Program Files\Java\jdk-23\bin"). |
♦ After setting the PATH, check if the compiler and the JRE are working. ♦ Open a command line and type: C:\Users\alex>javac -version ↻
javac 23
C:\Users\alex>java ↻
...
C:\Users\alex>
If the responses are friendly, everything is OK.♦ Typically you must write javac.exe (for the compiler) and java.exe (for the JRE), instead of just javac and java However in command line usually you can omit the .exe extension. |
Write♦ Write (or just copy - paste) in a plain text editor the following Java program: |
public class Person { public static void main (String [] args) {
System.out.println ("Hello World");
} }as the public class and .java extension (Person.java) |
CompileOpen a command line and go to the folder where you save the file. Type:C:\Users\alex>javac Person.java ↻
C:\Users\alex>
If there are no compiler errors, the command line will appear again silently. |
RunFrom the command line again, type:C:\Users\alex>java Person ↻
Hello World
C:\Users\alex>
Excellent |
♦ Alternatively, you can go to an online compiler, such as W3Schools Compiler, to experiment. In this case, there is no need to install anything from Java. |