Java Introduction

Java Hello World Program

 A "Hello, World!" is a simple program that produces "Hello, World!" on the screen. Since it is a very simple program, it is often used to introduce a new programming language to a beginner.
Let's explore how Java "Hello, World!" program works.
If you want to run this program on your computer, make sure that Java is correctly installed. Additionally, you need an IDE (or text editor) to write and edit Java code. For that

Java "Hello world!"


// Your First Program

class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!"); 
    }
}

The output will be:


Hello, World!

Comment Java "Hello, World!" Does the program work?

// Your First Program


In Java, any line starting with // is a comment. Comments are intended for users reading the code to better understand the intent and functionality of the program. It is completely ignored by the Java compiler (an application that translates the Java program into Java bytecode that the computer can run). To learn more, see the Java comments.

class HelloWorld { ... }


In Java, every application begins with a class definition. In the program, HelloWorld is the name of the class and the definition of the class is:

class HelloWorld {
... .. ...
}

For now, just remember that every Java application has a class definition and the class name must match the filename in Java.

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


This is the main method. Every application in Java must contain the main method. The Java compiler starts executing code from the main method.

How it works? Good question. However, we will not discuss it in this article. After all, it is a basic program for introducing the Java programming language to a beginner. We will learn the meaning of public, static, empty and how do the methods work? in the following chapters.

For now, just remember that the primary function is the entry point to your Java application, and is required in a Java program. The signature of the main method in Java is:

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


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

The following code prints the quoted string Hello, World! to standard output (your screen). Note that this statement is inside the main function, which is inside the class definition.

Things to take away

  • Every valid Java application must have a class definition (which is the filename).
  • The primary method must be inside the class definition.
  • The compiler runs the codes from the main function.
  • It is a valid Java program that does nothing.

public class HelloWorld {
    public static void main(String[] args) {
        // Write your code here
    }
}
Don't worry if you don't understand the meaning of class, statics, methods, etc. for the time being. We will discuss this in detail in the following chapters.

Comments

Most View Post

Java Data Types (Primitive)

Java operators

Java Basic Input and Output

Java Expressions, Statements and Blocks

Java JDK, JRE and JVM