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

Generate Parenthesis | Intuition + Code | Recursion Tree | Backtracking | Java

Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…

2 months ago

Square Root of Integer

Given an integer A. Compute and return the square root of A. If A is…

1 year ago

Build Array From Permutation

Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…

1 year ago

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is…

1 year ago

DSA: Trie

What is a Trie in DSA? A trie, often known as a prefix tree, is…

1 year ago

Trees: Lowest Common Ancestor

What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…

1 year ago