Java Keywords and Comments

This topic of the Java discusses about the keywords and comments for the Java programming language. Once we get these basic language concepts we can continue with the other object-oriented programming language concepts.

 

Keywords

There are certain words with a specific meaning in Java which tell (i.e. help) the compiler what the program is supposed to do. These Keywords cannot be used as variable names, class names, or method names. Keywords in Java are case sensitive, all characters being lower case.

Keywords are reserved words that are predefined in the language; see the table below. All the keywords are in lowercase.

Table 1: Java Keywords

abstract    default    if            private       this
boolean     do         implements    protected    throw    
break       double     import        public       throws    
byte        else       instanceof    return       transient    
case        extends    int           short        try    
catch       final      interface     static       void    
char        finally    long          strictfp     volatile    
class       float      native        super        while    
const       for        new           switch    
continue    goto       package       synchronized

 

The “keywords” are marked in red color as shown in the sample code below:

HelloWorld.java

/**
* This class is a Hello World Program used to introduce the Java Language
*/
public class
HelloWorld {
  public static void main(String[] args)  {
      System.out.println("Hello World"); //Prints output to console
  }
}

 

Comments

Comments are descriptions that are added to a program to make code easier to understand. The compiler ignores comments and hence it’s only for documentation of the program. Java supports three comment styles:

  • Block style  comments begin with /* and terminate with */ that spans multiple lines.
  • Line style  comments begin with // and terminate at the end of the line (Shown in the above program).
  • Documentation style comments begin with /** and terminate with */ that spans multiple lines. They are generally created using the automatic documentation generation tool, such as javadoc (shown in the above program).