// This is the Hello World program in Java
class HelloWorld {
public static void main (String args[]) {
/* Now let's print the line Hello World */
System.out.println("Hello World!");
} // main ends here
} // HelloWorld ends here
The /* */
style comments can comment out multiple lines so they're useful when you want to remove large blocks of code, perhaps for debugging purposes. //
style comments are better for short notes of no more than a line. /* */
can also be used in the middle of a line whereas //
can only be used at the end. However putting a comment in the middle of a line makes code harder to read and is generally considered to be bad form.Comments evaluate to white space, not nothing at all. Thus the following line causes a compiler error:
int i = 78/* Split the number in two*/76;
Java turns this into the illegal line
int i = 78 76;
not the legal line
int i = 7876;
This is also a difference between K&R C and ANSI C.