0% found this document useful (0 votes)
7 views3 pages

Java Hello World Program Explained

The document explains the Java 'Hello, World!' program, which is a basic introduction to Java programming. It outlines the structure of the program, including the class definition, main method, and print statement. Key points include the necessity of a class definition matching the filename and that execution starts from the main method.

Uploaded by

Shari Husain
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Java Hello World Program Explained

The document explains the Java 'Hello, World!' program, which is a basic introduction to Java programming. It outlines the structure of the program, including the class definition, main method, and print statement. Key points include the necessity of a class definition matching the filename and that execution starts from the main method.

Uploaded by

Shari Husain
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Hello World Program

A "Hello, World!" is a simple program that outputs Hello, World! on the


screen. Since it's a very simple program, it's often used to introduce a new
programming language to a newbie.
Let's explore how Java "Hello, World!" program works.

Java "Hello, World!" Program

// Your First Program

class HelloWorld {
public static void main(String[] args) {
[Link]("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


intended for users reading the code to understand the intent and
functionality of the program. It is completely ignored by the Java
compiler (an application that translates Java program to Java
bytecode that computer can execute). To learn more, visit Java
comments.
2. class HelloWorld { ... }

In Java, every application begins with a class definition. In the


program, HelloWorld is the name of the class, and the class definition
is:

3. class HelloWorld {

4. ... .. ...

For now, just remember that every Java application has a class
definition, and the name of the class should match the filename in
Java.
5. 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 the code from the
main method.

How does it work? Good question. However, we will not discuss it in


this article. After all, it's a basic program to introduce Java
programming language to a newbie. We will learn the meaning
of public , static , void

For now, just remember that the main function is the entry point of
your Java application, and it's mandatory in a Java program. The
signature of the main method in Java is:
6. public static void main(String[] args) {

7. ... .. ...

8. [Link]("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.
Notice the print 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 that


matches the filename (class name and file name should be same).

• The main method must 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
}
}

Don't worry if you don't understand the meaning of class , static , methods,
and so on for now. We will discuss it in detail in later chapters.

You might also like