Sunday, September 5, 2010

Java in the qualifiers to use summary

Java language defines a public, protected, private, abstract, static and final modifiers commonly used outside the 6 also defines five less commonly used modifiers, the following are Java modifiers of this 11 presentation:

1.public

Use the object: class, interface, members of the

Description: Whether it is in the package are defined in which, the class (interface, members) are accessible

2.private

Using Object: Members

Description: Members of the definition can only be accessed in its class


3.static

Use the object: class, method, field, initialization function

Description: famous for the static inner class is a top class, it includes members of the class is not relevant. Static method class method, are pointing to their class rather than class. Static field is the class field, no matter where the class of the field to create a number of instances, there is only one instance of the field is pointing to their class rather than class. Initialization function is executed in the loaded class, rather than creating an instance of time-consuming.

4.final

Use the object: class, method, field, variable

Description: The definition of the class is not allowed into the final sub-category, can not be covered (not used in dynamic query), field values are not allowed to be modified.

5.abstract

Use the object: class, interface, methods

Description: Class includes methods not implemented, can not be instantiated. If it is a abstract way, the method body is empty, the method of implementation is defined in subclasses, and includes an abstract method of abstract class type must be a

6.protected

Using Object: Members

Description: Members of the definition it can only be accessed package, if the other package is accessed, the class must implement this method is that the members of their class, subclass.

7.native

Using Object: Members

Description: associated with the operating platform, the definition does not define the method, method of implementation is an external library implementation.

8.strictfp

Use the object: class, method

Description: strictfp modified class hides all of the methods strictfp modifiers, methods, implementation of all the floating-point calculations to comply with IEEE754 standard, all values, including the middle of the results must be expressed as the float or double type, not used by the local platform floating-point format or hardware to provide the additional accuracy or that the scope.

9.synchronized

Using Object: Methods

Description: For a static method, before the implementation of the jvm to lock it in the class; for a non-static class methods, the implementation of a particular object instance before the lock.

10.volatile

Use the object: the field

Description: Because asynchronous thread can access the field, so there is certainly no role in optimizing operation on the field. volatile can sometimes substitute synchronized.

11.transient

Use the object: the field

Description: field is not part of persistent state objects, fields and objects should not be strung together.

No comments:

Post a Comment