In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the function of java modifier". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the function of java modifier".
Basic grammar
When writing Java programs, you should pay attention to the following points:
Case-sensitive: Java is case-sensitive, which means that the identifier Hello is different from hello.
Class name: for all classes, the first letter of the class name should be capitalized. If the class name consists of several words, the first letter of each word should be capitalized, such as MyFirstJavaClass.
Method name: all method names should start with lowercase letters. If the method name contains several words, the first letter of each subsequent word is capitalized.
Source file name: the source file name must be the same as the class name. When saving a file, you should use the class name as the file name (keep in mind that Java is case-sensitive), with the suffix .java. (if the file name and class name are different, it will result in a compilation error.)
Main method entry: all Java programs are executed by the public static void main (String [] args) method.
Introduction: according to the different modified objects, Java modifiers are divided into class modifiers, method modifiers and variable modifiers, each of which is divided into access control modifiers and non-access control modifiers. Reasons for the existence of access control: a, making it impossible for client programmers to touch parts they should not touch, and allowing library designers to change the way classes work without having to worry about affecting client programmers
1. Class modifier
Access modifier: public class modifier public
Non-access control characters: abstract class modifier abstract, final class modifier final
(1) the public class modifier public: in the Java language, only the public access control character for a class is public. One and only one class of each Java program is public, which is called
Is the main class, and other external classes have no access control modifiers and have package accessibility. Note: the inner class of a class can be used by other access control modifiers protected, default,
Private modifier, equivalent to a member of a class.
(2) Abstract class modifier abstract: a class modified with the abstract modifier is called an abstract class.
(3) the final class modifier final: when a class cannot be inherited, it can be modified to the final class with the modifier final. Classes defined as final are usually fixed classes that are used to accomplish something
A class of standard functions.
(4) Class default access control character: if a class does not have an access control character, it has default access control character characteristics. At this point, this class can only be accessed or referenced by classes in the same package.
This access feature is also known as package accessibility.
two。 Method modifier
Access control modifiers: public access control character public, protected access control character protected, default, private access control character private
Non-access control characters: abstract method control character abstract, static method control character static, final method control character final, local method control character native,
Synchronous method control character synchronized
(1) Abstract method control character abstract: a method modified with the modifier abstract is called an abstract method. Abstract methods have only method headers and no method body and operation implementation.
(2) static method controller static: a method modified with the modifier static is called a static method. Static methods are class methods that belong to the entire class; they are not decorated or qualified by static
Is a method that belongs to a specific class object Because the static method belongs to the entire class, it cannot manipulate and handle member variables that belong to an object, but can only handle
Member variables that belong to the entire class, that is, the static method can only handle the domain of static.
(3) the final method controller final: the method modified with the modifier final is called the final method. The final method is a method whose functions and internal statements cannot be changed, that is, the final method cannot be overridden.
Guy. Final fixes the function and operation of the method, prevents the subclass of the current class from misdefining the key methods of the parent class, and ensures the security and correctness of the program. All by
Methods whose private modifiers are private, as well as all methods contained in the final class (the final class), are considered final methods.
(4) the local method controller native: a method modified with the modifier native is called a local method. In order to improve the running speed of the program, it is necessary to write the program in other high-level languages.
Method body, then the method can be defined as a local method decorated with the modifier native.
(5) synchronization method control character synchronized: this modifier is mainly used for coordination and synchronization in multithreaded programs.
3. Variable modifier
Access control characters: public access control character public, protected access control character protected, default default access control character default, private access control character private
Non-access control characters: static domain modifier static, final domain modifier final, volatile (shared) domain modifier volatile, temporary domain modifier transient
(1) the public access control character public: the domain modified with public is called the public domain. Because the public modifier reduces the security of the operation and the encapsulation of the data, it should generally be reduced
Reduce the use of public domains.
(2) Private access control character private: member variables (fields) modified with private can only be accessed by the class itself, and cannot be referenced by any other class (including subclasses).
(3) protect the access control character protected: member variables modified with protected can be referenced by three categories: ① class itself; ② other classes in the same package; and ③ other packages.
A subclass of the. The main purpose of using the modifier protected is to allow subclasses in other packages to access specific properties of the parent class.
(4) default modifier: member variables without an access control modifier or modified with the modifier default can be accessed by the class itself or by other classes in the same package.
(5) static domain modifier static: the member variable modified with static only belongs to the class variable, not to any specific object. The value of the static member variable is stored in the class.
The common storage unit of the storage area, rather than in the memory interval of an object. Any object of this class accesses it with the same data; any object of this class modifies
It also operates on the same memory unit.
(6) the final domain modifier final: the final domain modifier final is used to define constants. If the domain (member variable) of a class is specified by the modifier final, its value is in the program
It remains the same throughout the execution process.
(7) the volatile (shared) domain modifier volatile: the volatile (shared) domain modifier volatile is used to indicate that this member variable may be controlled and modified by several threads. That is to say
In the process of running the program, this member variable may be influenced or changed by other programs. Volatile is usually used to modify fields that accept external input.
(8) the temporary domain modifier transient: the temporary domain modifier transient is used to define a temporary variable. It is characterized by a temporary change defined by the modifier transient
Quantity, the Java virtual machine is specified to determine that the temporary variable is not in a permanent state to achieve the archiving function of different objects. Otherwise, all variables in the class are one of the permanent states of the object
Section, you must save these variables at the same time when you store the object.
4. Summary of access control modifiers
Thank you for your reading, the above is the content of "what is the function of java modifier". After the study of this article, I believe you have a deeper understanding of what the function of java modifier is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.