If you are new in java programming and you want to know how to run a java program then see the below steps. For running the java program use the Notepad and Command Prompt.

Simple Java Program:

In order to start with basic Java programming, let us look at the standard Hello World program. In this programs we will simply print the “Say Hello World To The World!” sentence.

public class MyFirstJavaProgram  
public static void main(String []args)   
System.out.println(“Say Hello World To The World!”);
Run a Java Program

As you can see, the program uses a single line of code in the main() function, which prints the statement ‘Say Hello World To The World!’.


However, before try to run this, first look at the following steps that you must follow in your quest to run a java program.

  • Open any text editor and paste this code in that file.
  • Save the file with a .java extension. For example, you can save the file as MyFirstJavaProgram.java
  • The next step is to open the command prompt of the system and relocate its reference to the directory in which the file is saved. For instance, if you have saved the file in C:\, then you must take the prompt to the same directory.
  • To compile the code, you need to type the following: javac MyFirstJavaProgram.java If there are no errors, you will automatically be taken to the next line.
  • You can now execute the code using the following command: java MyFirstJavaProgram
  • You should be able to see the following output on the screen. Say Hello World To The World!

This is the simplest method of how to run java program because in this platform for running java programs we cannot use any other software or any other application. For beginners this are the simplest way for running java programs.

Here are some simple programs for beginners, If you want to see this programs then click on below link

2 thoughts on “How To Run a Java Program

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top