Java string optimization
The final keyword in Java can be used in class members (not called domains), in class methods, and in classes.
The final is used in the domain to represent:
1, a constant amount of compilation that never changes.
2, a value that is initialized at run time, and you don't want it to be changed.
The static keyword can be used in conjunction with the
1.static Final (constant)There are two ways to initialize:(1) Initialize at the time of declarationStatic final i = 1;You can also set the return value of a static method to itStatic Final int i = f (); Static Public int f () { return 1;}(2) initialization in the static Code fast (in general, if some code must be executed when the project is started, it is
resources in the software during class loadingApplication Scenarios:
Often used to load static resources (pictures, audio, etc.)
2.3.1 Casepublicclass StaticKeywords { // 定义了一个静态块 static { // 存储在方法区中,在类加载的时候执行的代码块 System.out.println("静态块执行"); } publicstaticvoidmain(String [] args) { }}// 执行结果 静态块执行 // main函数中没有任何代码,但是还是打印了静态块的语句,说明静态块在所有类实例化之前执行3. Final keywordFinal-Modified member variables and me
Package Com.victor.test;import Java.util.random;public class Staticandfinaltest {private static random Rand = new Random ( ;p rivate static int statica = Rand.nextint (+);p rivate final int finalb = Rand.nextint (+);p rivate static final int s Taticfinalc = Rand.nextint (+);p ublic static void Main (string[] args) { staticandfinaltest saft1 = new Staticandfina Ltest (); System.err.println ("Saft1.stat
Java Memory Model-final, java model-final
Compared with the locks and volatile described earlier, the read and write operations on the final domain are more like common variable access. For final domains, the compiler and processor must follow two reordering rules:
Below, we will illustrate these two rules through some
Java study notes 18 --- final keywords modify variables, methods, and classes, study notes 18 --- final
The word final in English is known as "final". In fact, it also means"Unchangeable". In Java,The final keyword is "unchangeable" to better explainThat is, the
Final modifier, final Modifier
When final modifies a variable, it indicates that the variable cannot be changed once the initial value is obtained,The final variable cannot be assigned a new value after obtaining the initial value. Therefore, the final modification of the m
2016/09/21 Java keyword final, 2016 final1. final class
The final class cannot be inherited and has no subclass. The methods in the final class are final by default.
The final class cannot be inherited. Therefore, the member metho
Final Class A {}, so that the defined Class A is the final class, the final class cannot be inherited, that is, the code cannot be written, class B extends a {}.final void B () {}, the method defined is the final method, and the final
If we do not want a class to be inherited, we use final to modify the class. This class cannot be inherited. Final --- used before classes and methods.
Final Class --- cannot be inherited.
Final method --- cannot be overwritten.
The final class cannot be inherited.If we do
If we do not want a class to be inherited, we use final to modify the class. This class cannot be inherited. Final --- used before classes and methods.
Final Class --- cannot be inherited.
Final method --- cannot be overwritten.
The final class cannot be inherited.If we do
Final can be modified: properties, methods, classes, local variables (variables in methods)The initialization of a final decorated property can be initialized at compile time, or at run time, after initialization, the JVM assigns it to a constant pool, and the program cannot change its value;The final decorated properties are related to the specific object, and t
http://blog.csdn.net/qq1623267754/article/details/36190715Final can be modified: properties, methods, classes, local variables (variables in methods)The initialization of a final decorated property can be either at compile time or at run time, and cannot be changed after initialization.The final decorated properties are related to the specific object, and the final
Disclaimer: this blog is an original blog and cannot be reproduced without permission! If you see it in other places, it is recommended to take a look at csdn (the original link for the http://blog.csdn.net/bettarwang/article/details/26744661), read the code and ask questions, discussion is more convenient.
In Java, final is mainly used in three aspects: Variable modification, modification method and modification class. The role of
/*Final (final, modifier) Final keyword usage: 1. When the final keyword modifies a variable of a primitive type, the variable cannot be re-assigned, and the first value is final. 2. When the FIANL keyword modifies a reference-type variable, the variable cannot be re-dire
Interview question: when a variable is modified using the final keyword, can the reference not be changed, or can the referenced object not be changed ?, Final keywords
/** Question: when you use the final keyword to modify a variable, whether the reference cannot be changed or the referenced object cannot be changed * answer: * when you use the
JAVA final keyword, constant definition, final keyword
Final (final) is a modifier1. final can be used to modify classes, functions, and variables (member variables, local variables)2. Classes modified by final cannot be inherite
When you learn Java, you are often confused by modifiers, which summarize the difference between static final and final.1, static emphasis only one copy, final description is a constant, final definition of the basic type of the value is immutable, but the value of the reference object defined by the fianl can be chang
Final---Used for classes, methods, and before.
The final class---cannot be inherited.
The final method---not be overwritten.
The final class cannot be inherited.If we do not want a class to be inherited, we use final to modify the class. This class will not be inherited. Fo
class modifier
Final
When final is applied to a class, this class is qualified as a non-inheritable class, that is, other classes cannot inherit this class, and the final class, when you do not want others to inherit their own written class, only need to precede the final keyword to
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.