Java Keywords

Google+
Google+
http://programmingloops.com/java-keywords/

Java keywords have a predefined meaning, start with a small letter, and cannot be use in programs as identifier of class, method, datatype, etc. Java contains around 50 keywords that are use in different sections of the code. Some of these keywords are package, import, class and public. Let us see them in a program.

package p1;
import java.io.*;

public class test
{
       public static void main(String args[]) throws IOException
       {
             String str = “Hello there”;
             System.out.print(str);
       }
}

The above program will run smoothly because it do not use any keyword as an identifier. For instances, class name is “test” and String variable name is “str”, which is okay, since they are not keywords. Some of the keywords use here are package, import, class, static and throws.

Let us see another example.

package p1;
import java.io.*;

public class int
{

       public static void main(String args[]) throws IOException
       {
             String for = “Hello there”;
             System.out.print(str);
       }
}

In this example, keywords are use wrongfully as identifiers, like class name is “int” which is wrong as “int” is a keyword use for identifying the integer datatype, and String variable name is “for”, which is again wrong as “for” is a keyword use for identifying the for-loop. Therefore, this program will not run.

Here are a few more keywords use in Java programming quite frequently.

abstract              boolean              catch              class              do
else              interface              finally              implements              long
native              package              return             short             throw