StackTips

Stepping Into My First Java Program “Hello World!”

stacktips avtar

Written by

Editorial,  5 min read,  2.5K views, updated on March 05, 2024

Before begin writing your first Java program, you need to have your development environment ready. For writing and executing Java program, you need the latest version of Java SDK installed installed and configured on your machine;

Now, let us create an example class that simply prints “Hello World!” on standard output terminal.

/* My first java program prints “Hello World!” */
class HelloWorldApp {  
    public static void main(String[] args) { 
       //Prints string hello world 
        System.out.println("Hello World!");  
    }  
}

The “Hello World!” application consists of three primary components:

  1. Source code comments
  2. The HelloWorldApp class definition
  3. The main method

Source Code Comments

Comments are ignored by the compiler but are useful for readability purpose. The Java programming language supports three kinds of comments such as, single line, multiline and documentation type comments.

  • // text – The compiler ignores everything from // to the end of the line.
  • /* text */ – This indicates multiline comments. The compiler ignores everything from /* to */.
  • /** documentation */ – This indicates a documentation comment (doc comment, for short). The compiler ignores this kind of comment, just like it ignores comments that use /* and */.

The following bold text defines the comments of the “Hello World!” application:

/* My first java program prints “Hello World!” */
class HelloWorldApp {  
    public static void main(String[] args) { 
        //Prints string hello world 
        System.out.println("Hello World!");  
    }  
}

The HelloWorldApp Class Definition

The following bold text begins the class definition block for the “Hello World!” application:

/* My first java program prints “Hello World!” */
classHelloWorldApp {  
    public static void main(String[] args) { 
        //Prints string hello world 
        System.out.println("Hello World!");  
    }  
}

As shown above, the most basic form of a class definition is class <Class Name> followed by curly braces. The keyword class begins the class definition for a class named name, and the code for each class appears between the opening and closing curly braces marked in bold above.

The main Method

The following bold text begins the definition of the main method:

/* My first java program prints “Hello World!” */
class HelloWorldApp {  
    public static void main(String[] args) { 
       //Prints string hello world 
        System.out.println("Hello World!");  
    }  
}

Java Collection APIs

The Collections framework in Java defines numerous different data structures in which you can store, group, and retrieve objects.

>> CHECK OUT THE COURSE

Keep exploring

Let’s be friends!

🙌 Stay connected with us on social media for the latest updates, exclusive content, and more. Follow us now and be part of the conversation!