Java Senior Engineer face questions summary and reference answers

Source: Internet
Author: User
Tags aop database load balancing mysql query new set volatile java web mysql index redis cluster

First, the basic summary of interview questions

1, the JVM structure principle, the GC working mechanism detailed

A: Specific reference: JVM structure, GC working mechanism in detail, when it comes to GC, remember two points: 1, GC is responsible for reclaiming all the memory space without any reference object. Note: Garbage collection is collected without any reference to the object occupied by the memory space instead of the object itself, 2, GC recycling mechanism of two algorithms, a, reference counting method B, the Accessibility analysis algorithm (here, you can see the basic 2 Java object of what period), as for more detailed GC algorithm introduction, You can refer to: Java GC mechanism algorithm

2. The life cycle of Java objects

A: Create phase, application phase, invisible stage, unreachable stage, collection stage, end stage, object space redistribution phase, and more, refer to: Java object life cycle

3, map or HashMap storage principle

A: HashMap is a structure of the array + linked list, the specific reference: HASHMAP implementation principle

4. When a and B fields in a data table are indexed together, will there be an index effect by using a alone or using B alone? (How to use a like query for indexed effects)

A: Look at a, B two fields do the combination index, who in front, who in the back, if a in front, then use a alone will have an index effect, using B alone is not, and vice versa. Similarly, when using a like fuzzy query, if you use only the previous%, then there is an index effect, if you use a double% number match, then no index effect

5, how to consider the time zone conversion problem when the database stores the date format?

A: Using timestamp, reason reference: time zone conversion problems encountered in Java programming

6. What are the methods in the Java object class?

Answer: What are the methods of object

7. HTTP protocol, the difference between get and post

A: Talking about the difference between get and post in HTTP

Second, threading, design patterns, caching aspects

1, Simpledataformat is non-thread-safe, how to better use and avoid the risk?

Answer: About SimpleDateFormat security time-formatted thread safety issues

2, how to look at the design pattern, and simply say your understanding of the observer pattern

A: 1, the design mode of God Horse 2, the observer pattern and the implementation of the class diagram

3, in the cluster environment, the session how to realize sharing

For:

1. Session Sharing of Java cluster

2, session multi-server sharing scheme, there is also a solution is to use a fixed server dedicated to maintain session, other servers share

4, distributed, cluster environment, how to refresh the cache, how to keep in sync?

For:

A, how does the cache refresh? 1, timed refresh 2, active refresh coverage, each cache frame has its own refresh mechanism, or cache invalidation mechanism, take redis and Ehcache for example, they have their own expiration mechanism, in addition to actively refresh the overlay, just get the corresponding key to cover the data can be

B. How does the cache stay in sync? This redis has its own cluster synchronization mechanism, that is, the replication function, specific reference: based on the Redis distributed cache implementation, Ehcache also has distributed cache synchronization configuration, only need to configure a different server address, reference: Ehcache Distributed Cache synchronization

5, a SQL execution too long time, how do you optimize, from what?

For:

1. See if SQL involves multiple tables or subqueries, and if so, see if business splits are possible, related fields are redundant or merged into temporary tables (business and algorithmic optimization)

2, related to the list of queries, whether it can be divided into table query, the results of a single table query after the field integration

3, if the above two can not operate, not to list query, then consider the corresponding query conditions to do the index. Speed up queries

4, for a large number of tables for the separation of historical tables (such as the trade table)

5, the database master-slave separation, read and write separation, reduce reading and writing for the same table pressure, as for master-slave synchronization, MySQL has its own binlog to achieve master-slave synchronization

6, explain analysis SQL statement, view execution plan, analyze index is used, analyze scan line number, etc.

7. Check the MySQL execution log to see if there are any other issues

Personal understanding: Fundamentally, the query is slow to occupy more than MySQL memory, then you can consider this aspect of the hand

