This tutorial will guide you how you can compile and run Jaa file using command prompt in windows operating system. Process is similar if you are using other operating system like Linux or Mac.
Step 1 : Install Java JDK and JAVA_HOME
First of all make sure to install Java JDK and JAVA_HOME on your system. For that you can go through this video.
You can check if you already have Java JDK installed on your system by opening command prompt and Just type java –version.
Step 2 : Create Java File
Now to create a java file just go to the folder you want like Desktop.
Now just right click on mouse and click on New -> Text Document.
Now just click on View -> Show -> File name extensions. This will show the extension of file.
Now Just rename Sign the file and replace .txt extension with .java file extension.
Step 3 : Write Java Program
Now, simply open the file with NotePad or any code editor.
Now just write Java Program.
class HelloWorld { public static void main(String[] args){ System.out.println(“Hello, World!”); } }
Step 4 : Run program using Command Prompt
Now to compile and run the java program using Command prompt .
Open Start Start Menu and Search for Command Prompt and Open it.
Then Just type cd Desktop, to navigate into Desktop.
Now just type javac HelloWorld.java, this command will compile the file. And show if there is any error.
This command will create a .class file.
Now just type java HelloWorld, this command will run the compiled class file.
So, here you can see the output, “Hello, World!”.
If you face any error following the above steps, watch this comprehensive video tutorial.