Big factory interviews get high salaries, knowing this is almost the same!

Let’s talk with you. If you want to find a high-paying job, it is the most basic to learn solid basic knowledge and professional skills. Today I have integrated some interview questions that have successfully obtained high-paying jobs in large factories and summarized the following interview essentials Knowledge points, I hope it will be helpful to everyone. {There are various interview information questions at the end of the article}

1. What is the difference between String, StringBuffer and StringBuilder? Why is String immutable?

  • String is a string constant, StringBuffer and StringBuilder are string variables. The character content of the latter two is variable, while the content of the former is immutable after creation.
  • String is immutable because the String class is declared as a final class in the JDK.
  • StringBuffer is thread-safe, while StringBuilder is not thread-safe.

Supplementary note: thread safety will bring additional system overhead, so StringBuilder is more efficient than StringBuffer. If you have a good grasp of whether the threads in the system are safe, you can use StringBuffer and add the keyword Synchronize where the threads are not safe.

2. What is the difference between Vector, ArrayList and LinkedList?

  • Vector and ArrayList are stored in memory in the form of arrays, and LinkedList is stored in the form of linked lists.
  • The elements in List are ordered and repeating elements are allowed, while the elements in Set are disordered and repeating elements are not allowed.
  • The Vector thread is synchronized, and the ArrayList and LinkedList threads are not synchronized.
  • LinkedList is suitable for insertion and deletion operations at a specified location, but not for searching; ArrayList and Vector are suitable for searching, but not suitable for insertion and deletion at a specified location.
  • ArrayList will automatically expand about 50% of the container size when elements fill the container, while Vector is 100%, so ArrayList is more space-saving.

3. What is the difference between HashTable, HashMap and TreeMap?

  • HashTable thread synchronization, HashMap non-thread synchronization.
  • HashTable does not allow <key, value> to have null values, HashMap allows <key, value> to have null values.
  • HashTable uses Enumeration and HashMap uses Iterator.
  • The default size of the hash array in HashTable is 11, and the increase method is old*2+1. The default size of the hash array in HashMap is 16, and the increase method must be an exponential multiple of 2.
  • TreeMap can sort the records it saves according to the key, the default is ascending order.

The above three questions are related to some of the more advanced data structures in the Java language, from string correlation to containers to data structures such as hash tables and trees. Therefore, we need to go deeper when learning the Java language. Compare the usage scenarios of similar data structures and their advantages and disadvantages.

4. What is the difference between Tomcat, Apache and JBoss?

  • Apache is an HTTP server, Tomcat is a Web server, and JBoss is an application server.
  • Apache parses static Html files; Tomcat can parse jsp dynamic pages and can also act as a container.

For the server, there may not be too much involved in the interview. Relatively speaking, the principles behind such as Linx and Tomcat may be more favored by interviewers.

5. The difference between GET and POST request?

Basic knowledge: The HTTP request format is as follows.


It mainly contains three pieces of information:

  • Type of request (GET or POST)

  • The resource to be accessed (eg resimga.jif)

  • HTTP version (http/1.1)

the difference:

  • Get gets data from the server, and Post sends data to the server.

  • On the client side, the Get method submits the data through the URL, and the request message can be seen in the URL address bar. The message has been encoded; the Post data is submitted in the Html header.

  • For the Get method, the server uses Request.QueryString to obtain the value of the variable; for the Post method, the server uses Request.Form to obtain the submitted data value.

  • The maximum number of data submitted by Get is 1024 bytes, while Post has no limit.

  • The parameters and parameter values ​​submitted by Get method will be displayed in the address bar, which is not safe, but Post will not, which is relatively safe.

