Print Hello world in Java

0
Share

Print Hello World in Java

To understand a programming language you must practice the programs, this way you can learn the language faster, In this tutorial you will be learn how to print ‘Hello world’ or anything in java .

  • The ‘Hello world’ is most common , simple and the basic program in every programming language.
  • In every programmer to learn any programming he/she can first run the most basic program to print anything.
  • To run java program we required an editor and a compiler, so we can use both online compiler and offline compiler that are installed in your machine.

Requirement to to print hello world in java Program

Print “Hello World” code

public class First_program
{
    public static void main(String arg[ ])
    {
        System.out.println("Hello World");
        System.out.println("Anything you can print here");
    }
}

Output:
Hello World
Anything you can print here

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).

Parameters used in First Java Program

Let’s see what is the meaning of class, public, static, void, main, String[], System.out.println().

  • class keyword is used to declare a class in java.
  • public keyword is an access modifier which represents visibility. It means it is visible to all.
  • static is a keyword. If we declare any method as static, it is known as the static method. The core advantage of the static method is that there is no need to create an object to invoke the static method. The main method is executed by the JVM, so it doesn’t require to create an object to invoke the main method. So it saves memory.
  • void is the return type of the method. It means it doesn’t return any value.
  • main represents the starting point of the program.
  • String[] args is used for command line argument. We will learn it later.
  • System.out.println() is used to print statement. Here, System is a class, out is the object of PrintStream class, println() is the method of PrintStream class. We will learn about the internal working of System.out.println statement later.

How many ways can we write a Java program

There are many ways to write a Java program. The modifications that can be done in a Java program are given below:

1) By changing the sequence of the modifiers, method prototype is not changed in Java.

Let’s see the simple code of the main method.

static public void main(String args[])  

2) The subscript notation in Java array can be used after type, before the variable or after the variable.

Let’s see the different codes to write the main method.

public static void main(String[] args)  
public static void main(String []args)  
public static void main(String args[]) 

3) Havi3) You can provide var-args support to the main method by passing 3 ellipses (dots)

see the code:

 public static void main(String... args)  

3) Having a semicolon at the end of class is optional in Java.

see the code:

class Hello{  
static public void main(String... args){  
System.out.println("hello java  World");  
}  
}; 

Invalid main method writing process

public void main(String[] args)  
static void main(String[] args)  
public void static main(String[] args)  
abstract public static void main(String[] args)  

Valid main Method writing process

public static void main(String[] args)  
public static void main(String []args)  
public static void main(String args[])  
public static void main(String... args)  
static public void main(String[] args)  
public static final void main(String[] args)  
final public static void main(String[] args)  
final strictfp public static void main(String[] args)  

Read More related post

  • What are the List of CSS3 New Features ?
    CSS3 is the latest version of the normal CSS . CSS3 adds several new styling features and improvements to enhance the web presentation capabilities. Text Effect in...
  • CSS Basic Property
    What is CSS ? CSS stands for Cascading Style Sheets. CSS basically used in designing the web tags & pages. CSS is the most popular used...
  • Java Program to swap two number use 3rd variable
    In this program, you’ll learn to Program to swap 2 number with 3rd variable in Java. After write the code, the final output is displayed on...
  • Java program to multiply two floating point number
    In this program, you’ll learn to Program to multiply two floating point number in Java. After write the code, the final output is displayed on the...
  • Java Program to find the ASCII value of a character
    In this program, you’ll learn to Program to find the ASCII value of a character in Java. After write the code, the final output is displayed...

Subscribe

Sign up for our newsletter and stay up to date

*
%d bloggers like this: