In this tutorial you will learn about the Java Compile and Run Program and its application with practical example.
Creating, Compiling, and Running a Java Program
Clear all the difficulties related to java compile and run the program with just one click. Get step-by-step solutions for your project.
Editing Java Program
Step 1:- Create a file called “HelloWorld.java” using a text editor program of your choice. The .java file extension is used to specify the java language file.
Step 2:- Let’s open the “HelloWorld.java” file that we created, put the following line of code in it, and save it.
1 2 3 4 5 6 7 |
// Your First Program class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } |
The println() is a function that tells java to display or output the content inside the parentheses.
Compiling Java Program
Step 3:- Now, go to the terminal and switch to the project directory and run the following command to compile the java program we created.
1 |
javac HelloWorld.java |
Running Java Program
Step 4:- After compilation the .java file gets translated into the .class file(byte code). Now we can run the program. To run the program, type the following command and press enter –
1 |
java HelloWorld |
Once the java program is executed it will print “Hello, World!”.
Output:-
1 |
Hello, World! |