Java Hello World Program
Let’s create first Hello World Java application.
Create a java file ‘HelloWorld.java’ with the name ‘HelloWorld’ and extension as ‘.java’. Copy, paste and save below code inside HelloWorld.java file.
Java application file will always have .java as an extension in the file name.
// HelloWorld is the class name.
class HelloWorld {
// Predefined function given by java to print output.
public static void main(String[] args) {
// function to print Hello World !!!
System.out.println("Hello World !!!");
}
}
Note: don’t worry about main method. We will be discussing this later in another chapter. Just remember, main method will be executing at first place.
Run javac HelloWorld.java command in the same directory where we created above HelloWrold.java file. This command will create Employee.class file.
Run java HelloWorld command to get output of java application.
Congratulations!!! we have created our first java application.
Note: For having latest output always run javac class_name.java before running java class_name command. After saving latest changes in java file and run java class_name command will not print or give latest output.
Imran Khan, Adobe Community Advisor, AEM certified developer and Java Geek, is an experienced AEM developer with over 11 years of expertise in designing and implementing robust web applications. He leverages Adobe Experience Manager, Analytics, and Target to create dynamic digital experiences. Imran possesses extensive expertise in J2EE, Sightly, Struts 2.0, Spring, Hibernate, JPA, React, HTML, jQuery, and JavaScript.