Before writing any Java code, let’s understand some basic building blocks of Java.
package io.rizwan;
public class Main {
public static void main(String[] args) {
// print "Hello World" on the console
System.out.println("Hello World");
}
}
System.out.println("Hello World");
is used to print any string that is passed to it on the console.
Detailed Explanation —
System
is a class that has a field called out
which returns a reference, of type PrintStream
. The PrintStream
class has a method called println
which prints the text that is passed as an argument on the new line in the console or terminal.“Hello World”
is passed as an argument in the println
method//
(Double forward slashes). Comments don’t get executed. As a best practice we should comment about why we wrote the block of code instead of what and how.Naming Convention, for Classes — PascalNamingConvention
and for Methods — camelNamingConvention
. Also, Starting curly braces should be on the same line as the method declaration.
<aside> 👨💻
Every statement in Java ends with a semicolon. Java is a case-sensitive language i.e. println
and Println
will be treated differently.
</aside>