First Java Program - Hello World

It's always exciting to write your first program and execute it without error. In this post you will learn to write your first java program.

Pre-Requisite Softwares :

1. Java SE Development Kit or JDK  - It is generally a Java Software which you need to install on your system before writing any code in Java. And after installing java set Java Path in your environment variables.

  • Download Latest Java Version from following link - Java Download
2. Java IDE or Text Editor - You need to have any text editor to write Java code. You can use anyone from following Netbeans, Intellij, Eclipse, Notepad or Notepad++ etc.

Creating Hello World Program
  • Declare a class 'MyFirstProgram'
  • Declare the main method public static void main()
  • And print a string "Hello World" using System.out.println()
Hello World Program

// Class
class MyFirstProgram {
 
 // Main method
 public static void main(String[] args) {
  
  // Print Hello World
  System.out.println("Hello World");
 } 

}




Java Keywords used in 'Hello World' Program
  • class keyword is used to declare a class.
  • Public is an access modifier which defines main method's accessibility. Public means main method is global or accessible to all other classes in the project.
  • static is a keyword in java, when static is used with any method then it is called static method. Static method can be called without creating the object of the class.
  • main is the method name and also the execution point of any program. Main method is required to execute the program.
  • String[] args is an array of string is basically for command line arguments.
  • System.out.println() is used to print any statement. 
    • System is a class
    • out is the object of PrintStream class
    • println() is method of PrintStream class

Run the First Program:
  • If you are using Eclipse then you can run this program by just clicking the green play button displayed on the top bar. 
  • Or right click anywhere in the class and click 'Run as Java Program'.

Output:
  • Hello World - will be displayed in the console


JDK, JRE & JVM  << Previous      ||      Next >>  Java Variables


Click here to find complete Java Tutorials Series

Author: Vaneesh Behl
Subscribe FB Group Techlistic on FB
Join Telegram channel at https://t.me/techlistic
Feel free to ask queries or share your thoughts in comments or email me.

Comments

Popular Posts

Top 10 Demo Websites to Practice Selenium Webdriver Online

Top 25 Must to know Selenium Webdriver Commands List

Selenium WebDriver - Browser and Navigation Commands

Assignment 6: Automate "User Registration" Process for E-commerce Website using Selenium

Selenium IDE - Sample Script With Most Commonly Used Commands