2019 Java interview questions (Tencent)
The following is an interview question from Tencent in 2019. I share it with you. I hope it will be helpful to everyone.
(Recommended video tutorial: java teaching video)
- Choose a project from your resume and tell us what major challenges you encountered in it? And your ideas for solving the problem?
- A piece of code needs to execute multiple redis commands. How to ensure atomicity without locking?
Use lua script: https://segmentfault.com/a/1190000009811453 - Let’s talk about data structures, such as binary trees and red black trees?
Understand this article: https://juejin.im/post/5a27c6946fb9a04509096248 - Talk about the differences and usage scenarios between B-tree and B tree?
- B-tree:
B-tree is a tree constructed by taking advantage of the characteristics of disk blocks. Each disk block has one node, and each node contains many keys. After increasing the node keywords of the tree, the
levels of the tree are fewer than the original binary tree, which reduces the number and complexity of data searches.
B-tree cleverly uses the principle of disk read-ahead to set the size of a node to equal one page (each page is 4K), so that each node only needs one I/O to complete
Full load.
B-tree data can be stored in any node. - B tree:
B tree is a variant of B-tree. B tree data is only stored in leaf nodes. In this way, based on the B-tree, each node stores more keywords, and the tree has fewer levels
, so querying data is faster. All keyword pointers exist in leaf nodes, so the number of searches per time is The same, so the query speed is more stable; - Which version of mysql and which storage engine use B tree for indexing? Why not use red tree?
You need to first understand the implementation principles of B tree and red tree. B tree has sequential access pointers, which red trees do not have. - Talk about the differences between several common message middlewares?
- RabbitMQ is the first choice for small and medium-sized companies: simple management interface and high concurrency.
- More related interview question recommendations: java interview questions and answers
- Large companies can choose RocketMQ: higher concurrency, and customized development of rocketmq.
- For the log collection function, kafka is preferred and is specially prepared for big data.
- How does rabbitmq ensure the reliability of messages?
For details, see "Exam question bank/rabbitmq" - Springcloud service discovery principle?
a. Send a heartbeat check every 30s to renew the lease. If the client cannot renew the lease multiple times, it will be removed from the server registration center within 90s.
a. Registration information and updates will be copied to other Eureka nodes. Clients from any region can find the registration center information. Replication occurs every 30s to locate their services and make remote calls. .
b. The client can also cache some service instance information, so even if Eureka fails, the client can still locate the service address. - Introduce the various components of springcloud? In addition to eureka, what else can be used for springcloud's registration center?
The working principle of springcloud
Features ActiveMQ RabbitMQ RocketMQ kafka
Development language java erlang java scala
Single machine throughput 10,000 level 10,000 level 100,000 level
Timeliness ms level us Level ms level Within ms level
High availability (master-slave architecture) High (master-slave architecture) Very high (distributed architecture) Very high (distributed architecture)
Functional features
Mature The product is used in many companies; it has more documents; it has better support for various protocols
It is developed based on Erlang, so it has strong concurrency capabilities, extremely good performance, and low latency; the management interface is relatively Rich
MQ has relatively complete functions and good scalability
It only supports the main MQ functions. Some functions such as message query and message backtracking are not provided. After all, it is prepared for big data and should be used in the field of big data. Use wide.
springcloud consists of the following core components:
Eureka: When each service starts, Eureka Client will register the service to Eureka Server, and Eureka Client can also pull the registry from Eureka Server in turn, thus Know where other services are
Ribbon: When a request is initiated between services, load balancing is done based on Ribbon, and one machine is selected from multiple machines of a service
Feign: Feign-based dynamic proxy mechanism, according to annotations and the selected machine, splice the request URL address, and initiate the request
Hystrix: The request is initiated through the thread pool of Hystrix. Different services use different thread pools, which realizes the isolation of different service calls and avoids service Avalanche
Problem
Zuul: If the front-end and mobile terminals need to call the back-end system, they must enter through the Zuul gateway, and the Zuul gateway forwards the request to the corresponding service
The registration center is okay Use zookeeper. - How many current limiting methods are there for microservices?
spring cloud gateway: https://windmt.com/2018/05/09/spring-cloud-15-spring-cloud-gateway-ratelimiter/ - In the case of current limiting, service isolation can still Is it necessary?
https://www.javazhiyin.com/25964.html - Dubbo has several types of load balancing? Is load balancing on the server side or the client side?
Dubbo load balancing is on the client side. Dubbo has 4 built-in load balancing strategies:
a. RandomLoadBalance: Random load balancing. Choose one at random. It is Dubbo's default load balancing strategy.
b. RoundRobinLoadBalance: Polling load balancing. Poll to select one.
c. LeastActiveLoadBalance: The minimum number of active calls, random with the same number of active calls. The active count refers to the difference in counts before and after the call. Make the slow Provider receive fewer requests,
because the slower the Provider, the greater the difference in counts before and after the call will be made.
d. ConsistentHashLoadBalance: Consistent hash load balancing. Requests with the same parameters always land on the same machine. - How to implement redis distributed lock? What problem should we pay attention to?
Learn about this article: https://juejin.im/post/5bbb0d8df265da0abd3533a5 - Tell me about the source code you have read? What design patterns or design highlights are used?
For specific analysis, you need to read some source code, such as spring source code, before the interview. - How to implement aop? Where is aop used in the project?
Master: https://juejin.im/post/5bf4fc84f265da611b57f906 - What is the role of the post-processor?
BeanPostProcessor in Spring: https://www.jianshu.com/p/f80b77d65d39 - Spring bean scope, when to use request scope.
Detailed reading: https://blog.csdn.net/icarus_wang/article/details/51586776 - Tell me about the result of the following question?
1 package com.giveu.web; 2 3 public class VolatileTest { 4 public static volatile int race = 0; 5 6 public static void increase() { 7 race++; 8 } 9 10 private static final int THREADS_COUNT = 10; 11 12 public static void main(String[] args) { 13 Thread[] threads = new Thread[THREADS_COUNT]; 14 for (int i = 0; i < THREADS_COUNT; i++) { 15 threads[i] = new Thread(new Runnable() { 16 @Override 17 public void run() { 18 for (int i = 0; i < 10000; i++) { 19 increase(); 20 } 21 } 22 }); 23 threads[i].start(); 24 } 25 while (Thread.activeCount() > 1) { 26 Thread.yield(); 27 } 28 System.out.println(race); 29 } 30
Copy after login
The program does not end and no printing occurs.
Related recommendations: java introductory tutorial
The above is the detailed content of 2019 Java interview questions (Tencent). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4
