Some of the good Java interview questions

INTRODUCTION
This article contains a number of companies face questions, the answer is purely personal opinions and do not represent the standard answer, if wrong please correct me in the comments section
interview questions related to this article does not include problem solving algorithm (space is too small and the content limitations too) and distributed system architecture (too theoretical and formulaic, that white people are old-fashioned question to ask, but the principle involved too bad architecture deployed), only selected portions I personally feel a little bit mean little or the depth of the problem, if anyone is interested I then went on to write several
functional programming What are the characteristics?

The same functions and variables status can be used as parameters and return values
support closures and higher order functions, you can make objects like a function operating
support lazy evaluation, may request until the time value and then calculated
using only expression, not to use statements All the code is a simple operation process, all of the processing operation for the operation are
no side effects, are all functions return a new value will not change the state of external variables and values

CgLib is how to improve the efficiency of the method to call the agent?
Using FastClass mechanism, as follows:

Indexing all methods
before calling the method according to the index to find information
when calling the index directly match the corresponding method calls directly

Speak a random selection algorithm (m elements selected from the set A random)
algorithm steps:

Of m elements in set B
for the i-th element (i> m, i is the initial m + 1), so that the probability of this element at m / i, and replacing any other probability of an element B
repeating the above operation until the end of the loop through the collection
returns a collection of B

prove:

Probability traverse to m + 1-th element, the element is stored in B of m / (m + 1), the probability of the elements B being replaced is not 1- (m / (m + 1 ) * 1 / m) = m / (m + 1)
the probability of traversing the i-th element before the i-1 th element is stored in B is m / (i-1), the i-th element is stored in B's probability m / i, the first i-1 th element B is left in the probability of each of m / i
when i is equal to n, i.e., traverse to the n-th element, before the n-1 element, each stay B is the probability of the probability of m / n, n-th element is replaced by the probability B is also m / n, so that each element is stored in B are m / n

Talk about JMM
JMM, namely Java Memory Model, namely Java memory model, define the virtual machine works in memory of
JMM is part of the JVM, from an abstract point of view, JMM defines an abstract relationship between the thread and the main memory:

Shared variables are stored in the main memory, thread
each thread has its own private local memory, local memory to save a copy of the shared variable

JMM local memory abstraction is not real, it covers the cache, write buffer, registers, etc.
with the most simple words to explain the various paradigms

1NF: each column are indivisible items
2NF: 1NF on the basis, in part dependent elimination
3NF: 2NF on basis, eliminating non-primary property of the code transmitted dependence
BCNF: on the basis of 1NF, guaranteed any dependencies determinants must contain code
4NF: on the basis of 3NF on the elimination of multi-valued dependency
5NF: on the basis of 4NF, ensure that the table can not be decomposed

Thread blocking state can be divided into three broad sense, to talk about is what three
wait indefinitely (Waiting): thread in this state will not be cpu allocation of time slices, other threads need to wait for an explicit wake

obj[1].wait()
thread.join()
LockSupport.park()

There waiting period (Timed Waiting): in this state, the thread will not be cpu other threads will not be assigned a time slice, but in addition to explicitly awakened by another thread, can wake up in their own time-out after waiting

Thread.sleep(millis)
obj.wait(timeout)
thread.join(millis)
LockSupport.parkNanos(nanos)
LockSupport.parkUntil(deadline)

Blocked (Blocked): a thread waiting to acquire a lock, will be blocked during the

Method for modifying or entering the synchronized code block, and the thread does not have a corresponding lock

If an exception occurs threads, other threads will be how to do?
After the current code of the exception clause thread method is invalid, does not affect the execution of other threads
park and wait method What is the difference?

wait thread synchronization method achieved by mutex object, park by a binary semaphore achieve thread synchronization
wait method will give up the thread lock currently held, park the method is not
called before the notify method is not valid in wait , but you can obtain a license in advance by calling the method unpark, call the park to make the next advance to the thread

TCP and UDP specific application scenarios What?
TCP: There are requirements for communication quality

Browser Protocol: http
file transfer protocol: ftp
mail protocol: smtp, pop
remote login standard protocols: Telnet

UDP: communication speed required by

Trivial File Transfer Protocol: tftp
Domain Name System: dns (tcp protocol is also used, if the packets sent over 512 bytes will be used to send tcp)
voice and video

Spring singleton pattern is how to achieve?
Is achieved by means of a single case of the registry, in the parent class DefaultSigletonBeanRegistry AbstractBeanFactory, there ConcurrentHashMap a member variable of type singletonObjects, save the beanName => mapping between bean object
when you need to create a singleton object, checks the object (registry) whether there has been mapped, if it exists directly back from the table,
the new generation of the object, which has several years into the old case?

