Big Data Nineth Day content

Source: Internet
Author: User

Notes section:


Create thread mode

-----------------

1.Thread

2.runnable{public void Run ();}


Class Man extends person implements runnable{

public void Run () {

...

}

}


New Car (). Start ();

New Thread (New Man ()). Start ();


Eclipse

---------------

ALT +///code assist

ALT + UP ARROW //Move up one line

ALT + DOWN ARROW //Move up one line

ALT + SHIFT + UP ARROW //copy up one row

ALT + SHIFT + DOWN ARROW //copy one line down

CTRL + D//delete a row


String

-----------------

1. = =//Determine if the same object. Determines the memory address of the object.

2. Equals //is to determine whether the contents of two objects are the same.

Split (String reg); //Split by the specified string, returning an array of values.

SUBSTRING (int start); Takes a substring operation, specifying all characters after the starting index

substring (int start,int end);//substring operation, specifying all characters between the starting and ending indexes,

Contains the starting index, without a trailing index. [A, b] is a semi-open half-closed interval.

bytebyte //wrapper class

Short Short

intInteger

LongLong

floatFloat

DouleDouble

BooleanBoolean

CharCharacter

byte B = 127;

byte B = new byte (127);


StringBuffer

string buffers

StringBuffer is a string variable whose object can be expanded and modified.

Append methods can append strings, characters, objects, etc.


Compared to string: When the string method performs Sting=string+i and so on, the string object is actually immutable, so it constantly increases in the creation of the object and in the string pool, and the original pair is recycled, and string execution is inefficient.


The method in StringBuffer is modified by synchronized, is synchronous, thread-safe, only one pair can execute at the same time, the lock is the current StringBuffer object when executing


StringBuilder not modified by synchronized, non-synchronous

Performance is inconsistent, the StringBuilder does not need to determine whether the lock is occupied and the performance is better and more efficient at each visit.


Job section:


1. The production and consumption of bees and bears, bear in the honey full 10 pounds eaten. Bees produce a catty of honey once, and the time it takes for a bee to produce a pound of honey is 10s.

10 bees and two bears.


Code:

Package com.work.ten;class bear extends thread{private fengmi fengmi;private  string bearname;public bear (fengmi fengmi,string  bearname) {this.fengmi=fengmi; This.bearname=bearname;} Public void run () {while (true) {synchronized (FENGMI) {if  (Fengmi.getfengmiweight () <10)  { Try {fengmi.wait ();} catch  (exception e) {}}else if (Fengmi.getfengmiweight () >=10&&fengmi.getfengmiweight () %10==0) {    fengmi. Chifemgmi (); System.out.println ("10  Jin Honey was" +bearname+ "eaten, the remaining" +fengmi.getfengmiweight () + "Catty Honey"); Try{fengmi.notifyall (); catch (exception e) {}}}yield ();}}} The number of honey in class fengmi {private static int fengmiweight=0; //honeypot private   Maximum number of honey in final int fengmiweightmax=20; //honeypot public  int getfengmiweight ()  { Return fengmiweight;} Public int getfengmiweightmax ()  {return fengmiweightmax;} PublIc void createfemgmi ()  { //production of Honey This.fengmiweight += 1;} Public void chifemgmi ()  { //eat Honey this.fengmiweight -=10;}} Class bee extends thread{private fengmi fengmi;private string  beename ;p Ublic bee (fengmi fengmi,string beename) {this.fengmi=fengmi;this.beename=beename;} Public void run () {Int i=1;while (true) {synchronized (FENGMI) {if (Fengmi.getfengmiweight () < Fengmi.getfengmiweightmax ()) {if (Fengmi.getfengmiweight () ==0) {Try{fengmi. Createfemgmi (); System.out.println ("Honey collection good, at present altogether" +fengmi.getfengmiweight () + "Jin Honey"); Fengmi.notifyall (); Thread.Sleep (10); System.out.println ("After 10ms, the bees rested Well");} catch (Exception e) {}}else {if  (Fengmi.getfengmiweight ()%10==0) {Try{fengmi. Createfemgmi (); System.out.println ("Honey collection good, at present altogether" +fengmi.getfengmiweight () + "Jin Honey"); Fengmi.notifyall (); Thread.Sleep (10); System.out.println ("After 10ms, the bees rested Well");} catch (exception e) {}}else {try{fengmi. CreateFemgmi (); if (Fengmi.getfengmiweight ()%10==0) {System.out.println ("Honey collected well, present altogether" +fengmi.getfengmiweight () + "Catty Honey, Bears can come to pick up ");} Else  system.out.println ("Honey collection good, at present altogether" +fengmi.getfengmiweight () + "Jin Honey"); Fengmi.notifyall (); Thread.Sleep (10); System.out.println ("After 10ms, the bees rested Well");} catch (exception e) {}}}}else {system.out.println ("honey full"); Try{fengmi.wait ();} catch (exception e) {}}}i++;yield ();}}} Class beebearmodel2{public static void main (String[] args) {FengMi fengmi=new  fengmi (); Bear bear1=new bear (Fengmi, "Bear1"); Bee bee1=new bee (Fengmi, "Bee1"); Bee bee2=new bee (Fengmi, "Bee2"); Bear1.start (); Bee1.start (); Bee2.start ();}}


Job 1 run result (partial):


Honey collection Well, at present altogether 18 Catty honey

After 10ms, the bees rested.

Honey collection Well, at present altogether 19 Catty honey

After 10ms, the bees rested.

Honey collection Well, at present a total of 20 pounds of honey, bear can come to pick up

After 10ms, the bees rested.

10 Catty honey is eaten by Bear1, the remaining 10 catty honey

Honey collection Well, at present altogether 11 Catty honey

After 10ms, the bees rested.

Honey collection Well, at present altogether 12 catty honey

After 10ms, the bees rested.

Honey collection Well, at present altogether 13 Catty honey

After 10ms, the bees rested.



Job 2

Remove the largest common substring in the two string.

Package com.work.nine;public class find {private string checkstring1;private  string checkstring2;public string getcheckstring1 ()  {return checkstring1;} Public void setcheckstring1 (string checkstring1)  {this.checkString1 =  CheckString1;} Public string getcheckstring2 ()  {return checkstring2;} Public void setcheckstring2 (string checkstring2)  {this.checkString2 =  CheckString2;} Public find (string checkstring1,string checkstring2) {this.checkstring1=checkstring1; This.checkstring2=checkstring2;} Public string findmaxpublicstring (Boolean result) {if (checkstring1==null| | Checkstring2==null)  return  ""; else{string temp=this.checkstring2;if (Result) {temp= Temp.tolowercase (); String string1lower=this.checkstring1.tolowercase (); String string2lower=this.checkstring2.tolowercase (); if (String1lower.equals (string2lower)) &NBsp;return this.checkstring1;else{while (! String1lower.contains (temp)) {temp=temp.substring (0, temp.length ()-1);} Return temp;}}  else{if (This.checkString1.equals (this.checkstring2))  return this.checkstring1;else{while (! This.checkString1.contains (temp)) {temp=temp.substring (0, temp.length ()-1);} return temp;}}}} Package com.work.nine;class maxpublicstringdemo{public static void main (String[]  args) {find find1=new find ("ABCDEFG", "" "); Find find2=new find ("ABCDEFG", "ABCDEFG"); Find find3=new find ("ABCDEFG", "higklmn"); Find find4=new find ("ABCDEFG", "AB"); Find find5=new find ("ABCDEFG", "AB"); Find find11=new find ("ABCDEFG", "AABBCCD"); System.out.println ("The largest common substring is" +find1.) Findmaxpublicstring (false)); System.out.println ("The largest common substring is" +find2.) Findmaxpublicstring (false)); System.out.println ("The largest common substring is" +find3.) Findmaxpublicstring (false)); System.out.println ("The largest common substring is" +find4.) FindmaxpublicstriNg (false)); System.out.println ("The largest common substring is" +find5.) Findmaxpublicstring (false)); System.out.println ("The largest common substring is" +find11.) Findmaxpublicstring (false)); System.out.println ("--------------------------------------------"); Find find6=new find ("ABCDEFG", "" "); Find find7=new find ("ABCDEFG", "ABCDEFG"); Find find8=new find ("ABCDEFG", "Aacceeg"); Find find9=new find ("ABCDEFG", "AB"); Find find10=new find ("ABCDEFG", "ABCDEFG"); System.out.println ("The largest common substring is" +find6.) Findmaxpublicstring (true)); System.out.println ("The largest common substring is" +find7.) Findmaxpublicstring (true)); System.out.println ("The largest common substring is" +find8.) Findmaxpublicstring (true)); System.out.println ("The largest common substring is" +find9.) Findmaxpublicstring (true)); System.out.println ("The largest common substring is" +find10.) Findmaxpublicstring (True));}}

