Java First Program

In this tutorial, you will learn to write java first program “Hello World” .

A “Hello, World!” is a simple program that  display outputs Hello, World! on the screen. As its a very simple program, it’s often used to introduce a new programming language to beginners.

Let’s illustrate how Java “Hello, World!” program works.

Java “Hello, World!” Program

// Your First Program
class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!"); 
 Output :  Hello, World!

How Java “Hello, World!” Program Works?

1.  // Your First Program

In Java, any line starting with // is a comment. Comments are used to help readers of the code understand the purpose and operation of the programme.. It is completely ignored by the Java compiler (an application that translates Java program to Java bytecode that computer can execute).
  • class HelloWorld { ... }

For now, Just keep in mind that every Java application has a class definition, and the class name should correspond to the Java filename.

3. public static void main(String[] args) { ... }

This is the primary approach. The main method is a need for every Java application. The main method’s code is first run by the Java compiler.

4. System.out.println("Hello, World!");

The code above is a print statement. It prints the text Hello, World! to standard output (your screen). The text inside the quotation marks is called  string in java.

Points to be Noted :

  • A class definition must match the filename in every valid Java application (class name and file name should be same).
  • The main method should be inside the class definition.
  • The compiler executes the codes starting from the main function.

This is a valid Java program that does nothing.

public class HelloWorld {
    public static void main(String[] args) {
        // Write your code here
Copyright © All rights reserved. | MoreNews by AF themes.