Java Keywords and Identifiers

In this chapter you will learn:

  1. Get to know the full list of keywords in Java
  2. How to use legal identifiers

Full list of keywords in Java

A keyword is a word whose meaning is defined by the programming language. Java keywords and reserved Words:

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

An identifier is a word used by a programmer to name a variable, method, class, or label. Keywords and reserved words may not be used as identifiers. An identifier must begin with a letter, a dollar sign ($), or an underscore (_); subsequent characters may be letters, dollar signs, underscores, or digits.

Some examples are:


foobar          // legal
Myclass         // legal
$a              // legal
3_a             // illegal: starts with a digit
!theValue       // illegal: bad 1st  char
//from   ww  w.  j  a  v a2s. c  o  m

Java Identifiers are case sensitive. For example, myValue and MyValue are distinct identifiers.

Using identifiers

Identifiers are used for class names, method names, and variable names. An identifier may be any sequence of uppercase and lowercase letters, numbers, or the underscore and dollar-sign characters. Identifiers must not begin with a number. Java Identifiers are case-sensitive. The following code illustrates some examples of valid identifiers:


public class Main {
  public static void main(String[] argv) {
    int ATEST, count, i1, $Atest, this_is_a_test;
  }//from ww w. j a v  a 2  s .com

}

The following code shows invalid variable names include:


public class Main {
  public static void main(String[] argv){
     int 2count, h-l, a/b, 
// ww w.j  a v  a 2 s  .  c om
  }
}

If you try to compile this code, you will get the following error message:

Next chapter...

What you will learn in the next chapter:

  1. How to declaring a variable
  2. How to use Assignment Operator
  3. How to initialize a variable dynamically
Home »
  Java Tutorial »
    Java Langauge »
      Java Hello World
Your first Java program
Your second Java program
Java Keywords and Identifiers
Java Variable