Run Your 1st Java Program
When Java program is written on notepad, then .java is given with this extension. The file name of java is the name of the class. If a java file has more than one class, then the class that contains the main method, then the name of that class is the name of the file. The name of any class and the name of the file are the first character; occurs in uppercase.
For example, HelloProgram.java
To run your 1st java program first set the path for java compiler. To set the path first press “windows+r” key and you get the following –
Now type the cmd in the text field and press ok and you will get the following-
Now create a java folder on the desktop or where you want. Then using cd command reach to that folder (see figure below). Type ‘dir’ command to see the files that are inside the java directory (folder).
Now we set the path to run the java file. To set path just open JDK directory in c drive and then go to the bin folder (figure below)
Now copy the path from address bar (figure below)
To set path just paste the copied content by right clicks and paste (figure below). Command below:
set path= “C:\jdk-16\bin”;
To check that the path is set or not just type command path and enter and your path is visible on the cmd.
Now we type and save our HelloProgram as HelloProgram.java (figure below)
Once program is saved it is visible in your java folder (created to save the programs) (figure below)
Now to compile the java program just type the ‘javac’ command like below:
Once java file is compiled a HelloProgram.class file is visible in your java folder. (Figure below)
Now to run the java program we use “java” command (see figure below)
Output: Once your program successfully run then you get the following output.
Must Read – Java Program Structure
Download JDK