Three or three major framework issues 1, spring transaction isolation, and say the difference between each isolation solution: Spring Transaction
2. The propagation behavior of Spring affairs, and the difference of each communication behaviorAnswer: A detailed explanation of spring transactions
3, the difference between hibernate and Mybatis/ibatis, why choose? Answer: The comparison between Hibernate and MyBatis
4, struts and the advantages and disadvantages of spring MVC, let you choose how to choose the answer: spring MVC and the difference between struts
5. Brief talk about spring transaction mechanism solution: Spring transaction mechanism
6, Spring 4.0 new features: Spring4 Four, load balancing, cluster-related 1, WebLogic load Balancing principle and cluster configuration solution: A, WebLogic load Balancing principle B, load balancing and cluster configuration (reference)
2, Nginx+tomcat+redis to achieve load balancing, resource separation, session sharing solution: Configuration Reference
3, nginx configuration file Details--nginx.conf answer: Nginx configuration file Detailed description five, the project optimization related 1, the web How to optimize the project solution: I've done this once. Web project performance optimization (collation)
2. How many kinds of singleton mode? How to optimize? Solution: 7 Usage in a singleton pattern
3, simple talk about the principle and implementation of thread pool solution: Threading principle and implementation vi. concurrency and Security 1. How to deal with the project concurrency? (We are Web projects) Answer: High concurrency Web site solution, in addition, there are database optimistic lock, database read and write separation, using Message Queuing, multi-use stored procedures and so on
2, simple to say that the function of the privileges of the level of permission vulnerabilities and vertical access to the vulnerability of the scene and solution (because we currently have permission level is functional permissions) Answer:
A, horizontal permissions vulnerability, such as
Assuming that the agency has user A and User B two users, where a has 1, 2, and 3 permissions, User B has 2 and 3 permissions, this time assume that User B knows 1, and to add 1 of their rights, this is the level of permissions vulnerability.
Current solution: 1, restrict the entry, so that User B cannot edit their own permissions 2, to User B cannot be extended. The most fundamental solution is to drill down to data permissions
Answer: Horizontal permissions vulnerability and resolution

B, Vertical Permissions Vulnerability
Answers: Vertical Permissions vulnerability Cases and solutions
3, the picture on the platform how to anti-theft chain solution: HTTP Download anti-theft chain principle: HTTP protocol field Referer record to achieve
4, how to distinguish the uploaded pictures is not a Trojan horse? Answer: 1, look at the uploaded picture suffix 2, how to suffix is tampered with, then each file has a magic digital file upload-magic number
5, the principle of Message queuing and implementation of the answer: 1, Message Queuing Principle 2, in-depth message Queue Activemq Seven, the database aspect 1, the MySQL query field area is not case-sensitive? Answer: Do not differentiate, even if the value is not differentiated (I asked at the time, the area of the application of the size of the meaning of what, the interviewer did not say)
2, simply say the database cluster and load balancing, distributed (I do not understand this piece) answer: Database load balancing and cluster reference, reference 2
3, the structure and advantages of stored procedures: approximate structure
Advantages and disadvantages of stored procedures
4, the trigger principle and the role of the answer: Refer to the Java underlying basic problem

1, the principle of SPRINGMVC and how to render the return data to jsp/html?

A: The core of Spring MVC is dispatcherservlet, a request passed through Dispatcherservlet, forwarded to handlermapping, then reflected, corresponding  The @requestmapping address of the controller and the methods inside it, and the final return to the corresponding view via Modelandview and Viewresoler. For specific reference: how Spring MVC Works

2. How do I let the caller know when a Class object property has changed?

A: Java event time monitoring, which is triggered when the Set method changes properties, this mode can also be understood as the observer pattern, specific view: Observer pattern simple case and description

3. Rewrite equals why do you want to rewrite hashcode?

A: To determine whether two objects are equal, the comparison is its hashcode, if you overload the Equals, for example, based on the content of the object implementation, while preserving the hashcode implementation is not changed, it is likely that the two objects are obviously "equal", and hashcode is not the same. Hashcode is not the same, you cannot assume that two objects are equal

4. What about your understanding of the JVM?

A: A very important feature of the Java language is its independence from the platform. The use of Java virtual machines is the key to achieving this feature. The Java compiler generates code or bytecode files that the JVM can understand as long as it is oriented to the JVM. The Java source file is compiled into a bytecode program that translates each instruction into a different platform machine code through the JVM, running through a specific platform.

The process by which the JVM executes the program: I. Load. class file, II. Managing and allocating memory, Iii. performing garbage collection

