Night eight o'clock more oneself in watching the video when suddenly received a call from Hangzhou, then felt very strange, abrupt, after the connection was told that Hangzhou NetEase, no simple self-introduction, no unnecessary nonsense, directly into the theme, scared my heart strange nervous, completely unprepared, but there is no way, or have to be hard on!
1, the project structure.
There is no time for moderation, the interviewer directly asked my resume on the situation of a project, briefly said the next is to alleviate the mood, asked the use of the relevant technology, such as using the Spring MVC Framework does not have a database is what these may be the interview officer to the time of moderation, but I am so more relaxed more nervous, sad urge ...
2. Have you used MyBatis? because not how to use, so the interviewer didn't how to ask ...
3, set frame hashtable, HashMap, list, list initialization size, HashMap automatic growth
A: The first is directly asked to understand the commonly used set framework, this one heard affirmation said to understand, so let's talk about Hashtable, HashMap, List of the difference, so the general start said:
The difference between ArrayList and vectors:
Common denominator:All two of these classes implement the list interface (the list interface inherits the collection interface), and they are allordered Collection, that is, the positions of the elements stored in the two collections are sequential, which is equivalent to athe dynamic array, we can laterindex number by locationAn element is taken out, and the data in it is allowed to be duplicated, which is the largest difference from a collection such as HashSet, where a collection such as HashSet cannot retrieve the elements by index number, nor does it allow duplicate elements.
Then say the difference between ArrayList and vector, which mainly includes two aspects:.
synchronization:The vector is thread-safe, that is, it is thread-synchronized between its methods, and ArrayList is a thread-less program that is not synchronized between its methods. If there is only one thread routines access to the collection, it is best to use ArrayList, because it is more efficient than thread-safe, and if there are multiple lines routines access to the collection, it is best to use vectors, since we do not need to consider and write thread-safe code ourselves.
Note:Here comes the thread safety, synchronization problems, the interviewer will have to say a word, let you talk about thread safety is what, if not to consider, you hear this question estimate will be a face, I was such a son! So here I add the thread security issue:thread Safety in JavaIs the thread synchronization means that when a program to a thread-safe method or variable access, the other program can no longer operate on him, you must wait until the end of the visit to the thread-safe method to access, otherwise it will cause errors occur;Thread SafetyThat is, if your code is in a process where more than one thread is running at the same time, these threads may run this code at the same time. If the result of each run is the same as the single-threaded run, and the value of the other variable is the same as expected, it is thread-safe. Thread safety issues are all caused by theglobal variables and static variablescaused, local private variables defined within the method are not thread safe or not.
remark:For Vector&arraylist, Hashtable&hashmap, to remember the thread-safety issues, remember that vectors and Hashtable are old, Java is the birth of the provision, they are thread-safe, ArrayList and HashMap are provided at JAVA2, and they are thread insecure. So, we talk about the old first class.
Data Growth: ArrayList and Vector have an initial capacity size, when the number of elements stored in them exceeds the capacity, you need to increase the storage space of ArrayList and vector, each time to increase storage space, not only add a storage unit, but add multiple storage units , each increase in the number of storage units in memory space utilization and program efficiency to achieve a certain balance. Vector growth is twice times the default, and ArrayList's growth strategy is not clearly defined in the documentation (from the source code to see the growth of 1.5 times times the original). Both the ArrayList and vector can set the initial space size, and the vector can also set the amount of space to grow, while ArrayList does not provide a way to set the growth space.
Summary: That is, the vector increases the original one times, the ArrayList increases the original 0.5 times times. PS: Because in the above talk about the difference between the question of automatic growth, so the interviewer incidentally asked a sentence, HashMap automatic growth of how much, this problem to tell the truth, he did not pay attention to, usually did not pay attention to, so can only honestly say do not know, face after online check under, not sure whether the correct, There is said 1.6 version of the growth is twice times!
Arraylist,vector, LinkedList storage performance and features:
Both ArrayList and vectors are usedstoring data in array mode, the number of elements in this array is greater than the actual stored data to increase and insert the element, both of which allow directindex elements by ordinal, but the insertion element is involved in memory operations such as array element movement, so the index data is fast and the insertion data is slow, vector due to the use of the Synchronized method (thread safety), usually performance is ArrayList poor, and LinkedList using a doubly linked list for storage, Indexing data by ordinal requires a forward or backward traversal, but inserting data requires only the front and back of the item to be recorded, so the insertion is faster. LinkedList is also thread insecure, LinkedList provides methods that enable LinkedList to be used as stacks and queues.
the difference between list and map:
One is the collection of single-column data, and the other is the storageKeys and ValuesSuch a collection of double-column data, the list of data stored in order, and allow repetition; the data stored in the map is not sequential, its key (key) is not duplicated, its value (value) can be duplicated, the value is put (key,value). Values in Map:value=m.get (Key)(This interviewer often asks, although not difficult, but also to note)
the difference between HashMap and Hashtable:
HashMap hashtable contains method removed, changed to Containsvalue and ContainsKey. Because the contains method is easy to cause misunderstanding.
I. Historical reasons: Hashtable is based on the old dictionary class, HashMap is an implementation of the map interface introduced by Java 1.2
Two. Synchronization: Hashtable is thread-safe, that is, synchronous, and HashMap is a thread program is not secure, not synchronous
Three. Value: Only HashMap can let you use NULL as the key or value of an entry for a table, that is, HashMap allows null as a entry key or value, and Hashtable is not allowed.
PS: Finally, the interviewer asked the list of the size of the initialization, that is, the default is how much, this actually asked is the list of list = new ArrayList () here initialize the size of the array, according to the source we know that the default size is 10.
4. Multithreading Wait () sleep ()
A: Chat to multi-threaded, roughly first asked the implementation of multi-threading, this problem does not have to say, very simple, Java provides two ways, one is to inherit the thread class, and the other is to implement the Runnable interface , because Java does not support multiple inheritance, so in multiple inheritance, We have to prioritize the implementation of the Runnable interface, because we can implement the interface method, indirect implementation of multiple inheritance! "After asking the implementation method, the interviewer asked the two methods of use," and then asked the difference between wait () and sleep (), the two methods differ:sleep () is the thread class, and wait () is the object class,sleep is sleeping, The thread continues execution after the specified time, does not discard the CPU resource (that is, does not discard the object lock), is equivalent to pausing the specified T, wait() is waiting, needs to wake, it frees up the CPU resource (that is, discards the object lock), calls Notify () and Notifyall () wake up.
5. Spring MVC Framework Spring filter, Login filter spring MVC layering spring annotations
A: The first question is the Spring MVC framework, let me talk about its composition and function, because the idea was a bit messy, I volunteered to ask this question to stay until the end! Then the interviewer asked, Spring filter, simply asked what I generally do with the filter, I answer the general processing characters and coding, obviously this is not the interviewer to the results, so the interviewer tips, join you in a login system, how to use filters to verify whether the match, I directly blurted out the database, said after I laughed, as to what the last thing I want to ask is here I also forget, good want to mention what controller I said yes, and then should not answer wrong, then asked the spring annotation question, said that their commonly used annotations, Here I have a general summary of some of the following excerpts:
Spring comes with Dependency injection annotations
1 @Required: Dependency check;
2 @Autowired: Automatic assembly 2 automatic assembly, used instead of automatic assembly based on XML configuration @autowired Automatic assembly, by default is injected according to type, can be used for constructors, fields, method injection
3 @Value: Injected spel expression used to inject spel expression that can be placed on a field method or parameter
@Value (Value = "Spel expression")
@Value (Value = "#{message}")
4 @Qualifier: Qualifier descriptor for fine-grained selection of candidates
@Qualifier qualifier descriptors can be injected in addition to names, but finer-grained control over how to select candidates
@Qualifier (value = "Qualified identifier")
JSR-250 annotations
1 @Resource: Automatic assembly, by default according to the type of assembly, if the specified name property will be assembled according to the name, you can use the following way to specify
@Resource (name = "identifier")
field or Setter method
2 @PostConstruct and Predestroy: specifying initialization and destruction method definitions by annotations
JSR-330 annotations
1 @Inject: Equivalent to the default @autowired, except that there is no required property
2 @Named: Specifies the bean name, corresponding to the default injection of the bean name in spring's own @qualifier
3 @Qualifier: Corresponds only to the extended @qualifier qualifier descriptor annotations in spring @qualifier, which can only be extended, with no Value property
JPA annotations
@PersistenceContext
@PersistenceUnit for injecting entitymanagerfactory and Entitymanager
Specific here is not detailed, we can refer to some special articles for annotations!
OK, so the next step is to mention the layering of spring MVC, which is summarized as follows:
When using Java Spring for MVC pattern development, the data model is often divided into two parts: DAO (Data Access Object) and service (business logic model). In the 2nd step, when the controller requests data from the model, it does not request data directly to DAO, but instead requests data through the service to DAO. The advantage of this is that the business logic and database access can be independent, for the future system to replace the data storage media (such as the current system using file system to store data, the future can be replaced with the use of database storage, or now using MSSQL storage data, future replacement of MySQL, etc.) provides a lot of flexibility. The controller only needs to invoke the method in the service interface to get or process the data, and the service layer passes the data of the controller to the DAO layer, which is responsible for writing the processed data to the database after the business logic processing. The service layer uses the abstract factory pattern to achieve low coupling between the service layer and the DAO layer, and it does not know how the DAO layer is implemented, nor does it really need to know which database or file system the system is using.
Action (Controller), Dao (data access Layer), service (business logic)! View layer (views JSP, etc.)!
Finally, we have to go back to the structure of the spring MVC framework, presumably following the summary below:
The core container Core container provides the basic functionality of the Spring framework. The main component of the core container is Beanfactory, which is the implementation of the factory pattern. The beanfactory uses the inversion of control (IOC) pattern to separate the application's configuration and dependency specifications from the actual application code.
Spring Context The spring context is a configuration file that provides contextual information to the spring framework. The Spring context includes enterprise services such as JNDI, EJB, e-mail, internationalization, checksum scheduling.
Spring AOP through configuration management features, the Spring AOP module directly integrates aspect-oriented programming capabilities into the spring framework. Therefore, it is easy to enable any object managed by the Spring framework to support AOP. The spring AOP module provides transaction management services for objects in spring-based applications. By using Spring AOP, you can integrate declarative transaction management into your application without relying on EJB components.
Spring DAO The JDBC DAO abstraction layer provides a meaningful exception hierarchy that can be used to manage exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the number of exception codes that need to be written (such as opening and closing connections). Spring DAO's JDBC-oriented exception conforms to the common DAO exception hierarchy.
Spring ORM The Spring framework inserts several ORM frameworks, providing ORM object-relational tools, including JDO, Hibernate, and IBatis SQL Map. All of these conform to Spring's common transaction and DAO exception hierarchies.
Spring Web Module The Web context module is built on top of the application context module and provides the context for Web-based applications. Therefore, the Spring framework supports integration with Jakarta Struts. The Web module also simplifies the process of working with multipart requests and binding request parameters to domain objects.
Spring MVC Framework The MVC framework is a full-featured MVC implementation of building WEB applications. With the policy interface, the MVC framework becomes highly configurable, and MVC accommodates a large number of view technologies, including JSP, Velocity, Tiles, IText, and POI.
The functionality of the Spring framework can be used in any Java EE server, and most features are also available in an out-of-management environment. The core point of Spring is to support reusable business and data access objects that are not tied to a particular Java EE service. There is no doubt that such objects can be reused across different Java EE environments (Web or EJB), standalone applications, and test environments.
PS: Outside the question to know: Springmvc Workflow description
-
Sends an HTTP request to the server, and the request is captured by the front controller dispatcherservlet.
-
Dispatcherservlet the requested resource Identifier (URI) based on the configuration of the <servlet-name>-servlet.xml to parse the URL of the request. Then, based on the URI, call handlermapping to get all the related objects of the handler configuration (including the handler object and the interceptor corresponding to the handler object), and finally return as a Handlerexecutionchain object.
-
Dispatcherservlet according to the obtained handler, choose a suitable handleradapter. (Note: If Handleradapter is successfully obtained, the Prehandler (...?) of the interceptor will start executing. method).
-
Extract the model data from the request, populate the handler entry, and start executing the handler (Controller). In the process of populating the handler, depending on your configuration, spring will do some extra work for you:
Httpmessageconveter: Converts a request message (such as JSON, XML, and so on) into an object, converting the object to the specified response information. Data transformation: Data conversion for a request message. such as string conversion to Integer, double, and so on. Data is initialized: Data is formatted for the request message. such as converting a string into a formatted number or a formatted date. Data validation: Verify the validity of the data (length, format, etc.), and verify that the results are stored in Bindingresult or error.
-
When the Handler (Controller) executes, returns a Modelandview object to Dispatcherservlet;
-
Based on the returned Modelandview, select a suitable viewresolver (must be viewresolver already registered in the spring container) to return to Dispatcherservlet.
-
Viewresolver combines model and view to render the view.
-
The view is responsible for returning the rendered result to the client.
6, the table Query method, Cartesian product through what connection to get sql to ' a ', ' B ', ' C ', ' d ' sort, the order of their own designated
A: Even the table Query method, I roughly said three, the introduction of the previous answer: say the truth, since the resignation of the study has been a long time since the use of SQL statements, about the connection of the light by memory words, is completely ignorant, fortunately he is not stupid, very natural according to the literal understanding, I very good answer out, left Join is to return records that include all the records in the left table and the join fields in the right table, so the interviewer will ask you, if there is a table, there are 3 records of A, B, 4 records, then if the conditions are satisfied, A left join B-C record will be detected, the answer is no! Well, right join is the opposite of the left join, and the inner join equivalent joins only return rows that are equal to the junction fields in the 2 table! Talking about here I stopped, perhaps the interviewer felt that my answer is not comprehensive enough, so remind me that Descartes product how to achieve, I think, suddenly out of the brain out of a cross join, then blurted out, crossed the connection, then the interviewer, then went down to ask me what sort of general, I answer, order BY, and then is to mention the meaning of DESC and ASC, a descending an ascending nothing to say, the last changed a turn, ask me, give me a B C d four characters let me follow the custom way to sort how to implement, such as sorting into B a C D I honestly do not know ...
7. Distributed
The last question is asking me to understand the distributed no, I said a little look at the next, do not know, this time is going to see ...
ps:spring MVC module and function is the final answer, so answer these, the interviewer let me ask some questions, casually asked some, is regretted not to ask me that a few unanswered questions, originally is to ask, finally unexpectedly forget!
February 22, 2017 22:44:18 summary by small brother Sau
Java Development NetEase Telephone interview one side summary