Exercise 2

(1)
Describe 3 types of comment in Java and explain their differences.

(2)
Does every java class have a main method?
What is the significance of the main method?
Circle the correct way(s) of writing the main method.
  1. private static void main(String[] args)
  2. public int main(String[] args)
  3. public static void main()
  4. public static void main(int[] args)
  5. public static void main(String[] args)
  6. public int main()
  7. static void main(int[] args)


(3)
Consider the following program,
 public  class HelloHi {
    public static void main(String[] args) {
             System.out.println("Hello " + args[0] );
	     System.out.println("Hi " + args[1]);
       }
}
(a)Circle the correct file name(s) of this program and explain your answer.
  1. HelloHi.java
  2. HelloHi.class
  3. HelloHi.ja
  4. HelloHi
  5. hellohi.java
  6. Hello.java
  7. hi.java
(b) What are the outputs of the following commands, explain your answers.
  1. java HelloHi Charles Dianne
  2. java HelloHi "Charles Li" Dianne
  3. java HelloHi Charles Li Dianne
  4. java HelloHi "Charles Li" "Dianne Patterson" "Amy Johnson"
  5. java HelloHi "Charles Li" Patrick "Dianne Patterson" "Amy Johnson"
  6. java HelloHi 1234 5678 1111
  7. java HelloHi Charles
(4)
Save the following program in an empty folder.
public class CommentTest {
    /** method1 prints out Hi on the screen*/
    public void method1() {
	System.out.println("Hi");
    }
    
    /** method2 prints out Hello name on the screen */
    public void method2(String name) {
	System.out.println("Hello " + name);
    }  
}
(a) type javadoc CommentTest.java at the DOS prompt. What happens? Are there any new file created?
(b) type explorer index.html at the dos prompt to open internet explorer or click on index.html file icon. Can you see the document?
(c) Replace the comment /** ...... */ by /* ........*/, repeat (a) and (b), can you recognize any difference?