Java Hello World Program

In order to start with basic basic Java programming, let us look at the standard Hello World program.

public class MyFirstJavaProgram {
	public static void main(String []args) { 
		System.out.println(“Say Hello World To The E3Docs!”); 
	}
 }


As you can see, the program uses a single line of code in the main() function, which prints the statement ‘Hello World!’. However, before that can be done, let us look at the steps that you must follow in your quest to execute the file. 

  • 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 Sample.java.
  • The next step is to 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.
  • In order to compile the code, you must type the following:
javac Sample.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 Sample.java
  • You should be able to see the following output on the screen.
Say Hello World To The E3Docs!