Reserved Words


Reserved Words:

In Java some words are reserved to represent some meaning and functionality. such type of words are called Reserved Words.

java keywords
Keywords Catagory

There are following 53 reserved word in Java:-

1.Reserved literals(3):- if the reserved words only to represent some value is called reserved literals.
a.true
b.false
c.null(default value for object reference.)
these are only reserved literals.

keywords(50):-there are 50 keywords in Java. if the reserved word associated with functionality is called keywords.

Unused keywords:
there are 2 keywords are unused in java.
a.goto
b.const
these are considered as keywords in java but not useful.
Used keywords:
there are 48 keywords in java which are useful in java.these keywords are followings-
Data type keywords(8):
byte, short, int, long, char, boolean, float, double

Control flow Keywords(11):
if, else, switch, case, default, while, do, for, break, continue, return

Modifiers(11):
public, private, protected, abstract
, static, final, native, synchronized, strictfp(1.2 came in version), transient, volatile
default is by default keyword so as 12 keywords.

Exception Based Keywords(6):
try, catch, finally, throw, throws, assert(came in 1.4 version)

Class related keywords:(6)
class, interface, extends, implements, import, package

Object related keywords(4):
new, instanceof, super, this, import, import,

Other keywords:
void
enum(came in 1.5 version)


Note: All 53 reserved words in java contains only lower case alphabet symbol.

java reserved word
Reserved Words



Identifiers

Identifiers
Identifiers:
A name in Java Program is called Identifier. which can be used for identification purpose.
it can be method name, variable name, class name or level name.

example:
                     
    class Simple{  
           
          public static void main(String args[]){ 
                       
                             int x=0; 
                             System.out.println("Hello Java");  
         }  
   }
following are identifiers:-
1.Simple(1st identifier)
2.main()(2nd identifier)
3.String[](3rd identifier)
4.args(4th identifier)
5.x(5th identifier)

As we have seen above that there are five identifiers in this program.
As above mentioned that it can be variable(x,args), it can be method name(main), it can be class name (Simple,String)

There are following Rules for defining java identifiers:
1. Allowed character in Java identifier
a-z(lowercase)
A-Z(uppercase)
0-9(any digits)
_(underscore)
$

if we use another character then compiler will give error.
example:

test_name(accepted)
test$(accepted)
test#(error) only $ and _ are acceptable special characters for identifiers in Java.

2. Identifiers should not start with digits.
test123(accepted)
123test(error)

3.Java identifiers are case sensitive and also Java language is a case sensitive programing language. example:-
int id=0; int Id=0; int ID=0; All cases are different in java program but all acceptable.
4. There is no length limit for Java identifiers but it is not recommended to take too lengthy identifiers.

int xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=0;
(accepted but not recommended)

int mobileNumber=0;
(accepted and recommended because it is simply understandable)


5. Reserved word are not allowed for identifiers.
int x=90;(accepted)
int for=0;(not accepted)

so we can not use keyword as identifiers.

6. All Java predefine classes and interfaces name can use as identifiers.

int String=456;
int Thread=777;

but not recommended because they reduce readability and creates confusion.

which are following identifiers are valid or invalid ?

count_line(valid)
count#(invalid)
count123(valid)
123count(invalid)
count$(valid)
c_o_u_n_t(valid)
count*count(invalid)
count123value(valid)
int(invalid)
Integer(valid)
Int(valid)
$count$(valid)
1count$(invalid)