Sunday, 14 August 2016

Reserved words in Java (day 2)

RESERVED WORDS:

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

Reserved words are divided into two categories.They are

1.keywords(50) - If the Reserved word associated with Functionality then those words are Keywords.

  In this 48 are used Keywords and remaining 2 are unused Keywords.
  The 2 unused keywords are goto and const
  The 48 used keywords are  if,else,switch,..........

2.Reserved Literals(3) - If the reserved word associated with only to value not functionality then  those are Reserved Literals.

 The 3 Reserved Literals are  true,false,null.

Keywords for data types:

1.byte
2.short,
3.int
4.long
5.float
6.double,
7.boolean
8.char

Keywords for flow control:

1.if
2.else
3.switch
4.case
5.default
6.while
7.do
8.for
9.break
10.continue
11.return

Keywords for modifiers:

1.public
2.private
3.static
4.final
5.abstract
6.synchronized  
7.Protected
8.volatile
9.transient
10.native
11.strictfp(1.2v)

Keywords for Exception:

1.try
2.catch
3.finally
4.throw
5.throws
6.assert(1.4v)

class related Keywords:

1.class 
2.interface
3.extends
4.implements
5.import
6.package

Object related Keyword:

1.new
2.instanceof
3.super
4.this

return type keyword:

1.void 
In Java, return type is mandatory.If a method won't return anything then we have to declare that method void return type.
But in C language return type is optional and default return type is int.


Unused Keywords:

 1.goto: Usage of 'goto' create a several problems in old languages and hence some people banned this keyword in java.

2.const: Use final instead of  'const'.

Note: goto and const are unused keywords and if we are trying to use will get compile time error.


Reserved Literals:

'true','false' values for boolian data type 
'null' default value for Object reference

enum keyword(1.5v):

we can use enum to define a group of named constant
 
Ex:  enum month

       {
       JAN,FEB,MAR,...,DEC;
       } 


Conclusions:

1.All 53 reserved words contains only alphabets.
2.All 53 reserved words contains only lower case alphabets.
3.In Java we have only 'new' keyword and there is no 'delete' keyword because destruction of useless objects is the responsibility of garbage Collector.
4.The following are new keywords in Java
    a.strictfp (1.2v)
    b. assert(1.4v)
    c.enum(1.5v) 
5.instanceof          but not    instanceOf
   strictfp               but not    strictFp
   synchronized     but not    synchronize
   implements        but not    implement
   import                but not    imports
   const                  but not    constant 
 


 

 





No comments:

Post a Comment

If you Like my blog Spread it and help friends for whom this blog is useful for their career.