Statements and Comments

Statements

Java programs are made up of Statements, and they end with a semi-colon, not when line ends. You may write the statement in a single line or multiple lines, that doesn’t matter.

package com.techstackjournal;
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!!!");
    }
}

Statements allow white-spaces like space characters, tab characters and new-line characters in between the parts of it as above.

Comments

Comments are usually lines of text written inside a Java program, that Java doesn’t compile.

Developers can write some notes on a complex code explaining what is that code all about.

It can also be used to hide the source code temporarily, without actually deleting it.

There are 3 different types of comments:

Line Comments

Line comments are comments that are start with double backslash (//) and ends with newline.

package com.techstackjournal;

public class App {
	public static void main(String[] args) {
		// line comment
		System.out.println("Hello World!!!"); // line comment
	}
}

Block Comments

Block Comments begin with “/*” and ends with “*/”. Compiler ignores everything written between these comments.

They can comment text of multiple lines or even middle of a line.

package com.techstackjournal;

public class App {
	public static void main(String[] args) {
		/* 
		 block comments
		 block comments
		*/ 

		System.out.println(/* block comment */ "Hello");
		System.out.println("Hello"); /* block comment */
	}
}

Javadoc Comments

Javadoc comments begin with “/**” and ends with “*/”, typically written on top of a class or a member of class. These comments are exclusively for writing Java documentation which can be generated using javadoc utility command.

package com.techstackjournal;

/**
 * This is program demonstrates javadoc comments.
 * 
 * @author Admin
 *
 */
public class HelloWorld {

	/**
	 * This is an entry point for this application.
	 * 
	 * @param args
	 *            Values from command-line
	 * 
	 */
	public static void main(String[] args) {
		System.out.println("Hello World!!!");
	}

}

After copying this to IDE, just hover around class and method to see these Javadoc comments appearing in popup.