We have already learnt about the keywords defination , different keywords and some important points about it in the previous post about Keywords and Identifiers in Java.
Now , after seeing all that keywords you must be feeling What do they do ? or What are their functions. In this post , we have put all the functions of all the 50 keywords in a tabular format.
Table of Keywords and
their descriptions :-
(-Each type is arranged
alphabetically-)
|
||
Class ,Method and Variables modifiers
|
1.
abstract
|
Used
to declare a class or method to be abstract. It signifies something empty. It
is used to declare a class or method without any implementation. Object of a
abstract class cannot be instantiated ,but can be extended by other classes.
|
2.
class
|
Used
to define a class.
We
have discussed class in detail. Click here.
|
|
3.
enum
|
Used
to declare an enumerated type.
|
|
4.
extends
|
Used
in sub-class declaration to specify the super class/parent class to the sub-class.
|
|
5.
final
|
Used
to define an entity that cannot be changed or extended later.
|
|
6.
implements
|
Used
in class declaration to specify one or more interfaces that are implemented
by the current class.
|
|
7.
interface
|
Used
to declare a special type of class that only contains abstract methods, constant
fields which are static or final and static interfaces.
|
|
8.
native
|
Used
to show that the implementation is not done in the same source file and ,also
, it is in different language.
|
|
9.
new
|
Used
for object creation and providing memory to it , generally , on heap.
|
|
10. static
|
Used
to declare a method, field or inner class as class members rather object
members.
|
|
11. strictfp
|
Used
to ensure portability by restricting the precision and rounding of floating
points in Java.
|
|
12. synchronized
|
Used
to ensure that at a time only one thread can be accessed by a method by using
mutex lock.
|
|
13. transient
|
Used
to prevent fields from being serialized. Transient fields are always skipped
when objects are serialized.
|
|
14. volatile
|
Indicates
that a variable may be modified by concurrently running threads. It can also be
called as a lock-free mechanism.
|
|
Flow Control
|
15. break
|
Used
to exit the current enclosing block or skip the immediate statement. Actually
, it transfers the flow of program to the other part of program.
|
16. case
|
Used
within switch statements. It executes a block of code depending on the switch
expression .
|
|
17. continue
|
Used
to resume program execution at the end of the current loop body.
|
|
18. default
|
Used
within the switch statement. Executes a block of code , if none of the value
of case keywords is matching with the switch statement value.
|
|
19. do
|
Executes
a block of code one time and then based on the while statement determines will that block of code be executed
again.
|
|
20. else
|
Executes
a block of code when the if condition is not true.
|
|
21. for
|
Used
to define a loop that reiterates statements. The for loop specifies the
statements to be executed , exit condition , updating operations and initialization variables for the loop.
*A
new concept of "enhanced for loop"
has been specified where each iteration of the loop executes block of code using
a different element in the array or Iterable.
|
|
22. if
|
Used
to a conditional test and executes a block of code if the test evaluates to
true . If it evaluates to false , an optional block of code is defined with
the else keyword .
|
|
23. instanceof
|
Used
to check an object belongs to which class. The instanceof evaluates to true
if an object belongs to a specified class or its super class; else raises
compilation error.
|
|
24. return
|
Used
to finish the execution of method. It can be followed by a value to pass to
the caller method.
|
|
25. switch
|
Used
to evaluate a variable that can later be matched with a value specified by
the case keyword in order to
execute a block of statements.
|
|
26. while
|
Used
to execute a block of code in loop if given logical boolean expression evaluates to true.
|
|
Special Reference
Keywords
|
27. super
|
Reference
variable referring to immediate super class / parent class.
|
28. this
|
Reference
variable referring to the instance of current object.
|
|
Access Modifiers
|
29. private
|
Used
to make method or variable accessible only within its own class.
|
30. protected
|
Used
to make method or variable accessible only to classes in same package or to subclasses(derived
class) of the class.
|
|
31. public
|
Used
to make method or variable accessible to everybody.
|
|
Primitives
|
32. boolean
|
Used
with variable that can have value as true or false only.
|
33. byte
|
An
8-bit signed integer.
|
|
34. char
|
An
Unicode character(16-bit unsigned integer).
|
|
35. double
|
An
64-bit signed floating-point number.
|
|
36. float
|
An
32-bit signed floating-point number.
|
|
37. int
|
An
32-bit signed integer.
|
|
38. long
|
An
64-bit signed integer.
|
|
39. short
|
A
16-bit integer value
|
|
Error Handling
|
40. assert
|
Evaluates
a conditional expression to verify the programmer’s assumption. If the
condition is not true, an AssertionError is thrown. Generally used for
debugging purpose.
|
41. catch
|
Declares
a block of code that executes if exception occurs .
|
|
42. finally
|
Block
of code that follows try block code
and executes no matter how exception is handled.
|
|
43. throw
|
Used
to pass an exception to method that called this method
|
|
44. throws
|
Used
to specify which exceptions are not handled in the method and will be passed
on to the next higher level of the program.
|
|
45. try
|
Used
with the block of code that will be tried for execution, but which may cause
an exception.
|
|
Package Control
|
46. import
|
Used
at the beginning of a source file to declare what packages or classes are to
imported.
|
47. package
|
Used
to keep classes together which have a relation between them.
|
|
Void keyword
|
48. void
|
Used
to indicate that the method does not have a return type.
|
Keywords unused
|
49. const
|
Not
used. 'final' keyword can be used
in place of this keyword.
|
50. goto
|
Not
used.
|
So we have learnt the functions of all the 50 keywords present in Java programming langauge.
Don't worry , if you did not understand the meaning of all the above stuff. We will be learning the working of all of them as and when they come in further programs.
KEEP COMPILING !!
Keywords in Java
Reviewed by shashank
on
13:13
Rating:
Great Explanation of keywords in Java .Thanks !!
ReplyDeleteThanks !! Keep Following JavaCompile for more stuff.
Delete