Keyword in Java

In this section, we will discuss on the Keyword in Java in details.


  • Identifier
  • Reserved Word
  • Naming convention of identifier
  • What is Keywords in Java
  • Use of Keywords in Java
  • Reserved Word

Before going into depth of the Keyword, we need to understand the naming convention of variable. As Java is strongly typed language, variable / identifier must be declared before used it.

How you will name the identifier ?

There are some protocol which need to be keep in mind when you are declaring the variable.

  1. Identifier/ variable should not be start with a number.
  2. I can contain the character [A-Z], [a-z], numbers [0-9].
  3. @ should not be used for declaring the identifier.
  4. Variable names should not contain space in between the name.
  5. It should not contain the Reserved keyword like float, int etc.
  6. Identifier/ variable should not contain below character.
    • (                      
    • )
    • {
    • }
    • /
    • \
    • [
    • ]
    • *
    • +
    • ,
    • ;
    • #
    • %
    • !
    • ^
    • .
  7. $ and _ can be used to declare the identifier.

Let’s take a quick assessment to check the valid identifier name.

  1. Myname = Valid
  2. myname = Valid
  3. id5 = Valid
  4. 5id = Invalid
  5. A = Valid
  6. ABC = Valid
  7. My name = Invalid
  8. My-name = invalid
  9. A&B = Invalid
  10. Float = Invalid

Reserved Keyword:

As we checked that variable name should not contain the reserved keyword in java.

What is Reserved Keyword?

From the name you can guess that Reserved keywords are reserved for some functions. So it can not be used to name the variable. If you use the reserved keyword in identifier name then it will throw an error.

Every keyword has its own meaning of functionality. Literals defines the value of the keyword.

Keyword in Java

Keywords in Java:

There are many keyword available in java which has different action defined in java. Let’s discuss some of them below.

  1. abstract : This is used to declare the class as abstract. Abstract class has only abstract method. It does not contain any body. It is only a signature. Its implementation is declared in child class.
  2. assert : If you want to verify the value with the specifier value, then you need to use assert keyword. It is introduced in J2SE 1.4 version.
  3. boolean: Boolean is the primitive data type. This contains only 2 values. i.e TRUE & FALSE.
  4. break : This is used to break the statement in loop or switch case to achieve certain target.
  5. byte : Like Boolean this is also a primitive data type. 0 is the default value for the byte data type.
  6. case : This is used in switch case loop to check certain condition.
  7. catch : In Exception handling in java, catch is used to handle the exception. If you want to handle some IOException then in catch statement only you need to declare that will be the instruction to be executed.
  8. char : char is a primitive data type which contain the unicode character in quote.
  9. class – class is the keyword through which user can create the user  defined

Leave a Reply

Your email address will not be published. Required fields are marked *