Some PCs might have Java already installed.
To check if you have Java installed on a Windows PC, search in the start bar for Java or type the following in Command Prompt (cmd.exe):
C:\Users\Your Name>java -version
If Java is installed, you will see something like this (depending on version):
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
JAVA_HOME
environment variable to the directory where you installed the JDK.bin
directory to your system's PATH
variable to access Java commands from the command line.HelloWorld.java
.public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } }
HelloWorld.java
.javac
command:javac HelloWorld.java
If the compilation is successful, a HelloWorld.class file will be generated.
Run the compiled program using the java command:
java HelloWorld
Congratulations, you have written and executed your first Java program.