20200115 - java interview questions most commonly a 200+

The final effect
. 1) modified final class called final class, which can not be inherited
2 final modified method) can not be rewritten
. 3) final modified variable called constants, must be initialized, the initialization can not be modified after


Java strings are operating in what class, what difference there is between them
String the StringBuilder StringBuffer
String statements are immutable objects, each operation will generate new String object. StringBuilder and StringBuffer can be operated on the basis of the original object, so the case of frequent changes to the contents of the string should not use String.
StringBuffer is thread-safe, StringBuilder is not thread-safe, but the performance is higher than StringBuffer StringBuilder, so the use of StringBuilder in a single-threaded environment, multiple threads using StringBuffer.


The container java
Here Insert Picture Description
java container is generally of two different data structures, one is Collections, Map is another
major container is java Collections Set List Map


HashMap and HashTable
storage: HashMap allow Key and value is null, HashTable not allow
thread safety: HashTable are thread-safe, while HashMap is not thread safe


The principle of HashMap
HashMap Hash-based algorithm, we, get (key) to get through put (key, value) memory, when an incoming key, hashmap calculates a hash value based on key.hashCode (), based on hash values value stored in the bucket, when the calculated hash values are the same, we call hash conflicts, the HashMap practice with the same hash value list and a red-black tree stored value, when the number of hash conflicts less, linked lists otherwise, use red-black tree


The difference between ArrayList and LinkedList what
data structure to achieve: ArrayList dynamic array is a data structure implementation, and LinkedList is a doubly-linked list data structure to achieve
random access efficiency: high-efficiency ArrayList random access, you only need to take a random label to the next.
Add and delete efficiency: LinkedList high, high chain operations.


What is the difference between parallel and concurrent
parallel: a plurality of processors or multi-core processor to handle multiple tasks
concurrently: a plurality of tasks in the same cpu, broken down according to rotation time slice (alternating) performs those tasks logically It is performed simultaneously.


The difference between threads and processes
a program only a few process, a process has at least one thread, a process can have multiple threads.


Ways to create a thread
to inherit Thread override the run method
to achieve Runnable interface
to achieve Callable Interface


Thread state
new has not yet started
runnable is being executed
blocked blocking
waiting forever waiting state
status timed_waiting waiting for a specified time to re-awakened
terminated execution is completed


** In java program how to ensure the safe operation of multi-threaded **
1) the use of safety class java.util.concurrent under the category
2) using an automatic lock the synchronized
3) using the manual lock lock


Reflex
reflector is in operation, for any class, can know all the properties and methods of this class, for any object, it can invoke any one of the methods and properties, such information and dynamic invocation object obtained functionality of the method is referred to as reflected java language.


java serialization
java serialization order to save the state of various objects in memory, and can read out the stored objects.
About the situation need to use java serialization of
objects in memory trying to save to a file or database in time
when I wanted to use a socket transfer object on the network
want to call the transfer object through RMI remote method when


Dynamic proxies
jdk dynamic proxy and native cglib dynamic proxy, jdk native agent based interface implementation, cglib are subclasses of the current class-based implementation.


How to avoid injection sql statement
1) Pretreatment PreparedStatement
2) was filtered off using a regular expression of characters in a special character


CSRF attacks
cross-site request forgery cross-site request forgery can be understood by the offensive Pirates your identity to your name send malicious request
means of defense:
the authentication request source address
critical operations add validation code
to add token verification code in the request address


osi seven layer model
physical layer: the transmission medium using a data link layer provides the physical connection, transparent transmission bit stream
data link layer: a link between the node responsible for establishing and managing
the network layer: The routing algorithm, packets or subnet grouping by selecting the most appropriate path to
the transport layer: the user provides reliable end to end flow control and error, to ensure the correct transmission of the packet
session layer: providing a method for establishing and using the connection to the two presentation layer entities
presentation layer : represents user information processing problems, such as encoding, encryption, and data format conversion
application layer: providing services directly to the user, the user wishes to complete a variety of work done on the network.


get and post differences
get request will be actively browser cache, while the post will not
get passed parameters limited in size, and post no
post more secure transmission parameters, the parameters will get expressly limited to the url, post will not

Published 657 original articles · won praise 39 · views 60000 +

Guess you like

Origin blog.csdn.net/qq_36344771/article/details/103986001