OO Programming with Java


Hello World !

As another complement, it is usual to add comments into code to describe what is a class for, the behavior of an operation, etc. These comments can then be exploited to generate the HTML documentation of a code with the javadoc tool. In particular, the Java API is documented in this way and is available here.

  1. Add comments in Person.java:
/**
 * Sample class that does greetings.
 **/
public class Person {
	/**
	 * Sample operation/method.
	 * @param s : person's name to say 'Hello'
	 **/
	public void sayHello(String s) {
		System.out.println("Hello "+ s +" !");
	}
}

Create a doc directory and generate documentation:

mkdir doc
javadoc -d doc src/hello/*.java

Now, take a look at the generated documentation at doc/index.html.


10 - 17