[Java multithreading] correct use of volatile keywords, multi-thread volatile
The volatile variable hassynchronizedBut not Atomic. In a multi-threaded environment, variables using the volatile keyword can only read the latest modified variable values when reading variables from different threads, however, when modifying the variable value, thread security cannot be ensured (there may be a write value overwr
num;static int staticnum;//transient keyword is a transient string pwd;transient int NUM0 that cannot be serialized; Serializabletest (string name, int num, int staticnum, String pwd, int num0) {this.name = Name;this.num = Num;this.staticnu m = staticnum;this.pwd = PWD;THIS.NUM0 = NUM0;} Public String toString () {return "name=" + name + ", num=" + num + ", staticnum=" + Staticnum + ", pwd=" + pwd + ", num0=" + N UM0;}}Output Result:Name=str,num=12,staticnum=1,pwd=null,num0=0False5. Relationshi
inner class in the code above Carwindow 's Show () method is changed to a static method, the following modifications are made in the main () method:Public staticvoid Main (string[] args) {Car.CarWindow.showCarWindow (); }The result of the operation is:The color of the car glass is black. Although static methods for accessing static inner classes are simple to use, they are limited when defined as static. As mentioned in the previous article, static methods can only access static members, so it
1, the concept of keywordsKeywords: In fact, a language has given special meaning to the word.Reserved words: In fact, there is no special meaning, but prepare the words to be used later.2.theJava language has A keyword, you cannot use the reserved keyword to name a class, method, or variable1, data type boolean int long short byte float double char class interface 2. Process ControlIfElse Do while forSwitch Casedefault BreakContinuereturnTryCatchfinally3. Modifier Publicprotecte
Packagejava_test;/** Static keyword action: is a modifier that modifies members (member variables, member methods) * Only 1 copies of the member variable after the static modification * When the member is modified by static, there is a way to access it, in addition to being accessible by the object, can also be called directly by the class name ( Class name. static member) **/ /*Static Features: * 1. Loaded with the class * 2. Takes precedence over the existence of an object * 3. is shared by
1. Volatile keyword The Java language provides a slightly weaker synchronization mechanism, the volatile variable. Variables modified by the volatile keyword are not cached in registers or in places that are not visible to other processors, so the most recent value is always returned each time the Volatitle type variable is read, rather than being fetched from the register. Since the locking mechanism ensures visibility and ensures atomicity, volatil
There are two ways to implement multithreading in Java, one is to inherit the thread class, one to implement the Runnable interface, and the thread class to be defined in the Java.lang package. A class that inherits the thread class to overwrite the run () method in this class can implement multithreaded operations, but only one parent class can inherit from a class, which is the limitation of this method.1 Public class extends Thread {2public v
2018-04-30This keywordWhat is this: Represents the current object itself, or an instance of the current class, through which all methods and properties of this object can be called.This is mainly present in two places:1) Constructor: This represents the invocation of the currently created object2) member method: Object A calls the method where this is located, at which point this represents the object aWhen an object is created, the JVM automatically assigns a reference to the current object's t
class.L polymorphic Call method, compile See = left, parent class has, compile succeeded, parent class not, compile failedrun, static methods , run static methods in the parent class,Run, non-static method, overriding method for running subclassesmember variables, compiling run It's all the parent class .Defining static constantsIn development, we want to define a static constant in the class, usually using a variable that is modified by the public static FINAL to complete the definition. At th
First, super keyword use super in the Java class to refer to the composition of the parent class, use this to refer to the current object , and if a class inherits from another class, when we new the instance object of the subclass, there will be a parent class object inside the subclass object. How do you refer to the parent object inside? Using Super to refer to, this refers to a reference to the current object, and super is a reference to the pare
();//housekeeping methods for executing the dog class8 } 9 Else if(AinstanceofCat)//If animal A is a cat class objectTen { OneCat C = (cat) A;//turn animal a strong into cat class AC.catchmouse ();//perform cat-like mouse-catching methods - } -}Example 2:1Object obj = "ABC";//Polymorphic , assigning a String object to the type of object2System.out.println (objinstanceofObject);//true3System.out.println (objinstanceofObject);//true4System.out.println (Obj.getclass ()
Java Learning Series (21) Java object-oriented explanation, java object-oriented
Reprinted please indicate the source: http://blog.csdn.net/lhy_ycu/article/details/45295947
I. Preface
Annotation in Java is used in many aspects, such as @ Test, Spring, SpringMVC, and other
Java multithreading explanation, java Multithreading
1. Return the name of the current Thread: Thread. currentThread. getName ();
2. The Thread name is defined by Thread + number. The number starts from 0.
3. The code to be run by the thread is stored in the run method.
4. To run a thread, it must be enabled through the method specified in the class. Start () (an
Detailed explanation of how php calls its own java program and how php calls java
This example describes how php calls its own java program. We will share this with you for your reference. The details are as follows:
Jdk should be installed at the beginning. I installed java
There may be a lot of learning Java friends do not know how Java operation, Java Virtual machine is how to work, this article will give you a detailed explanation (JVM) Java virtual machine.
In Java, the concept of virtual machine
Li Qiangqiangon the basis of the previous article, Mason said the next Java I/o: bit operation bitwise Operation . In this story, the Masons take you into the Java in-depth explanation. First, the PrimerIn the Java world, 99% of all jobs are handled at this high level. So where are the binary, bytecode?Self-answer: Whe
Java Garbage Collector standard explanation and usage, java garbage collectionOverview
When talking about Garbage Collection (GC), most people regard this technology as a companion product of the Java language. In fact, GC has a long history than Java. The Lisp, which was bo
JVM Insider: detailed explanation of Java virtual machine, jvm Insider: Java Virtual Machine
This article explains the internal architecture of Java Virtual Machine (JVM. Displays typical JVM core internal components that comply with Java SE 7 specifications.
The displayed
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.