Seven cattle cloud interview knowledge

1.final, finally, finalize the difference?

final is a modifier, if a class is declared final, meaning that it can not send another unexpected new sub-class can not be inherited as a parent. Is declared as final variables must be given in the initial statement, a reference in the future can only read, can not be modified, is declared as final method can only be used, can not be overloaded.

finally finally block to provide exception handling to perform any cleanup. If it does, then phase matching catch clause will be executed, then the control will finally enter the block.

finalize the method name, do the necessary cleanup before the finalize () method to remove the object from memory out of the garbage collector. This method calls to the garbage collector when the object to determine the object is not referenced. A subclass overrides the finalize () method to organize system resources or perform other cleanup work. finalize () method before the garbage collector to delete the object this object calls.

2. ordering fast row is stable right? Some say stable sort, what sort of space complexity is O (n)?

Quick sort is unstable sort, the process is fast row beginning with the first one as a reference, and then compare the data from the far right, if smaller than the data, the exchange position, and then compare that number k from the left, and if large than k, k, and this switching element will be the right position until the final position k is determined, followed by first and second halves compared sort, until all the sort is complete. Quick Sort time complexity O (nlog 2 n) at best

Stable sort have bubble sort, direct insertion sort, binary insertion sort, merge sort, and radix sort.

Space complexity sort O (n) and for binary merge sort order. Merge sort is a stable sort, the algorithm uses divide and conquer. The combined sequence has been ordered, fully ordered sequence; i.e., each subsequence first ordered, and then make the time ordered sequence. The last two will be merged into a sorted list ordered list, called Road merge.

3. differences and relations between threads and processes

Is a thread in the same process can share resources into lightweight

 (1) address space: an execution unit within the process; the process has at least one thread; they share the process's address space; and the process has its own separate address space; 

 (2) resource owners: the process is owned by a unit of resource allocation and resource within the same process threads share the process 

 (3) A thread is the basic unit of processor scheduling, but the process is not. 

 (4) both of which can execute concurrently.

 Process is the basic unit of resource allocation, thread is the basic unit of scheduling. Process contains threads, threads share the process resources.

4.3 kinds of familiar design patterns

Single-mode embodiment, the adapter mode, simple factory mode, proxy mode

Separate modes: always a class can only create an instance of this class is called a singleton class, this pattern is called Singleton pattern.

public class Singleton{

    private Singleton(){}

    private final static Singleton instance=new Singleton();

    public static Singleton getInatance(){

        return instance;

    }

}

Simple factory pattern is determined by a factory object to create an instance of what kind of product class. Simple factory pattern is a special mode of realization of different plants.

Proxy mode is when the client code needs to call an object, the client does not actually care whether the object is to get accurate, it's just a subject that can provide the gongn can, then we can return to the proxy object.

Acting is a java object to act on behalf of another java object

public class Imageproxy implements Image{

    // a combination image instance, as the agent object

    private Image img;

    public Imageproxy(Image img){ this.img=img;}

    public void show(){

        if(img==null){ img=new BigImage(); }

        img.show();

    }

}

5. how multi-threading deadlock and avoid deadlock

  1. Locking sequence: when a plurality of threads requires some of the same lock, but in a different order locking, a deadlock occurs easily. If you can make sure that all the threads are to acquire a lock in the same order, then the deadlock will not occur.

  2. Locking time: when trying to acquire locks plus a timeout, which means that in the process of trying to acquire the lock in exceeds this limit then give up the thread of the lock request. If a thread is not within a given time frame successfully obtain all the required locks, will be rolled back and release all locks have been acquired, and then wait for a random time and try again. This random wait time for other threads have the opportunity to try to obtain the same locks, and let the application can continue to run at the time did not get a lock.

  3. deadlock detection: The main sequential locking for those who can not achieve and lock timeout is not feasible scenario.

Whenever a thread acquires the lock, which will be noted in the thread will lock and associated data structures. In addition Before, whenever a thread requests a lock, this also needs to be recorded in the data structure. Whenever a thread requesting the lock fails, this thread can traverse the lock graph to see if there is deadlock. When the deadlock is detected, a feasible method is to release all locks, rollback, and after waiting for a random retry time. A better solution is to set priorities for these threads, make a thread or several threads rolled back, the rest of the thread as there is no deadlock continues as they need to maintain a lock.

6. how to achieve synchronization mechanism

  Modified synchronization method with the synchronized keyword

 There are several methods to achieve synchronization, are what? Are synchronized, wait and notify

 wait (): make a thread in a wait state, and releases the lock held by the object.
 sleep (): make a running thread in a sleep state, it is a static method call this method to capture InterruptedException exception.
 notify (): wake up a thread in a wait state, noting that at the time this method is called, does not exactly wake up one thread wait state, but which is determined by the JVM thread wakes up, but not by priority.
 notityAll (): wake up a thread into a wait state at all, note that not all wake up threads to lock an object, but let them compete.

Difference 7.UDP and TCP

1. Based linked to a connectionless; connection-oriented protocol is the TCP, UDP a connectionless
2. Requirements of system resources (TCP more, UDP less);
3.UDP relatively simple program structure;
4. stream mode and packet mode data ;

5.TCP ensure data accuracy, UDP possible packet loss, TCP guarantee data order, UDP does not guarantee

8.http的get post head

head only request header, the page class GET method, does not respond to the page Body section, basic information for access to resources, i.e., to check whether the links and the accessibility of the resource modification.

http 4xx Client Error 400 401 Bad Request unauthenticated pay 402 403 404 405 prohibited method is not allowed 406 Not Found do not accept the request timed out 408 414 Request URI Too Long

http 5xx Server Error 500 Internal Server Error 501 502 Unrealized Gateway 504 Gateway Timeout 505 HTTP failure version does not support

9.git undo changes how the local file

1. not added cache, file modification undo git checkout - file

2. The buffer zone has been added, revocation documents submitted git reset HEAD file or git rm --cached file

3. has been submitted to the local rollback submit git reset --HARD commit_id / HEAD ^ n

4. push to have remote 1> git revert way git revert commit_id // will be submitted to revert to withdraw for a new submission, not only submitted was revoked, and local branches also submit one more than the remote branch

                      2) git push origin master // remote pushed   in this way is most convenient, but the drawback is more than 2 times useless commit, commit so that the entire branch is no longer clean. 

                         3) You can delete a remote branch, and then roll back the local branch, and then push the local branch to origin

10.linux command, view the occupied port, view memory conditions

  View port occupancy lsof -i: port number to see a port occupied by the case, such as lsof -i: 8000

      netstat -tunlp | grep process port numbers to view the specified port number of cases

      netstat -anp | grep port number 

  Check the memory occupancy enter top input ps aux --sort -rss view memory

     Input cat / proc / meminfo gnome-system-monitor input

11. How indexed database

Unique index create unique index index name on table name to create a unique index, the database can guarantee the uniqueness of each row of data.

Can greatly accelerate the speed of the index data, you can accelerate the connection between the table and the table, especially in reference to particular interest for data integrity aspects.

Can significantly reduce the query time grouped and sorted by using an index, the process may query, concealer optimized to improve system performance.




Published 36 original articles · won praise 19 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_27182767/article/details/80296341