KEYWORDS IN JAVA

The Java programming language has total of 50 reserved keywords which have special meaning for the compiler and cannot be used as variable names. Following is a list of Java keywords in alphabetical order, click on an individual keyword to see its description and usage example.

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
Some noteworthy points regarding Java keywords:
  • const and goto are resevered words but not used.
  • truefalse and null are literals, not keywords.
  • all keywords are in lower-case.


The following table shows the keywords grouped by category:

Categorys
Keyword
Access modifiers
private, protected, public
Class, method, variable modifiers
abstract, class, extends, final,
implements, interface, native,
new, static, strictfp, synchronized, 
transient, volatile
Flow control
break, case, continue, default, 
do, else, for, if, instanceof, 
return,switch, while
Package control
import, package
Primitive types
boolean, byte, char, double, 
float, int, long, short
Error handling
assert, catch, finally, throw, 
throws, try
Enumeration
enum
Others
super, this, void
Unused
const, goto

  1. //example of this keyword  

  1. class Student11{  
  2.     int id;  
  3.     String name;  
  4.       
  5.     Student11(int id,String name){  
  6.     this.id = id;  
  7.     this.name = name;  
  8.     }  
  9.     void display(){System.out.println(id+" "+name);}  
  10.     public static void main(String args[]){  
  11.     Student11 s1 = new Student11(111,"Karan");  
  12.     Student11 s2 = new Student11(222,"Aryan");  
  13.     s1.display();  
  14.     s2.display();  
  15. }  
  16. }  
Output111 Karan
       222 Aryan

No comments:

Post a Comment