"1, basic grammar"
second, class member method modifier 1, method modifier function: Control access to member methods. 2. Modifiers for eight methods: public, protected, private, static, final, abstract, native, synchronized public, protected, private, static, Final in the previous article has been explained, here is not to repeat.
modifier Description: Abstract abstraction methods, abstract classes: Abstract abstract methods, abstract and interface can be used to abstract classes, abstract class is a single inheritance, interface can implement multiple. From a grammatical point of view, there is no difference between the two, can be used to abstract classes, from the design level, it follows the ISP (Interface segregation priciple) follow OCP (Open-close principle), to open up, to modify the closure of the principle. Implement OCP: Abstraction, inheritance, interface, polymorphism.
native JNI (Java Native Interface) that uses Java to interact with locally compiled code. The writing step for JNI: Write a Java class with the native method; Use the Javac command to compile a Java class with a native method; use Javah? JNI Java class name that generates a header file with an. h extension, a local method using C/n + + (or another language), and a written file to generate the key words in the dynamic-link library Java native analysis
Synchronized Two uses: Synchronized method, Synchronized block
public static void Main (string[] args} {
int times = 1000;//1000 secondary access
thread [] thread = new Thread[times];
for (int i=0; i<times; i++) {
thread[i] = new Thread (new Runnable () {
@Override public
void Run () {
Sync Hronizedtest.t.storemoney (m);
try {
thread.sleep (1000);
} catch (Interruptedexception e) {
e.printstacktrace ();
}
Synchronizedtest.t.getmoney (MB);
}
);
Thread[i].start ();
}
System.out.println ("wait!");
for (int i=0; i<times; i++) {
try {
thread[i].join ();
} catch (Interruptedexception e) {
E.printstacktrace ();
}
System.out.println ("final:" + Synchronizedtest.amount);
}
The result would be strange: wait!
final:1500 wait!
final:1300
wait!
final:1400
The results of three executions were different. Optimization details. A detailed description of the thread, and the use of synchronized.