Tuesday, October 16, 2012

Java Keywords


Keywords

There are certain words with a specific meaning in java which tell (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 (Taken from Sun Java Site). All the keywords are in lowercase.
    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


/** 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
}
}

Some Tricky Observations: The words virtual, ifdef, typedef, friend, struct and union are all words related to
the C programming language. const and goto are Java keywords. The word finalize is the name of a method
of the Object class and hence not a keyword. enum and label are not keywords.

No comments:

Post a Comment