6. What is the difference between Session and Cookie?

  • Session is a server-side storage space maintained by the application server; Cookie is the client-side storage space and is maintained by the browser.
  • The user can decide whether to save the Cookie through the browser settings, but cannot decide whether to save the Session, because the Session is maintained by the server.
  • Objects are stored in Session, and strings are stored in Cookies.
  • Session and Cookie cannot be used across windows. Each time a browser is opened, the system will assign a SessionID. At this time, the SessionID is different. To complete cross-browser access to data, you can use Application.
  • Session and Cookie have expiration time, and will be automatically deleted after expiration, reducing system overhead.

Seven, HTTP message contains content

It mainly consists of four parts:

  • request line

  • header line

  • blank line

  • request body

The above three questions are the basic knowledge of network programming. As a Java engineer, you also need to master the knowledge of HTTP, and now HTTPS has also become a standard, and you need to further understand. In addition, compared to the HTTP 1.0/1.1 protocols that everyone has learned in textbooks or classrooms, many companies have entered the HTTP 2.0 era, so the difference between the two also requires us to further understand.

Eight, Servlet life cycle

Roughly divided into 4 parts: Servlet class loading -> instantiation -> service -> destruction

The sequence diagram of Servlet in Tomcat is as follows:

  • The Web Client sends an HTTP request to the Servlet container (Tomcat).

  • The Servlet container receives the client's request.

  • The Servlet container creates an HttpRequest object and encapsulates the request information of the Client into this object.

  • The Servlet creates an HttpResponse object.

  • Servlet calls the service method of the HttpServlet object, passing the HttpRequest object and HttpResponse object as parameters to the HttpServlet object.

  • HttpServlet calls the method of the HttpRequest object to obtain the Http request and process it accordingly.

  • After processing, HttpServlet calls the method of HttpResponse object and returns the response data.

  • The Servlet container sends the response result of HttpServlet back to the client.

   Three of the methods illustrate the life cycle of a servlet:

  • init(): Responsible for initializing the Servlet object.
  • service(): Responsible for responding to client requests.
  • destroy(): When the Servlet object is launched, it is responsible for releasing the occupied resources.

9. The difference between Statement and PreparedStatement, what is SQL injection, and how to prevent SQL injection?

  • PreparedStatement supports dynamic setting of parameters, but Statement does not.
  • PreparedStatement can avoid coding troubles like single quotes, but Statement cannot.
  • PreparedStatement supports precompilation, but Statement does not.
  • PreparedStatement is not easy to check when the SQL statement is wrong, but Statement is easier to check.
  • PreparedStatement can prevent SQL from helping and is more secure, but Statement cannot.

Supplementary explanation-what is SQL injection and countermeasures: 

