Reserved words: In java some identifiers are reserved to associate some functionality or meaning such type of reserved identifiers are called reserved words.
Diagram:
Reserved words for data types:
1) byte2) short
3) int
4) long
5) float
6) double
7) char
8) boolean
Reserved words for flow control:
1) if
2) else
3) switch
4) case
5) default
6) for
7) do
8) while
9) break
10) continue
11) return
Keywords for modifiers:
1) public
2) private
3) protected
4) static
5) final
6) abstract
7) synchronized
8) native
9) strictfp(1.2 version)
10) transient
11) volatile
Keywords for exception handling:
1) try
2) catch
3) finally
4) throw
5) throws
6) assert(1.4 version)
Class related keywords:
1) class
2) package
3) import
4) extends
5) implements
6) interface
Object related keywords:
1) new
2) instanceof
3) super
4) this
Void return type keyword:
• If a method won’t return anything compulsory that method should be declared with the
void return type in java but it is optional in C++.
Unused keywords:
goto: Create several problems in old languages and hence it is banned in java.
Const: Use final instead of this.
• By mistake if we are using these keywords in our program we will get compile time
error.
Reserved literals:
1) true values for boolean data type.
2) false
3) null----------------- default value for object reference.
Enum:
• This keyword introduced in 1.5v to define a group of named constants
Example:
enum Beer
{
KF, RC, KO, FO;
}
Note: All reserved words in java contain only lowercase alphabet symbols.
New keywords are:
Strictfp-----------1.2
Assert-------------1.4
Enum--------------1.5
Which of the following list contains only java reserved words?
1) final, finally, finalize (invalid)//here finalize is a method in Object class.
2) throw, throws, thrown(invalid)//thrown is not available in java
3) break, continue, return, exit(invalid)//exit is not reserved keyword
4) goto, constant(invalid)//here constant is not reserved keyword
5) byte, short, Integer, long(invalid)//here Integer is a wrapper class
6) extends, implements, imports(invalid)//imports keyword is not available in java
7) finalize, synchronized(invalid)//finalize is a method in Object class
8) instanceof, sizeOf(invalid)//sizeOf is not reserved keyword
9) new, delete(invalid)//delete is not a keyword
10) None of the above(valid)
Which of the following are valid java keywords?
1) public(valid)
2) static(valid)
3) void(valid)
4) main(invalid)
5) String(invalid)
6) args(invalid)
Which of the following list contains only java reserved words?
1) final, finally, finalize (invalid)//here finalize is a method in Object class.
2) throw, throws, thrown(invalid)//thrown is not available in java
3) break, continue, return, exit(invalid)//exit is not reserved keyword
4) goto, constant(invalid)//here constant is not reserved keyword
5) byte, short, Integer, long(invalid)//here Integer is a wrapper class
6) extends, implements, imports(invalid)//imports keyword is not available in java
7) finalize, synchronized(invalid)//finalize is a method in Object class
8) instanceof, sizeOf(invalid)//sizeOf is not reserved keyword
9) new, delete(invalid)//delete is not a keyword
10) None of the above(valid)
Which of the following are valid java keywords?
1) public(valid)
2) static(valid)
3) void(valid)
4) main(invalid)
5) String(invalid)
6) args(invalid)
Comments
Post a Comment