Categories: Java

Simple Hello World Program

Requirement for Java Hello World Program:
Hello World Example:
class Hello{  
    public static void main(String args[]){  
     System.out.println("Hello World! Coderzpy");  
    }  
}  

Save the above file as Hello.java.

In the terminal:

To compile:javac Hello.java
To execute:java Hello
Output:
Hello World! Coderzpy
Parameters used:

Let’s look at what class, public, static, void, main, String[], and System.out.println mean ().

  • In Java, the class keyword is used to declare a class.
  • The visibility is represented by the public keyword, which is an access modifier. It means that it is visible to everyone.
  • static is a keyword. Any method that is declared as static is referred to as a static method. The main advantage of the static method is that it does not require the creation of an object to use. Because the main() method is executed by the JVM, there is no need to create an object to call it. As a result, it conserves memory.
  • The method’s return type is void. It indicates that it does not return any information.
  • The program’s starting point is represented by main.
  • The command line argument is String[] args or String args[]. We’ll go over it in the next section.
  • To print a statement, use System.out.println(). System is a class, out is a PrintStream class object, and println() is a PrintStream class method. In the following section, we’ll look at how the System.out.println() statement works internally.
Compilation Flow:

The Java compiler converts source code into byte code when we compile a Java program with the javac tool.

Note: We can also use other editors like the eclipse(https://www.eclipse.org/downloads/), also read about the JDK vs JRE vs JVM

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Share
Published by
Rabecca Fatima

Recent Posts

Find Intersection of Two Singly Linked Lists

You are given two singly linked lists that intersect at some node. Your task is…

12 hours ago

Minimum Cost to Paint Houses with K Colors

A builder plans to construct N houses in a row, where each house can be…

3 days ago

Longest Absolute Path in File System Representation

Find the length of the longest absolute path to a file within the abstracted file…

3 weeks ago

Efficient Order Log Storage

You manage an e-commerce website and need to keep track of the last N order…

1 month ago

Select a Random Element from a Stream

You are given a stream of elements that is too large to fit into memory.…

1 month ago

Estimate π Using Monte Carlo Method

The formula for the area of a circle is given by πr². Use the Monte…

2 months ago