Tutorialspoint

1 Answer
Samual Sam
, 0 Views

Keywords in Java are reserved words that represent predefined actions, internal processes etc. Because of this, keywords cannot be used as names of variables, functions, objects etc.

The main difference between keywords and identifiers is that keywords are reserved words that represent predefined actions while identifiers are the names of variables, functions, objects etc.

Some of the keywords in the Java are given as follows −

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

A program that demonstrates keywords is given as follows −

Example

Live Demo

public class Example  {
   public static void main(String[] args) {
      int i = 5;
      char c = 'A';
      System.out.println("i = " + i);
      System.out.println("c = " + c);
   }
}

Output

i = 5
c = A

Now let us understand the above program.

The keywords in the above program are int and char that specify integer and character data types respectively. Also i and c are identifiers.

In the above program, the values of i and c are defined and then they are printed. The code snippet that demonstrates this is given as follows.

int i = 5;
char c = 'A';
System.out.println("i = " + i);
System.out.println("c = " + c);

Advertisements