Results:


The largest common substring is

The largest common substring is ABCDEFG

The largest common substring is

The largest common substring is AB

The largest common substring is

The largest common substring is a

--------------------------------------------

The largest common substring is

The largest common substring is ABCDEFG

The largest common substring is a

The largest common substring is AB

The largest common substring is ABCDEFG



Job 3

StringBuffer is thread-safe, StringBuilder is not thread-safe. Is the performance consistent in single-threaded access?

Performance is inconsistent, the StringBuilder does not need to determine whether the lock is occupied and the performance is better and more efficient at each visit.



Job 4

Complete the practice of 8 basic data class wrapper classes to complete the automatic unboxing operation.

Package com.work.nine;public class chaizhuang {public static void main ( String[] args) {// byte type of automatic boxing and unpacking         byte b1 =  1;        byte b2 = b1;         system.out.println ("byte "  +  (B1&NBSP;==&NBSP;B2));         // short types of automatic packing and unpacking         short  s1 = 1;        short s2 = s1;         system.out.println ("short "  +  (S1&NBSP;==&NBSP;S2));         // integer types of automatic packing and unpacking          integer int1 = 1;        int int2  = int1;  &nbsP;     system.out.println ("integer "  +  (Int1 == int2));         // long types of automatic packing and unpacking          long long1 = 1l;        long long2  = long1;        system.out.println ("Long "  +   (long1 == long2))         // float type automatic packing and unpacking         Float f1 = 3.1415f;         float f2 = f1;         System.out.println ("float "  +  (F1&NBSP;==&NBSP;F2));         // double types of automatic packing and unpacking         Double d1 =  3.1415d;       &nBsp;double d2 = d1;        system.out.println ("Double   " +  (D1&NBSP;==&NBSP;D2));        //  automatic boxing and unpacking of character types         Character c1 =  ' A ';         char c2 = c1;         System.out.println ("Character"  +  (C1&NBSP;==&NBSP;C2));         // boolean types of automatic packing and unpacking         Boolean bool1 =  false;        boolean bool2 = bool1;         system.out.println ("boolean "  +  (Bool1 == bool2));}}


This article is from the "11138113" blog, please be sure to keep this source http://11148113.blog.51cto.com/11138113/1775411

Big Data Nineth Day content

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.