As We had already discussed about Java Hello World Program in the previous posts. Till now if you haven’t run your Java program then You first need to Setup JDK and Integrated Development Environment(IDE) or any Code Editor. If you had any confusion about setting up JDK and IDE you should check How to install JDK in your Computer? as well as you go through YouTube and watch it.
As of now we assume that you had already setup you JDK as well as you had setting up you IDE or Code Editor whatever you like to run your Java Program.
Run your First Java Program using IDE
As I discussed about IntelliJ IDEA we are using IntelliJ as our default IDE.
Create the Project in the IntelliJ IDEA
Step 1: Simply Open you IDE and select Create New Project.
Step 2: Then in the next Step Select Java from the left pane. If the Project SDK Section has No SDK detected simply click on the drop down menu and select your JDK version and leave everything as default and Click enter as shown in the below Image.
In the next Section leave it as default and click next.
Step 3: Then In the next Window IntelliJ IDEA asks you for the Project Name. As I had entered DailyJavaConcept as my Project name same as Enter your project name and click finish.
It will take a minute or two to prepare the workspace for our Java Development.
Step 4: In the Left Pane you will get you Project Name. Expand the Project Folder and then analyze the project Structure.
Step 5: Under the Project you will found a folder named src
. In this folder we will create our all java files and run them.
So for creating you First Java Program, right click on the src Folder then select new and select Java Class.
right click on src folder -->New -->Java Class
Then you will get the window like below and then Enter you Java Program name as i had entered Hello_Java.
after entering the Java file name Hit enter and you will see a new file with the name of your java program will be created under the src folder.
After that the IDE Interface will look like as the image below:
If you didn’t learn the basics of the Java Hello World program till now then learn by visiting the link or copy the below Java First Program and paste into the IDE.
//First Java Program class Hello_Java { public static void main(String[] args) { System.out.println("Hello World!"); } }
After pasting the program you should check that the Java filename and the Class name of the Java program should be same otherwise you will get the error.
Create the Configuration to Run your Java Program
Step 6: Then you Click on the App Configuration Button on the top bar nd then Click on the +
and then Select the Application from the drop down menu.
Step 7: After Selecting the Application,
- Change the name of the Configuration for running the Program as I renamed it to App.
- Follow the Main Class label and click the 3 dots in the last.
- Then select the Java Program to run, as We have Hello_Java then select and click ok and again ok to save the congiguration.
Now everything is done and you just need to run the program.
Step 8: For running the Java program click on the green color triangular button next to the Configuration then your program start compiling and start running and within a moment you will get the output under the Run tab in the below section of the IDE.
Note: This process of running the Java program is same for both Windows and Linux.
Run your First Java Program using Code Editor
In this Section I will only cover to run the Java Program using the Notepad++(Windows) or Notepadqq(Linux) because both the process is same as you can try to runt you java program using the Visual Code Editor by your own if you get ang issue then comment below.
Step 1: Open your Notepad and copy and paste the program below program:
//First Java Program class Hello_Java { public static void main(String[] args) { System.out.println("Hello World!"); } }
Step 2: Then save the program with the name of the class name with the extension .java for example Hello_Java.java
is the file name for the program given above.
Now open you Terminal / Command Prompt and type the below command to first compile the Java program and then run the java program.
javac Hello_Java.java
: The javac
command use to compile the Java file into the Bytecode.
java Hello_Java
: The java
command use to run the Java program. java
command run the generated .class file.
As I had already discussed all the ways to run the Java program if you need further assistance then you can also follow the video below:
These are the steps to run the Java program. In the most of the Tutorial we will use the IntelliJ IDE for ease. Otherwise if you want to run the Java program using the Terminal / Command Prompt you can choose you own way.
I hope you like this post. If you have any doubt then feel free to comment in the below section.
You could find the below post useful for your knowledge:
- History of Java
- Java Programming Language
- Christmas Tree Pattern Program
- Data Structure in Java
- Queue implementation in Java
- Pattern Programs in Java
- Feature of Java
- Java Hello World Program
- How to install JDK in your Computer?