Today, we have completed the ninth day of the IT program Java Basic Course:
Learning content:
Thread Creation Method
-----------------
1. Thread
Class demo extends thread
{
Public void run ()
{
}
}
2. runnable {public void run ();}
Class man extends person implements runnable {
Public void run (){
...
}
}
New car (). Start ();
New thread (New Man (). Start ();
Differences between implementation and inheritance:
1. the implementation method avoids the limitations of single inheritance in Java.
2. the implementation method separates code from data, reflecting the Object-Oriented Design Philosophy
3. the implementation method ensures that multiple threads operate on the same data and improves code robustness.
Production and consumption problems:
Bees and bears:
Bee and bear are two thread classes, and the operation sharing resource class is honey class.
The key is that the Code should be synchronized during honey operations to avoid the security problem of multithreading.
In terms of production and consumption, wait and consumer y should be used separately for control.
Wait () and policy must be called using the lock flag object, that is, they must be used in synchronization. This lock can be any subclass object of the object class and has the tag function.
The wait () method enables the current thread object to enter the waiting queue, discard the CPU execution right, and release the lock. The thread with the CPU execution right can get the lock. Exception thrown
The Y () method wakes up a thread in the waiting queue and has the CPU execution right to compete.
The yyall () method wakes up all threads in the waiting queue and competes for CPU execution right.
Differences and relationships between wait () and sleep () methods:
1. The wait () method must be used in synchronization. It is called by the flag lock. Sleep () can be called by the thread object at any position of the thread.
The wait () method is in the object, and the sleep () method is in the Thread class.
2. Both the wait () method and the sleep () method make the current thread sleep, but the wait () method releases the lock while the sleep () method does not. Wait until the current thread is sleep.
3. Calling the wait () method will cause the current thread to enter the waiting queue. Only when the Lock Object calls y () or yyall () will it be awakened.
Eclipse
---------------
Alt + // code assist
Alt + up arrow // move up a row
Alt + down arrow // move up a row
Alt + Shift + up arrow // copy a row up
Alt + Shift + down arrow // copy a row down
CTRL + D // delete a row
CTRL + // single line comment
CTRL + Shift + // multi-line comment
CTRL + Shift + f // format the code
Alt + Shift + S // call up the source menu item
CTRL + O // call up the corresponding details
String
-----------------
1. ==/// determine whether the object is the same. Determine the memory address of the object.
2. Equals // determine whether the content of the two objects is the same.
The equals method in the object class is rewritten in the string class to compare whether the content of the string is the same.
Split (string REG); // split according to the specified string and return an array.
Str. Split (",") cut the string by commas and return an array of the corresponding type.
Example: String STR = "SAF, fdsa, fsald ";
String [] Ss = Str. Split (",");
Substring (INT start); // substring operation, which specifies all characters after the start Index
Substring (INT start, int end); // obtains the substring operation, specifying all characters between the start index and the end index,
// Contains the starting index, not the ending index. [A, B) is a semi-open semi-closed interval.
Basic Data Type object Packaging
---------------------------------------------
Byte byte // packaging class
Short short
Int integer
Long long
Float float
Doule double
Boolean
Char character
Bytes B = 127;
Byte B = new byte (127 );
Problems:
1. multithreading production and consumption problems
2. Eclipse and debug
3. Methods of the string class
Problems that require help:
1. Eclipse debugging code and tool usage
2. multi-thread Summary
This article is from the "" blog. For more information, contact the author!
It 18 palm ninth day course Summary