JRE (Java Runtime Environment) the running environment of Java programs constructed by the JVM

Specific details: JVM Principle and tuning

5. What is the level of the MySQL thing isolation?

A: MySQL thing isolation level is actually the same as spring's thing isolation level, are 1, read UNCOMMITTED (reading uncommitted content), 2, read Committed (read the submission), 3, repeatable read (can reread), 4, Serializable (serializable) Specific reference: MySQL thing isolation level

6. Spring principle

A: The core of spring is IOC and AOP, the IOC is dependency injection and control inversion, its injection method can be divided into set injection, constructor injection, interface injection and so on. The IOC is a container that is responsible for instantiating, locating, configuring objects in the application, and establishing dependencies between those objects. The simple understanding is that Java each business logic processing requires at least two or more objects to work together, but each object in the use of its co-object, the need for frequent new objects to implement, you will find that the coupling between objects is high. The IOC's idea is that the spring container manages these, and the object only needs to deal with its own business relationship. As for what is control reversal, it is the way to get dependent objects reversed.
AOP, aspect-oriented programming, the most direct manifestation is the spring things management. As for the relevant information of spring, we will not elaborate, reference: Spring Annotated Things management

7. Talk about your understanding of NIO

A: IO is a stream-oriented, NIO is buffer-oriented, here is not a detailed reference: the difference between Java NiO and IO

8, the difference between ArrayList and LinkedList, vector?

A: It must be understood as:.

1.ArrayList is the realization of the data structure based on dynamic array, LinkedList data structure based on linked list.
2. For random access get and set,arraylist feel better than LinkedList, because linkedlist to move the pointer.
3. Add and Remove,linedlist for new and delete operations are dominant because ArrayList is moving data

Vector and ArrayList similar, but belong to the strong synchronization class, that is, thread-safe, specific comparison reference: Compare ArrayList, LinkedList, Vector

9, casually talk about a few singleton mode, and choose a thread-safe

A: Singleton categories: lazy, a hungry man, enumeration, static internal class, double check lock and so on, select thread safety I chose the last, double-check lock. Specific implementation methods reference: Java: Seven Ways to make a single case pattern

10. Talk about red and black trees

Answer: The algorithm and data structure has been my weak point, this aspect said oneself fill, the effect is not big, here I recommend one: red black tree

11, for example to say a few sort, and explain its sorting principle

A: I'm not going to go into detail here, let's take a look at Java implementation of several common sorting algorithms

12. mysql Index principle

A: The role of the index everyone knows, is to speed up the query speed, but the principle, I can not say, here to see directly: MySQL index how it works

13. The principle and function of serialization

A: Serialization (serialization) is a process of describing objects in a sequence of bytes, and deserializing deserialization is a process of re-building these bytes into an object. It is mainly used for the propagation of object parameters during HTTP or WebService interface transmission, see: Java Serialization mechanism and principle

Ix. Concurrency and Project tuning

1, say a few ways to realize the thread safety?

Answer: What is thread safety? My understanding is that an object that is accessed concurrently by multiple threads can maintain the order and synchronization of its internal properties, and is considered thread-safe.  Three ways to implement thread safety: be modified by keywords such as volatile, synchronized, or use the class library below Java.util.concurrent. As for the relationship between the former two, refer to: Synchronized and volatile usage differences

2, how to achieve better asynchronous inside the method?

A: We know that async is actually getting another thread to run, so how do I create a thread? The first is the direct new Thread, and the second is the implementation class that implements the Runnable interface. Third, through the thread pool to manage the creation and so on, here is the better implementation of async, that is to say we avoid frequent new threads inside the method, we can consider the thread pool. So how does the thread pool create? You can create a new thread pool here, but you need to consider a singleton, or create a thread pool when the program is initially Qidong, let him run, and then, at the time of the method, creating threads by thread pool to implement asynchronous

3. Why should I use cache in the project? How do I understand Nginx + tomcat + redis cluster cache?

Answer 1: The most direct performance is to reduce the pressure on the database. Avoid the possibility of a program outage due to frequent or oversized data reads that affect database performance

