1.02 Reserved Words
In Java some words are reserved to represent some meaning or functionality such type of words are called Reserved Words
Reserved Word | Description |
---|---|
null | |
true | |
false | |
const | |
goto | |
byte | |
short | |
int | |
long | |
float | |
double | |
boolean | |
char | |
if | |
else | |
switch | |
case | |
default | |
while | |
do | |
for | |
break | |
continue | |
return | |
public | |
private | |
protected | |
static | |
final | |
abstract | |
synchronized | |
assert | |
native | |
strictfp | |
transient | |
volatile | |
try | |
catch | |
throw | |
throws | |
finally | |
assert | |
package | |
import | |
class | |
interface | |
extends | |
implements | |
new | |
instanceof | |
super | |
this | |
void | Specifies that a method does not have a return value |
enum |
NOTE 01
- In java return type is mandatory, if a method doesn’t return anything then we have to declare the method with void return type.
- Usage of goto created several problems hence it is banned in Java.
- Use final instead of const
- The keywords const and goto are reserved, even they are not currently in use.
- We can use
enum
to define a group of named constants.
Example of enum:
enum month {
JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEPT,OCT,NOV,DEC
}
Conclusions
- All 53 reserved words contains
lower-case alphabets
onlyinstanceof, strictfp
- In Java we have only
new
keyword and there is nodelete
keyword because destruction of useless objects is the responsibility of Garbage Collector. -
The following are newly added Keywords in Java:
strictfp
assert
enum
NOTE 02
strictfp
but notstrictFp
instanceof
but notinstanceOf
synchonized
but notsynchronise
extends
but notextend
implements
but notimplement
import
but notimports
const
but notconstant
TEST
Q. Which of the following lists contains only Java reserved words?
Sr. No. | word |
---|---|
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 Above |
Answers
Sr. No. | word | Answer |
---|---|---|
1. | new, delete | delete is not a keyword in Java |
2. | goto, constant | const is keyword, constant is not a keyword |
3. | break, continue, return, exit | exit is not a keyword in Java (Method) |
4. | final, finally, finalize | finalize is not a keyword in Java |
5. | throw, throws, thrown | thrown is not a Keyword in Java |
6. | notify, notifyAll | both are not Java Keywords. (Methods) |
7. | implements, extends, imports | imports is not a Java Keywords |
8. | sizeof, instanceof | sizeof is not a Java Keyword |
9. | instanceOf, strictFp | Java keywords contain lower-case alphabets only |
10. | byte, short, Int | Java keywords contain lower-case alphabets only |
11. | None of Above | Solution: No list contains Java keywords only. |
Q. Which of the following are Java reserved words?
public, static, void, main, String, args
:
First three only. String is a ‘pre-defined’ class name.