Java Day 12

Source: Internet
Author: User

Package
Compilation format javac-d. **.java

Access between packages
Class not found: Class name is wrong, package name. Class Name
Package does not exist: Specify Classpath
Class for other packages cannot be accessed: permissions public

Protected

Package Imports Import
Principle: Which class to use, and which class to import

Jar Package
JAR-CF Aha.jar.

Specify the class file in Classpath,jar for the jar to run directly

Multithreading
Procedure in progress in progress
A control unit in the thread process that is responsible for program execution

Pros and cons
Run simultaneously
Thread Multi-efficiency low

Multithreading creation-inheriting the thread class
Create thread mode One: Inherit the thread class
1. Define class and Inherit
2. Override the Run method in the thread class
3. Creating Threads
4. Start thread

Defined in the Run method is the task code that the thread will run
Because you are running a custom task code, you need to override the

Method thread name in the thread class
CurrentThread (). GetName ();

Graphic

1 classthreaddemo{2      Public Static voidMain (string[] args) {3Demo A =NewDemo ("Xiao Qiang");4Demo B =NewDemo ("Wancai");5 A.start ();6 B.start ();7          for(intx=0;x<5;x++){8System.out.println (",,, x=" +x+ "... name:" +Thread.CurrentThread (). GetName ());9         }Ten     } One } A  - classDemoextendsthread{ -     PrivateString name; the Demo (String name) { -         Super(); -          This. Name =name; -     } + Demo () {} -      +      Public voidrun () { A          for(intx=0;x<10;x++){ atSystem.out.println (",,, x=" +x+ "... name:" +Thread.CurrentThread (). GetName ()); -         } -     } -}

Java Day 12

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.