What are java modifiers?
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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Square Root in Java. Here we discuss how Square Root works in Java with example and its code implementation respectively.

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.
