Reserve or Key Words in Java
Any programming language reserves some words to represent functionalities defined by that language. These words are called Reserved words.
These words can't be used as names for Variables, Methods, Class or any other Identifier.
Keywords for Data Types (8):
1. byte
2. short
3. int
4. long
5. float
6. double
7. boolean
8. char
Keywords for Flow control (11):
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 (11):
1. public
2. private
3. protected
4. static
5. final
6. abstract
7. synchronized
8. native
9. strictfp (came in 1.2 version)
10. transient
11. volatile
Keywords for Exceptional Handling (6):
1. try
2. catch
3. finally
4. throw
5. throws
6. assert (came in 1.4 version)
Keywords for Class Related (6):
1. class
2. interface
3. extends
4. implements
5. package
6. import
Keywords for Object Related (4):
1. new
2. instanceof
3. super
4. this
Keywords for Void return type (1):
1. void
- In java return type is mandatory, if a method won’t return anything then we have to declare that method with void return type.
- But in C language return type is optional and default return type is int
Keywords Unused (2):
1. goto
- usage of goto created several problems in old languages and hence SUN people banned these keyword in java.
2. const
- Use final instead of const.
Note:- goto and const are unused keywords and if we are trying to use we will get COMPILE TIME ERROR.
Reserved Words Literals (3):
1. true
2. false
3. null
- true and false are value for boolean data types.
- null is default value for object reference.
enum keyword (came in 1.5 version)
- We can use enum to define a group of named constants.
Ex:-
enum month
{
JAN, FEB, MAR…………DEC.
}
Conclusions:
1. All 53 reserve words in java contains only lowercase alphabet symbols and no digits allowed.
2. In java we have only new keyword and there is no delete keyword because distraction of useless objects is the responsibility of garbage collector.
3. The following are new keywords in java (strictfp, assert, enum).
Question 1: Which of the following list contains only java reserve words?
1. new, delete
2. goto, constant
3. break, continue, return, exit
4. final, finally, finalize
5. throw, throws, thrown
6. notify, notifyAll
7. implements, extends, imports
8. sizeof, instanceof
9. instanceOf, strictFp
10. byte, short, Int
11. None of the above.
Answer: 11. None of the above.
Exit, finalize, notify, notifyAll are methods
Thrown, sizeof, delete doesn’t exits
Question 2: Which of the following are java reserve words?
1. public
2. static
3. void
4. main
5. String
6. args
Answer: 1, 2, 3.
main is name of method.
String is predefined java class.
args is variable name.
Question 3: Which of the following are valid java Reserved words ?
1) int, float, signed, double
2) abstract, final, volatile, virtual
3) new, delete
4) goto, constant, static
5) byte, short, int, long
Answer: 5
Happy Learning !
These words can't be used as names for Variables, Methods, Class or any other Identifier.
Keywords for Data Types (8):
1. byte
2. short
3. int
4. long
5. float
6. double
7. boolean
8. char
Keywords for Flow control (11):
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 (11):
1. public
2. private
3. protected
4. static
5. final
6. abstract
7. synchronized
8. native
9. strictfp (came in 1.2 version)
10. transient
11. volatile
Keywords for Exceptional Handling (6):
1. try
2. catch
3. finally
4. throw
5. throws
6. assert (came in 1.4 version)
Keywords for Class Related (6):
1. class
2. interface
3. extends
4. implements
5. package
6. import
Keywords for Object Related (4):
1. new
2. instanceof
3. super
4. this
Keywords for Void return type (1):
1. void
- In java return type is mandatory, if a method won’t return anything then we have to declare that method with void return type.
- But in C language return type is optional and default return type is int
Keywords Unused (2):
1. goto
- usage of goto created several problems in old languages and hence SUN people banned these keyword in java.
2. const
- Use final instead of const.
Note:- goto and const are unused keywords and if we are trying to use we will get COMPILE TIME ERROR.
Reserved Words Literals (3):
1. true
2. false
3. null
- true and false are value for boolean data types.
- null is default value for object reference.
enum keyword (came in 1.5 version)
- We can use enum to define a group of named constants.
Ex:-
enum month
{
JAN, FEB, MAR…………DEC.
}
Conclusions:
1. All 53 reserve words in java contains only lowercase alphabet symbols and no digits allowed.
2. In java we have only new keyword and there is no delete keyword because distraction of useless objects is the responsibility of garbage collector.
3. The following are new keywords in java (strictfp, assert, enum).
Question 1: Which of the following list contains only java reserve words?
1. new, delete
2. goto, constant
3. break, continue, return, exit
4. final, finally, finalize
5. throw, throws, thrown
6. notify, notifyAll
7. implements, extends, imports
8. sizeof, instanceof
9. instanceOf, strictFp
10. byte, short, Int
11. None of the above.
Answer: 11. None of the above.
Exit, finalize, notify, notifyAll are methods
Thrown, sizeof, delete doesn’t exits
Question 2: Which of the following are java reserve words?
1. public
2. static
3. void
4. main
5. String
6. args
Answer: 1, 2, 3.
main is name of method.
String is predefined java class.
args is variable name.
Question 3: Which of the following are valid java Reserved words ?
1) int, float, signed, double
2) abstract, final, volatile, virtual
3) new, delete
4) goto, constant, static
5) byte, short, int, long
Answer: 5
Happy Learning !
Comments
Post a Comment