A method for querying database data without parameters through the splicing of SQL statements. If the SQL statement to be executed is select * from table where name = "+appName+", use the input of the appName parameter value to generate a malicious SQL statement. For example, pass in ['or'1'='1']. Executed in the database. Therefore, you can use PrepareStatement to avoid SQL injection. After receiving the parameter data on the server side, verify it. At this time, the PrepareStatement will be automatically detected, but the Statement does not work and requires manual detection.

Ten, the difference between sendRedirect and foward

  1. Forward is the server-side control page redirection, and the redirected address will not be displayed in the browser address of the client; sendRedirect is a complete redirection, and the browser will display the redirected address and resend the request link. Principle: Forward is the server requesting resources. The server directly accesses the URL of the target address, reads the response content of that URL, and then returns the content to the browser. The browser does not know where the content sent by the server comes from. Yes, so the address bar is still the original address.

  2. Redirect means that the server sends a status code based on logic to tell the browser to re-request the address, and the browser will re-send the new request with all the parameters just now.

The above three questions go a step further on the previous network-related knowledge and rise to the relevant knowledge of Java network programming. This part is intended to examine the interviewer's mastery of the relevant knowledge of Java network programming.

11. Talk about the understanding of Hibernate, the role of the primary and secondary caches, how does Hibernate use the cache in the project?

Hibernate is a developed object-relational mapping framework (ORM). It encapsulates JDBC with very object, Hibernate allows programmers to operate relational database in an object-oriented way.

Advantages of Hibernate:

  • Program is more object-oriented
  • Increased productivity
  • Easy to transplant
  • Non-invasive

Disadvantages of Hibernate:

  • Slightly less efficient than JDBC
  • Not suitable for batch operations
  • Only one relationship can be configured

Hibernate has four query methods:

  • The get and load methods query the object based on the ID number.
  • Hibernate Query Language, HQL
  • Standard query language
  • Query via SQL

How Hibernate works:

  • Configure the Hibernate object-relational mapping file, start the server
  • The server reads the configuration content of the hibernate.cfg.xml file by instantiating the Configuration object, and builds tables and the mapping relationship between the tables according to related requirements.
  • Create a SessionFactory instance through the instantiated Configuration object, and create a Session object through the SessionFactory instance.
  • The database is added, deleted, modified and checked through the Session object.

State transition in Hibernate:
temporary state (Transient)

  • Not in session cache
  • No object records in the database

Supplementary explanation-how Java enters a temporary state:

  • When creating an object through the new statement.
  • When the delete() method of Session is first called, when an object is deleted from the Session cache.

Persisted state (Persisted)

  • In session cache
  • There is no object record in the persistent object database
  • Session will save the two synchronization at a specific moment

Supplementary note-how Java enters the persistent state:

  • Save() method of Session.
  • Object returned by Session's load().get() method.
  • The objects stored in the list collection returned by the Session find() method.
  • The update().save() method of Session.

Detached

  • No longer in the session cache
  • Free objects are transformed from persistent state, and there is no corresponding record in the database.

Supplementary explanation-how Java enters the state of displacement:

  • Session的close()。
  •  The evict() method of Session deletes an object from the cache.

The cache in Hibernate mainly includes Session cache (first level cache) and SessionFactory cache (second level cache, generally provided by a third party).

12. Talk about the difference between Hibernate and iBatis, which performance will be higher

  • Hibernate prefers object operations to achieve the purpose of database-related operations; iBatis prefers SQL statement optimization.
  • The query statement used by Hibernate is its own HQL, while iBatis is a standard SQL statement.
  • Hibernate is relatively complicated and not easy to learn; iBatis is similar to SQL statements, simple and easy to learn.

Performance aspects:

  • If the system has huge data processing capacity and extremely demanding performance requirements, it is often necessary to manually write high-performance SQL statements or error storage procedures. At this time, iBatis has better controllability, so the performance is better than Hibernate.

  • Under the same requirement, because Hibernate can automatically generate HQL statements, and iBatis needs to write SQL statements manually, the efficiency of using Hibernate is higher than that of iBatis.

13. Understanding of Spring, what do you use in the project? How to use it? Understanding and implementation principles of IOC and AOP.

Spring is an open source framework in the control layer of the MVC model. It can respond to rapid changes in requirements. The main reason is that it has the advantage of aspect-oriented programming (AOP). Secondly, it improves system performance because of the dependency inversion mechanism ( IOC), the objects used in the system are not all instantiated when the system is loaded, but the objects of this class will be instantiated when this class is called, thereby improving system performance. These two excellent performances make Spring favored by many J2EE companies. For example, Spring related technologies are the most used in Ali.

Advantages of Spring:

  • The coupling between components is reduced, and the decoupling between software layers is realized.

  • Many services that are easy to provide can be used, such as transaction management, message service, logging, etc.

  • The container provides AOP technology, which can easily implement functions such as permission interception and runtime monitoring.

AOP technology in Spring is a dynamic proxy mode in design patterns. Only need to implement the dynamic proxy interface InvocationHandler provided by jdk, all the methods of the proxy object are taken over by InvocationHandler for actual processing tasks. In aspect-oriented programming, we must also understand the concepts of entry point, aspect, notification, and weaving.
IOC in Spring uses Java's powerful reflection mechanism to achieve. The so-called dependency injection means that the dependency between components is determined by the container at runtime. Among them, there are two methods of dependency injection, through constructor injection, and through set method.

14. Describe the Struts workflow

  • When the web application is started, the ActionServlet is loaded and initialized. The ActionServlet reads configuration information from the struts-config.xml file and stores them in each configuration object.
  • When the ActionServlet receives a client request, it first retrieves the ActionMapping instance that matches the user request, and if it does not exist, returns the invalid information of the user request path.
  • If the ActionForm instance does not exist, create an ActionForm object, and save the form data submitted by the client to the ActionForm object.
  • Determine whether the form needs to be validated according to the configuration information. If necessary, call the validate() method of ActionForm. If the validate() method of ActionForm returns null or returns an ActionErrors object that does not contain ActionMessage, it means that the form validation is successful.
  • ActionServlet decides which Action the request is forwarded to according to the mapping information contained in the ActionMapping instance. If the corresponding Action instance does not exist, it will first create an instance and then call the execute() method of the Action.

The related questions in the above part examine the Java language-related framework used by the interviewer in actual software development and the degree of understanding of the framework principle. In this part, we need to pay attention to some common frameworks. Not only need to know what they do, but also need to know them. The principle behind, the frameworks that are often asked include Spring Boot/Spring Cloud Family Bucket, Hibernate, MyBaits, Netty, Kafka, etc. The most important is the open source Apache Dubbo framework of Alibaba.

15. About the Java memory model

An object (two properties, four methods) is instantiated 100 times, the current storage state in memory, several objects, several properties, and several methods. Since the new objects in Java are all placed in the heap, if you want to instantiate 100 times, 100 objects will be generated in the heap. Generally, the object and its attributes and methods belong to a whole, but if the attributes and methods are Static is declared with the static keyword, then the attributes and methods belonging to the class will always only exist in memory.

16. Reflections

It's mainly a concept. Where do you need a reflection mechanism? How to optimize the performance of reflection?

The definition of reflection mechanism:
in the running state, for any class, you can know all the attributes and methods of this class, and for any object, you can call any method of a class through the reflection mechanism. This kind of dynamic acquisition of class information And the function of dynamically calling methods of class objects is called the reflection mechanism of java.

The role of reflection:
1. Dynamically create an instance of the class, bind the class to an existing object, or obtain the type from an existing object.
2. The application needs to load a specific class from a specific assembly at runtime.

17. Thread synchronization, how to control concurrent operations?

In Java, you can add the keyword syschronized before the method name to handle the problem when multiple threads access shared resources at the same time. syschronized is equivalent to a lock. When an applicant applies for the resource, if the resource is not occupied, the resource is delivered to the applicant for use. During this period, other applicants can only apply for the resource and cannot use the resource. After the resource is used, the lock on the resource will be released, and other applicants can apply for use. Concurrency control is mainly for resource reading and writing problems caused by multi-threaded operations. If no space is added, deadlocks may occur, such as reading dirty data, non-repeatable reading, and missing updates.

Concurrent operations can be controlled by locking, which can be divided into optimistic locks and pessimistic locks.

Pessimistic lock: The pessimistic lock concurrency mode assumes that there are enough data modification operations in the system so that any certain read operation may be affected by data modifications made by individual users. That is to say, pessimistic lock assumes that conflicts will always occur, and avoid conflicts by monopolizing the data being read. However, exclusive data will cause other processes to be unable to modify the data, which will cause blockage. Reading data and writing data will block each other.

Optimistic locking: Optimistic locking assumes that the system's data modification will only produce very few conflicts, which means that any process is unlikely to modify the data that other processes are accessing. In the optimistic concurrency mode, there will be no conflicts between read data and write data, only conflicts between write data and write data. That is, reading data will not cause blocking, only writing data will cause blocking.


The above is the whole content of this article. Finally, I will share some interview materials with you for free, I hope it will be helpful to everyone: click here, click here, password: CSDN

  •  

     

Guess you like

Origin blog.csdn.net/weixin_46577306/article/details/109205939