Small Java Programs

This chapter discusses naming and coding conventions as well as reserved words in Java. When you go through this chapter, you'll get some hands-on experience with writing in Java.

17. Many-line Comments


Answer:

No. The compiler ignores comments when creating the bytecodes.
Comments are just for human readers of the source program.

Many-line Comments

/* Program 1
Write out three lines of a poem.
The poem describes a single moment in time,
using 17 syllables.
*/ public class Haiku { public static void main ( String[] args ) { System.out.println("On a withered branch" ); System.out.println("A crow has just alighted:"); System.out.println("Nightfall in autumn."); } }


Often you want to write a comment that spans several lines, as above.

With this style of comment, everything between the two characters /* and the two characters */  are ignored by the compiler.

The / and the *  must not have any character between them. There can be many lines of comments between the /* pair and the */  pair.

The /* and the */  can start and stop anywhere on a line. Everything between the pair is a comment ignored by the compiler.


Question 17:

Is the following correct?
public class Haiku
{
  public static void main ( String[] args )
  {
    System.out.println /* print a line containing the following string */ ("On a withered branch" );
    System.out.println("A crow has just alighted:");
    System.out.println("Nightfall in autumn."); 
  }
}