1, basic knowledge-basic grammar-2

Source: Internet
Author: User
Tags modifier

"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.



Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.