Eden area is full, a Minor GC, if the object is still unable to survive into the Cenozoic, then transferred to the early years of old
objects If you need to create is too large, then directly assigned to the object's old
objects survived for more than a certain algebra Cenozoic (default is 15 generations)
If the object of a certain age, more than half of Survivor region, and more than an object of this age-old's transfer in advance (dynamic Age estimation)

MVVM and MVC What is the difference?
MVVM is an abbreviation for Model-View-ViewModel will in MVC View abstract state and behavior, while the separated view of the UI and business logic to achieve the separation of the rear end of the data, the template page and the controller
portion of the Controller's role in MVC split to separate the responsibility of the ViewModel, to achieve a self-synchronizing Model and View, reducing the coupling business page and
TCP optimization techniques you know what?
Nalge algorithm
designed to address a large number of small data transmission efficiency decreases causing the problem and achieve the principle is always only one to be less than the MSS (MSS) determines the packet on the link, as far as possible to send large chunks of data
only if the following conditions when only allowed to send:

Packet length reaches the MSS (maximum segment size)
with FIN
set TCP_NODELAY option
when the option is not set TCP_CORK, but all the small packets sent (length less than MSS) were confirmed
when the above conditions are not met, a timeout occurs

While avoiding network congestion, but overall network utilization is very low, but also reduces the real-time
Delay ACK (acknowledgment delay mechanism)
aims to reduce the network transmission of large amounts of a few tabloid paper, the principle is achieved by the new data to the ACK piggybacking past
concrete realization of the following:

When data is received, ACK not immediately, but wait for some time and then perform ACK
if received two consecutive data packets, still need to immediately ACK

The concept of the operating system in the debris and debris outside to talk about

In the debris: has been allocated memory space larger than the memory space required for the request, the process has led to a part of the address space is not used to, and ultimately a waste of
foreign debris: not yet been allocated, but because the application can not be too small other processes use, and ultimately wasted

Singleton pattern than the static method What are the advantages?

Singleton class method override support
singleton class can be instantiated delay
singleton may be used for multi-state, the state need not be concerned globally

Mysql performance optimization What program?
sql optimization

Avoid full table scan: too many specific operation, do not list them
to avoid unnecessary operations: slightly, ditto
table structure optimized
to choose the right type of data

System performance optimization

Increase the value of innodb_buffer_pool_size ensure avoiding frequent reads data from the disk
before starting the database, perform the warm-up warm-up script data, the data on the disk cache in memory
using a large enough innodb_log_file_size (write cache), adjustment proposed innodb_log_file_size 0.25 times the
increase max_connections, increase the number of users connected to allow simultaneous
increase in the value of key_buffer_size increase the buffer size for the block index
increases the value of thread_cache_size, increasing the number of reusable threads

Structural optimization

Sub-libraries: based on the master is separated from the read architecture
part table: horizontal / vertical part tables
other
enable caching

What mode adapter scenario?
Abstract scene

It requires the use of a class, but the class interface does not meet system needs
require some do not like each other much associated link, so that it can work together with the
need for a number of classes to provide a uniform output interface

Specific scenes

spring-aop: to fit different types of notifications to a unified interface to the adapter AdvisorAdapter, the interceptor can acquire a corresponding notification through specific adapter classes
spring-mvc: Use HandlerAdapter adapted to specific Controller, and the Controller achieved DispatcherServlet unified interface between the butt

Cross-table query optimization are those ideas?

Can not join in the WHERE
ON the conditions as much as
the left and right to ensure the connection table index field, left and right to ensure the connection table field index, En warrant that any field index table
first table group by columns from the join
to the group by adding an index column, to avoid temporary table (doubtful)

How would you implement micro letter "people in the vicinity" algorithm

The latitude and longitude of the map according to a certain distance cut into squares, each square cut can be further separated smaller squares
for each grid used gohash algorithm [2] are numbered, numbered according to the leftmost matching, may represent different precision range box
when opened "close" and function, the system according to the positioning location information of the device to give a user ID squares
according to a selected range of accuracy, the matching box top n number, then the search box from the database top n number of its consistent user
can speed up queries by pressing the square sub-library sub-table

refers to refers to any thread thread obj Object ordinary objects, hereinafter ↩︎

The latitude and longitude in the form of a partition between two constant breakdown, if it falls on the left side labeled 0, otherwise labeled 1 ↩︎

Guess you like

Origin blog.csdn.net/a59612/article/details/91125659