<>【1】 Please give us a brief description String,StringBuffer,StringBuilder?

String: Immutable character sequence , Bottom use char[] storage
StringBuffer: Variable character sequence , Thread safe , Low efficiency , Bottom use char[] storage
StringBuilder: Variable character sequence , Thread unsafe , efficient , Bottom use char[] storage

StringBuffer and StringBuilder The default constructor initializes a length of 16 Of char[], Continuous data append after , If char[] Insufficient capacity , Capacity expansion will be carried out , By default , Expansion to original capacity 2 times +2, At the same time char[] Elements in are copied to the new array

proposal : About append Times and string length , Should be called when creating StringBuffer(int capacity) or StringBuilder(int
capacity) Method specifies the char[] length , Prevent multiple expansion , increase of efficiency

<>【2】JDK1.8 New time in API What is it? ? For example

localDateTime,LocalDate,LocalTime
localDateTime Compared with LocalDate,LocalTime, More frequently used
public static void main(String[] args) { // now(): Get current date , time , date + time LocalDate
localDate = LocalDate.now(); LocalTime localTime = LocalTime.now();
LocalDateTime localDateTime = LocalDateTime.now();
System.out.println(localDate);//2020-05-17
System.out.println(localTime);//14:44:08.682
System.out.println(localDateTime);//2020-05-17T14:44:08.682 LocalDate
localDate1 = LocalDate.of(2020, 5, 17); LocalTime localTime1 =
LocalTime.of(14,49,20); LocalDateTime localDateTime1 = LocalDateTime.of(2020,
5, 17, 10, 20, 30); System.out.println(localDate1);//2020-05-17
System.out.println(localTime1);//14:49:20
System.out.println(localDateTime1);//2020-05-17T10:20:30
System.out.println(localDateTime.getDayOfMonth());//17
System.out.println(localDateTime.getDayOfWeek());//SUNDAY
System.out.println(localDateTime.getDayOfYear());//138
System.out.println(localDateTime.getMonthValue());//5 LocalDate localDate2 =
localDate1.withDayOfMonth(22); System.out.println(localDate1);//2020-05-17
System.out.println(localDate2);//2020-05-22 LocalDate localDate3 =
localDate2.plusDays(7); System.out.println(localDate3);//2020-05-29 LocalDate
localDate4 = localDate3.minusDays(6);
System.out.println(localDate4);//2020-05-23 }
<>【3】 Please specify List,Map,Set When three interface access elements , What are the characteristics of each ?

List Access elements with specific indexes , Can have repeating elements
Set Cannot store duplicate elements ( With object equals() Method to distinguish whether the element is repeated )
Map Save key value pair (key-value pair) mapping , The mapping relationship can be one to one or many to one

<>【4】 Please judge List,Set,Map Inherit from Collection Interface ?

List,Set yes ,Map no
Map Is the key value pair mapping container , And List and Set There are obvious differences , and Set Scattered elements stored and duplicate elements are not allowed ,List It's a linear container , For accessing elements by numerical index

<>【5】 Please specify Collection and Collections The difference between

Collection Is the parent interface of a collection class , The interface between inheritance and him mainly includes Set and List
Collections Is a tool class for collection classes , It provides a series of static methods to search various collections , sort , Thread safety and other operations

<>【6】 Please give us a brief description ArrayList,Vector,LinkedList What are the storage performance and characteristics of ?

ArrayList Data is stored by array at the bottom , It's not thread safe , So it's faster , Storing data is orderly , So sequential storage and query are efficient , But random insertion of elements is inefficient
Vector Data is stored by array at the bottom , Is thread safe , So it's slower ,
LinkedList Storage using double linked list , Index data by sequence number needs to be traversed forward or backward , Good at random insertion and random deletion of data

<>【7】 Please explain HashMap and Hashtable The difference between ?

HashMap It's not thread safe , So it's efficient , allow Key and Value by null
Hashtable Is thread safe , So it's inefficient , not allow Key and Value by null

<>【8】 Please explain TreeMap?

TreeMap It's an order key-value aggregate , Based on red black tree (Red-Black tree) Of NavigableMap realization .
This map is sorted according to the natural order of its keys , Or based on the Comparator Sort , Depending on the construction method used
TreeMap Characteristics of :
The root node is black
Each node can only be red or black
Each leaf node (NIL node , Empty node ) It's black .
If a node is red , Then both of its child nodes are black , That is to say, two red nodes cannot appear in one path . All paths from any node to each of its leaves contain the same number of black nodes

<>【9】 Please explain HashMap Why is the capacity of 2 Of n pow ?

The default load factor is 0.75, 2^n To make the hash more uniform , For example, in extreme cases, a subscript is hashed in the array , that hashmap By O(1) Complex degenerates to O(n) Of </font

<>【10】 If hashMap Of key Is a custom class , What does this class need to do ?

use HashMap, If key Is a custom class , This class must override hashcode() and equals(), adopt hashcode() Determine where data is stored , adopt equals() Come on key duplicate removal

<>【11】 How to ensure thread safety ?

Through reasonable time scheduling , Avoid access conflicts of shared resources . in addition , Appropriate strategies can be adopted in parallel task design , Ensure that there is no shared resource between tasks , Design a rule to ensure that a client's computing work and data access will only be completed by one thread or one machine , Instead of assigning a client's computing tasks to multiple threads

<>【12】 Please briefly describe the basic state of the thread and the relationship between the States ?

among Running Indicates operation status ,Runnable Indicates ready state ( Everything is ready , Only owe CPU),Blocked Indicates blocking status , There are many kinds of blocking States , Probably because of the call wait() Method to enter the waiting pool , It is also possible to execute a synchronization method or synchronize code blocks into an equal lock pool , Or call sleep() Method or join() Method to wait for sleep or other threads to end , Or because it happened I/O interrupt

<>【13】 Please explain what thread pool is (thread pool)?

In object-oriented programming , Creating and destroying objects is time consuming , Because to create an object, you need to obtain memory resources or other resources . stay Java Especially in China , The virtual machine will try to track every object , So that garbage collection can be performed after the object is destroyed . So one way to improve the efficiency of service programs is to reduce the number of objects created and destroyed as much as possible , Especially the creation and destruction of some resource consuming objects , This is it. ” Pool resources ” Causes of Technology . As the name implies, thread pool is to create several executable threads in advance and put them into a pool ( container ) in , Get threads from the pool when needed without creating them by yourself , After use, the thread does not need to be destroyed but put back into the pool , This reduces the cost of creating and destroying threaded objects

<>【14】 Please introduce the related methods of thread synchronization and thread scheduling

* wait(): Make a thread wait ( block ) state , And release the lock of the held object
* sleep(): Sleep a running thread , Is a static method , This method does not release the object lock , Call this method to process InterruptedException abnormal
* notify(): Wake up a waiting thread , Of course, when this method is called , Does not wake up a waiting thread exactly
* notityAll(): Wake up all waiting threads , This method does not lock objects to all threads , It's about letting them compete , Only the thread obtaining the lock can enter the ready state
* adopt Lock Interface provides an explicit locking mechanism (explicit
lock), Increased flexibility and thread coordination .Lock Lock is defined in the interface (lock()) And unlock (unlock()) Method of , It also provides newCondition() Method to generate the Condition object ; in addition ,Java
5 Semaphore mechanism is also provided (semaphore), Semaphores can be used to limit the number of threads accessing a shared resource . Before accessing resources , Threads must be licensed for semaphores ( call Semaphore Object's acquire() method ); After completing access to resources , Thread must return permission to semaphore ( call Semaphore Object's release() method )
<>【15】 Now there's a one-way list , Talk about it , How to judge whether a link appears in a linked list ?


Use speed pointer , Define two pointers , Starting from the head node of the list , One pointer, one step at a time , The other pointer takes two steps at a time . If the fast pointer catches up with the slow pointer , So a linked list is a circular list ; If the fast pointer goes to the end of the list (next point
NULL) Not catching up with the first pointer , So a list is not a circular list

<>【16】 Introduce to you , How to sort ? Please list

The sorting methods are :
Insert sort ( Direct insert sort , Shell Sort ), Exchange sort ( Bubble sorting , Quick sort ), Select sort ( Direct selection sorting , Heap sort ), Merge and sort , Assign sort ( Box sorting , Cardinality sort )

<>【17】String s = new String(“xyz”); Created several String Object?

Two objects , One is "xyx", One is to point "xyx" References to s

<>【18】Math.round(11.5) How much is it ? Math.round(-11.5) How much is it ?

Math.round(11.5) return (long)12,Math.round(-11.5) return (long)-11;

<>【19】short s1 = 1; s1 = s1 + 1; What's wrong ? short s1 = 1; s1 += 1; What's wrong ?

short s1 = 1; s1 = s1 + 1; There is a mistake ,s1 yes short type ,s1+1 yes int type , Cannot explicitly convert to short type . Can be modified to s1
=(short)(s1 + 1) .short s1 = 1; s1 += 1 correct

<>【20】try {} One of them return sentence , So it's right here try Post finally
{} Inside code Will it be implemented , When is it implemented , stay return Before or after ?

Will execute , stay return Pre execution

<>【21】

<>【22】

<>【23】

<>【24】

<>【25】

Technology
©2019-2020 Toolsou All rights reserved,
Mybatis Error resolution :There is no getter for property named '*' in 'class Java.lang.String Big data tells you , How tired are Chinese women Message quality platform series | Full link troubleshooting Gude Haowen serial - You deserve to be an engineer ( Preface ) Image explanation of over fitting and under fitting Springboot of JPA Common query methods JAVA Detailed explanation of anomalies vue Of v-if And v-show The difference between python To solve the problem of dictionary writing list in Codeup——601 | problem A: task scheduling