Demystifying Hello World in Java !

Majority of the folks in the programming community start with the plain old “Hello World” when experimenting with a new language.

Let’s print “Hello World” in PHP.

<?php 
echo "Hello World";
?>
<?="Hello World"?>

In JavaScript :

console.log("Hello World");

Let’s enter the Java World.

public class DemoClass{  public static void main(String[] args){
System.out.println("Hello World");
}
}
Blueprint of an iPhone 5

Switching to our Hello World Example

public simply implies that the class is visible/accessible to everyone. DemoClass is the name of the class I created.

//public implies the class is accessible to everyone.
public class DemoClass{
//We want our main method to be public since an external agent(outside the class) will call the main method.
//void simply implies the main method does not return any value.
public static void main(String[] args){
//static implies method will be called with the help of Classname
//args
consists of an array of data passed by an external agent
public static void main(String[] args){
//println() is a non-static method in PrintStream class
//We make use of the out instance to call println()
out.println("Hello World");
//public implies the class is accessible to everyone
public class DemoClass{
//public implies the main method is accessible to everyone
//static implies the method can be called with the classname
//void indicates the method does not return any value
public static void main(String[] args){

/
/println is a non-static method inside PrintStream class
//out is an instance of PrintStream class
//out is a static field inside System class
System.out.println("Hello World");
}
}
  • An object is an instance of a class.
  • Functions existing inside a class are called as methods.
  • Variables existing inside a class are called as fields.
  • Static members need to be called with classname.
  • Non-static members need to be called with the instance of the class.

Developer @Shopify