Java modifiers are used to define classes, methods or variables, and are usually placed at the front of the statement. (Recommendation: java video tutorial)
Java language provides many modifiers, mainly divided into the following two categories:
Access modifier
non Access modifiers
The Java language defines 6 commonly used modifiers, including public, protected, private, abstract, static and final, and also defines 5 less commonly used modifiers. The following is a description of these Java modifiers. Introduction:
1. Public objects used: classes, interfaces, members Introduction: No matter where the package in which it is located is defined, the class (interface, member) is accessible.
2. Private usage object: Member introduction: Members can only be accessed in the class in which they are defined.
3. Static uses objects: classes, methods, fields, and initialization functions. Introduction: The inner class named static is a top-level class, which is not related to the members of the containing class. Static methods are class methods that are pointed to the class to which they belong rather than to instances of the class.
Static fields are class fields. No matter how many instances are created by the class in which the field is located, there is only one instance of this field that points to the class to which it belongs rather than an instance of the class. The initialization function is executed when the class is loaded, not when the instance is created.
4. Objects used by final: classes, methods, fields, variables Introduction: Classes defined as final do not allow subclasses, cannot be overwritten (should not be used for dynamic queries), and field values are not allowed to be modified. .
5. Abstract usage objects: classes, interfaces, methods Introduction: Classes include unimplemented methods and cannot be instantiated. If it is an abstract method, the method body is empty, the implementation of the method is defined in the subclass, and the class containing an abstract method must be an abstract class.
6. Protected use object: Member introduction: A member can only be accessed in the package in which it is defined. If it is accessed in other packages, the class that implements this method must be a subclass of the class to which the member belongs. .
7. Native usage object: Member introduction: It is related to the operating platform. Its method is not defined when it is defined. The implementation of the method is implemented by an external library.
8. Objects used by strictfp: Class, method introduction: All methods in the class modified by strictfp hide the strictfp modifier. All floating point calculations performed by the method comply with the IEEE754 standard, and all values include intermediate results. All must be represented as float or double types without taking advantage of the additional precision or representation range provided by the native platform floating point format or hardware.
9. Objects used by synchronized: Method introduction: For a static method, the jvm locks the class it is in before execution; for a non-static class method, a specific object instance is locked before execution.
10. Volatile usage objects: Field introduction: Because asynchronous threads can access fields, some optimization operations must not be applied to fields.
Volatile can sometimes replace synchronized.
11. Transient usage objects: Field introduction: Fields are not part of the persistent state of the object, and fields and objects should not be strung together.
For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of What are java modifiers?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
