Modifiers |
Can be used on |
Meaning |
Abstract |
Class |
Abstract class contains
unimplemented methods. And it cannot be instantiated |
Method |
Abstract method has
only signature no implementation. The containing
class is abstract |
Interface |
All interfaces are
abstract |
Static |
Class |
Make an inner class
top-level class |
Method |
A static method is
invoked through the class name. A static method
can access only static variables. Also Static
methods may not be overridden to be non-static. |
Variables |
Static variables are
initialized at class load time. A class has
only one copy of these variables. |
Free floating code-block
(static initializer) |
Run when the class
is loaded, rather than when an instance is created. |
Native |
Can be applied to methods only. (Static
methods also) |
It means method is written in a non-Java
language, compiled for a single machine target
type. Native doesn't affect access qualifiers.
Native methods can be private.You can pass/return
Java objects from native methods |
Final |
Class |
Final classes cannot
be sub-classed |
Method |
Final methods cannot
be overridden |
Variables |
Final variables cannot
be changed. (Either a value has to be specified
at declaration or an assignment statement can
appear only once). |
Field |
Cannot change its value.
Static final fields are compile-time constants. |
Synchronized |
Can be applied to methods or parts of methods
only. |
Used to control access to critical code
in multi-threaded programs. .For a static method,
a lock for the class is acquired before executing
the method. For a non-static method, a lock
for the specificobject instance is acquired. |
Volatile |
Can be applied to variables, static variables
but NOT final variables |
Declaring a variable volatile indicates
that it might be modified asynchronously, so
that all threads will get the correct value
of the variable.Used in multi-processor environments |
Transient |
Can be applied to class level variables
only.(Local variables cannot be declared transient) |
Transient variables may not be final or
static.(But compiler allows the declaration,
since it doesn't do any harm. Variables marked
transient are never serialized. Static variables
are not serialized anyway.) Not stored as part
of object's persistent state, i.e. not written
out during serialization. Can be used for security. |