Thursday, 18 April 2013

How to Add Comments in Java

There are two ways to include comments in your Java code:
  • You can add one or more single-line comments by starting each line with two forward slashes.
  • You can add a multi-line comment by starting it with /* and ending it with */.
You can see what I mean in the program source code below:

UBUNTU > cat Andrew_Was_Here.java
// This is a one-line comment.
// You can do a multi-line comment as shown below:
/*
Humpty Dumpty sat on a wall.
Humpty Dumpty had a great fall.
All the king's horses and all the king's men
Couldn't put Humpty together again.
*/
public class Andrew_Was_Here
  {
  public static void main(String args[])
    {
    System.out.println("Andrew was here!");
    }
  }
UBUNTU >