2:nginx often do static content services and proxy servers, facing the external request forwarded to the back of the application services. Nginx itself can also do cache, such as static page cache what. Tomcat is an application server that handles Java Web program functionality and so on. You can also understand that, assuming the user's request as a river, then Nginx is equivalent to a water conservancy project, Tomcat is equivalent to a diversion of tributaries, and Redis is equivalent to a single reservoir next to a branch. When you flood, Nginx distributes different amounts of water according to the strength of each tributary, distributing it to each tributary (Tomcat) in a way that ensures the program is running normally. And the Redis equivalent of a tributary of the reservoir, storage water, reduce pressure, so that the back of the water smooth.

4. In daily projects, if you take over, where are you going to tune in?

A: The first is to understand what needs to be optimized, the need for optimization must be the performance of the project bottleneck or speculation is imminent, we will consider optimization. So how to optimize?

A, expansion, expansion of the understanding of the expansion of the server parallel processing capacity, simply to add the server, increase the ability to process requests, such as increased nginx, Tomcat and other application server number, or the number of physical servers, as well as increase the server bandwidth, and so on, here is to consider the hardware

B. Tuning and tuning, including system tuning and code tuning. System tuning means faster processing speed, such as the CDN, Ehcache, Redis and other cache technology mentioned, message queue, etc., to speed up the response between services, increase system throughput, avoid concurrency, as for code tuning, these need to accumulate, such as refactoring, factories, etc. Database tuning I'm not quite sure of that. Index and stored procedures, specific reference: MySQL Database tuning 21 best practices, other database tuning aspects look for yourselves.

5. Talk about your understanding of distributed

A: Personal understanding: Distributed is to split a system/business into multiple subsystems/sub-business to work together, this process is called distributed, the specific evolution of the reference: Java Distributed Application Technology architecture Introduction

6. Redis implements Message Queuing

Answer: Redis implements Message Queuing, reference 2

7, another summary of multi-threaded related questions 50 road

8. Share a tuning tool and solution: How to use Jconsole to observe and analyze the operation of Java programs, and to perform debugging and tuning

Ten, handwritten code questions (including SQL questions)

1, suppose merchant table A (ID, city), Trade flow table B (aid, amount, time) here time represents the trading hours, please write in SQL to query each city monthly sales performance (answer can be in the comments reply)

2. Suppose there is an array a, int[] a = {1, 3,-1, 0, 2, 1,-4, 2, 0, 1 ...   N}; It is necessary to find an array greater than 0, but due to the error of the parameters or other reasons, resulting in the detection of 0 and negative numbers, it is now required to not use the new array and the new set (that is, only use this a array, the factor group data is larger, and can only use one loop) to implement positive numbers in front of the array Numbers less than or equal to 0 are placed at the end of the array (answers can be answered in comments)

XI. Design Program Related

The interview will also ask questions about design options, such as

1, your interface service data is truncated, how do you prevent malicious data submission?

A: We can set a business number in the interface transfer parameter, which is used to distinguish whether or not to commit repeatedly. So even if the data is captured, the other party can not distinguish the meaning of each field, then the role of this business number is coming

2, if the server is often down, where do you troubleshoot the problem?

A: This will be left for you crossing added, can comment reply

Summarize

For the time being summarize these, follow up again, the face question is changeable, the invariable is the knowledge point and the technology fundamental. The foundation is very important, therefore does not accumulate kuibu, not to be thousands of miles, does not accumulate the small stream, does not have to become Jianghai. Learn the foundation, grasp the principle of good technology, and then to practice, so as to understand a technology, learning can not have!

In addition, the interview process, to maintain self-confidence, will not be bold to say no, no good disgrace, not to say you really will not, perhaps forget, perhaps did not notice, remember the interview topic, back to their own supplementary information and related information, I believe you will be more and more calmly, to remember not for the interview and interview, But for the future job interview, if can keep this state, there is nothing to take.

In my own case, many will not, the key is that you would like to learn, willing to put into action. Come on, I hope you can find the right job for all your friends!

I have a public number that often shares some of the dry stuff related to Java technology, and if you like my share, you can use the search for "Java leader" or "Javatuanzhang" for attention.

Java Senior Engineer face questions summary and reference answers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.