Hello world program of Java -Explained

Hello world

//program that every developer loves to execute
class Hello {
	public static void main(String args[]){
		System.out.println("Hello world");
	}
}

When you compile and run your program you will get the output as 

Hello world
//program that every developer loves to execute

This is a comment. Like most other programming language java also allows us to write comment which will not be executed while running the program.

Java supports three types of comments single line comment, multiline comments and documentation comment. Above comment is single line comment.

class Hello {

Here class is a keyword which declares the new class. Hello is the name of class which is also known as identifier. The entire class definition, including all of its members, will be between the curly braces {}.

public static void main(String args[]){

This is the line at which the program will begin executing

All java applications begin execution by calling main()

The public keyword is an access specifier, which allows the programmer to control the visibility of class member. class preceded by public keyword can by accessed by the code outside the class in which it is declared.

The keyword static indicates that the particular member belongs to a type itself, rather than to an instance of that type. Means only one instance of main() is created which is shared across all instances of the class.

The void keyword tells the compiler that main() does not return any value.

main() is the method called when a Java application begins.

String args[] declares a parameter named args, which is an array of instance of the class String. args receives any command-line arguments present when the program is executed.

System.out.println("Hello world");

this line outputs the string "Hello world" followed by a new line on the screen.

In System.out System is predefined class that provides access to the system, and out is the output stream that is connected to the console.

println()displays the string which is passed to it. It can also be used to display other types of information too on the output console.

println() statment ends with a semicolon. All statements in java ends with a semicolon. The above program only has one statement. 

A block of code is written inside curly braces {}.


Hope you liked the new code snippets!


Complete Guide to Execute your java program

Comments

YouTube

Popular posts from this blog

GTU OOP Programs - 11

Mini project ideas for Operating System

GTU OS Program - 8