One: Final keyword① final variable : A final variable that is declared final for a member variable or a local variable (a variable in a method or a block of code is called a local variable). The final variable is often used with the static keyword as a constant . The
Original:Http://www.tuicool.com/articles/2YjmqySummarize:The Final variable is in concurrency, and the principle is to re-order the instruction set of the CPU by prohibiting it (reorder the http://ifeve.com/java-memory-model-1/http://ifeve.com/java-memory-model-2/ ) to provide out-of-the-box courseware to ensure secure publication of objects, preventing object references from being taken and used by other threads before the object is fully constructed
The final conceptThe advent of inheritance increases the reusability of code and facilitates development. However, there are problems, some classes do not want to be inherited after the description, or some of the methods in the class function is fixed, do not want subclasses to rewrite. But when the subclass inherits these special classes, it can rewrite the method, how to solve it? To solve the above problems, you need to use a keyword
2.final1) Why is the string final modified?Answer yourself:Answer:Mainly for the sake of "efficiency" and "safety". If string is allowed to be inherited, the performance of the program may be reduced due to its high usage rate, so string is defined as final.There is another explanation:A class with a final modifier is not derived. In the Java Core API, there are many examples of
In the Java keyword,static and final are two of the keywords we have to master. Unlike other keywords, they are used in a variety of ways, and can improve the performance of the program and optimize the structure of the program in a certain environment.1.FIANL variablesThe FIANL keyword can be used to declare a variable, and once the variable is set, the value of the variable cannot be changed, and the defined variable must be assigned at the time of
For the final keyword in Java, we can first understand the literal meaning, Baidu translation shows as follows: In other words, the final English meaning is final and cannot be changed. The corresponding meaning is also expressed in Java, you can use the final keyword to modify variables, methods, and classes. Whateve
Classname.methodname.
For static variables and static methods that are frequently used, you can import them statically. The advantage of static import is that you can simplify some operations, such as output statement System.out.println (); The out is the static variable of the System class, which can be java.lang.system.* by import static; Import it, the next time you call OUT.PRINTLN () directly.
Take a look at the following code:
Import static java.lang.system.*;
Import static java
Java final variable, javafinal
Final variable definition: Once initialized, variables cannot point to other objects. The address to which the object belongs cannot be modified, but the object to which the address belongs can be modified.Let's first talk about final variable initialization:Many articles have said this: the initialization can be in two places: one
Java keyword static, final usage summaryStatic1. Static variablesThere are two ways to classify a class member variable statically: A variable that is statically modified, called a static variable or a class variable, and another variable that is not modified by static, called an instance variable. The difference is that there is only one copy of the static variable in memory (memory saving), the JVM allocates only one memory at a time, completes the
[JAVA] final modifier Field, javafinalfield
I. Introduction
The final modifier can be used to modify variables, methods, and classes. The final variable cannot be changed once it is assigned a value.
Ii. final member variables
Member variables are initialized with class initialization or object initialization. When the
Document directory
Final data
Final arguments
Final Methods
Final classes
In the sense of final keywords, they cannot be changed. There are two reasons for creating final keywords: 1. design 2. for efficiency (this part is
Learning the static and final Keywords of Java, javastaticfinal
Static: (static modifier) the content of static modifier in Object-Oriented objects belongs to classes rather than objects. Therefore, static modifier member variables are generally called class member variables, static modification is generally called a class method.
Category:
1. static variables, also known as static variables or class variables. The other is a variable that is not modi
One. FinalMeaning: Adj. final, Final; The decisive; Non-changing. In Java is a reserved keyword that can declare member variables, methods, classes, and local variables. Once you have the reference declaration as final, you will not be able to change the reference, the compiler will check the code, and if you attempt to initialize the variable again, the compiler
One: final type modifier in Java(0)finally although in English grammar is final adv. form, the two are very similar, but the Java application environment is quite different. (1) Final classThe final class cannot be inherited, so the member methods of the final class have no
method name () is called.It is important to note that during the loading and initialization of classes, the data with static is loaded and called first, followed by the constructor's loading, and finally the normal member variables and methods are loaded.Usage of final keyword Final means "immutable" and is generally applied to data, methods, and classes.Final dataWhen the data is a basic type, it means t
In Java, when declaring classes, variables, and methods, you can use the keyword final to decorate. Final modified data has "end state" characteristics, which means "final" meaning. Specific provisions are as follows:
The final decorated class cannot be inherited.
The
Sealed and final modifiers are not actually a product of a language platform, they have their own locale, but these two keywords are. NET platform, then the use of both geometry, with this article to explore.I.SealedThe sealed modifier can be applied to classes, instance methods, and properties. When used in a class, the class is called a sealed class, and the sealed class cannot be inherited; When used in a method, the method is called a sealing meth
The final modifier and Javafinal modifier in Java
1. When can I select the final modifier?
If you want to prevent a class from being inherited by other classes and are not allowed to have child classes, you should consider using final for modification.
2. Classes modified with final
First, you must understand that the
code exampleImport java.util.*;Import static net.mindview.util.print.*;Class value{int i;Public Value (int i) {this.i=i};}public class finaldata{private static Random rand=new random (47);Private String ID;Public FinalData (String id) {this.id=id; }Private final int valueone=9;//privately final memberprivate static final int value_two=99;//static private
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.