Summary of Java interview questions at the end of 2020, 1100 interview questions in more than 20 categories with answer analysis

foreword

2020 is about to pass, summarizing all kinds of Java interview questions, both junior and intermediate, including Java OOP interview questions, Java collection/generic interview questions, Java exception interview questions, Java IO and NIO interview questions , Java reflection interview questions, Java serialization interview questions, Java annotation interview questions, multithreading and concurrency interview questions, JVM interview questions, MySQL interview questions, Redis interview questions, Memcached interview questions, MongoDB interview questions, String interview questions, Spring Boot Interview questions, Spring Cloud interview questions, RabbitMQ interview questions, Dubbo interview questions, MyBatis interview questions, ZooKeeper interview questions, data structure interview questions, algorithm interview questions, Elasticsearch interview questions, Kafka interview questions, microservice interview questions, Linux interview questions.

108 Java OOP interview questions

1. What is B/S architecture? What is C/S Architecture

(1) B/S(Browser/Server), browser/server program

(2) C/S (Client/Server), client/server, desktop application

2. What development platforms does Java have?

(1) JAVA SE: Mainly used in client development

(2) JAVA EE: mainly used in web application development

(3) JAVA ME: Mainly used in embedded application development

3. What is JDK? What is JRE?

(1) JDK: java development kit: java development kit, which is the environment that developers need to install

(2) JRE: java runtime environment: java operating environment, the environment required for the java program to run

4. What are the characteristics of the Java language

(1) Easy to learn and rich class library

(2) Object-oriented (the most important feature of Java, which makes the program less coupled and more cohesive)

(3) Platform-independent (JVM is the foundation of Java's cross-platform use)

(4) Reliable and safe

(5) Support multi-threading

24 Java collection/generic interview questions

The difference between ArrayList and linkedList

Array (array) is an index-based data structure, which uses the index to search and read data in the array very quickly.

The time complexity of Array to get data is O(1), but to delete data is very expensive, because it needs to rearrange all the data in the array, (because after deleting the data, all the subsequent data needs to be moved forward)

Disadvantage: Array initialization must specify the length of initialization, otherwise an error will be reported

For example:

int[] a = new int[4];//推荐使用int[] 这种方式初始化int c[] = {23,43,56,78};//长度:4,索引范围:[0,3]

List—is an ordered collection that can contain repeated elements and provides access by index. It inherits from Collection.

List has two important implementation classes: ArrayList and LinkedList

ArrayList: Can be seen as an array that can automatically increase capacity

The toArray method of ArrayList returns an array

ArrayList's asList method returns a list

The underlying implementation of ArrayList is Array, and the implementation of array expansion

LinkList is a double-linked list, which has better performance than ArrayList when adding and deleting elements. But it is weaker than

ArrayList. Of course, these comparisons refer to a large amount of data or frequent operations.

8 Java exception interview questions

1. What are the two types of exceptions in Java?

2. How many exception handling mechanisms are there?

3. How to customize an exception

4. Try catch fifinally, there is return in try, is finally still executed?

5. Excption and Error package structure

6. The difference between Thow and thorws

7. What is the difference between Error and Exception?

8. What is the difference between error and exception?

 

15 IO and NIO interview questions in Java

1. IO stream in Java?

2. The difference between Java IO and NIO

3. What are the common io classes?

4. The difference between byte stream and character stream

5. Blocking IO model

6. Non-blocking IO model

7. Multiplexing IO model

8. Signal-driven IO model

9. Asynchronous IO model

10、JAVA NIO

11. NIO buffer

12. NIO's non-blocking

13、Channel

14、Buffer

15、Selector

11 Java reflection interview questions

1. In addition to using new to create objects, what other methods can be used to create objects?

2. Is it more efficient to create objects through Java reflection or to create objects through new?

3. The role of java reflection

4. Where will the reflection mechanism be used?

5. Implementation of reflection:

6. Classes that implement Java reflection:

7. Advantages and disadvantages of reflection mechanism:

8. Java Reflection API

9. Reflection usage steps (acquire Class object, call object method)

10. There are several ways to get the Class object

11. Use reflection to dynamically create object instances

 

10 Java serialization interview questions

1. What is java serialization and how to realize java serialization?

2. Save (persist) the object and its state to memory or disk

3. Serialized objects are kept as byte arrays - static members are not saved

4. Serialize user remote object transmission

5. Serializable implements serialization

6. WriteObject and readObject custom serialization strategy

7. Serialized ID

8. Serialization does not save static variables

9. The Transient keyword prevents the variable from being serialized into the file

10. Serialization (implemented in deep clone one)

Java annotation interview questions 2

1. What are the four standard meta-annotations?

2. What are annotations?

108 multithreading and concurrency interview questions

1. There are several ways to implement multithreading in Java

Inherit the Thread class;

Implement the Runnable interface;

Implement the Callable interface to create a Thread thread through the FutureTask wrapper;

Use ExecutorService, Callable, and Future to implement multithreading with returned results (that is, use ExecutorService to manage the previous three methods).

2. Inherit the Thread class

The Thread class is essentially an instance that implements the Runnable interface, representing an instance of a thread. The only way to start a thread is through the start() instance method of the Thread class. The start() method is a native method that starts a new thread and executes the run() method.

 

public class MyThread extends Thread {public void run() {System.out.println("MyThread.run()");}}MyThread myThread1 = new MyThread();myThread1.start(); 

3. Implement the Runnable interface.

If your own class already extends another class, you cannot directly extend Thread. At this time, you can implement a Runnable interface.

 

public class MyThread extends OtherClass implements Runnable {public void run() {System.out.println("MyThread.run()");}} //启动 MyThread,需要首先实例化一个 Thread,并传入自己的 MyThread 实例:MyThread myThread = new MyThread();Thread thread = new Thread(myThread);thread.start();//事实上,当传入一个 Runnable target 参数给 Thread 后, Thread 的 run()方法就会调用target.run()public void run() {if (target != null) {target.run();}}

87 JVM interview questions

1. Will there be a memory leak in java? Please describe it briefly.

meeting. There may be memory leaks when implementing the heaped data structure by yourself, see effective java.

2. In 64-bit JVM, what is the maximum length of int?

In Java, the length of an int type variable is a fixed value, which is 32 bits regardless of the platform. That is to say, in the 32-bit and 64-bit Java virtual machines, the length of the int type is the same.

3. What is the difference between Serial and Parallel GC?

Both Serial and Parallel will cause stop-the-world when GC is executed. The main difference between them is that the serial collector is the default copy collector, and there is only one thread when executing GC, while the parallel collector uses multiple GC threads to execute.

4. For 32-bit and 64-bit JVM, what is the maximum length of int type variable?

In the 32-bit and 64-bit JVM, the length of the int type variable is the same, both are 32 bits or 4 bytes.

5. What is the difference between WeakReference and SoftReference in Java?

Although both WeakReference and SoftReference are beneficial to improve the efficiency of GC and memory, once WeakReference loses the last strong reference, it will be recycled by GC, while soft reference cannot prevent it from being recycled, but it can be delayed until the JVM runs out of memory.

6. What does the JVM option -XX:+UseCompressedOops do? why use

When you migrate your application from a 32-bit JVM to a 64-bit JVM, the heap memory will suddenly increase, nearly doubling, due to the increase in object pointers from 32-bit to 64-bit.

This will also adversely affect data in the CPU cache (which is much smaller than RAM). Because the main motivation for migrating to a 64-bit JVM is that the maximum heap size can be specified, and a certain amount of memory can be saved by compressing OOP. With the -XX:+UseCompressedOops option, the JVM will use 32-bit OOP instead of 64-bit OOP.

7. How to judge whether the JVM is 32-bit or 64-bit through a Java program?

You can check some system properties like sun.arch.data.model or os.arch to get this information.

83 MySQL interview questions

1. Database storage engine

The database storage engine is the underlying software organization of the database, and the database management system (DBMS) uses the data engine to create, query, update and delete data. Different storage engines provide different storage mechanisms, indexing techniques, locking levels, and other functions. Using different storage engines, you can also obtain specific functions. Many different database management systems now support many different data engines. The main storage engines are: 1. MyIsam, 2. InnoDB, 3. Memory, 4. Archive, 5. Federated.

2. InnoDB (B+ tree)

The underlying storage structure of InnoDB is a B+ tree. Each node of the B tree corresponds to a page of InnoDB. The page size is fixed, generally set to 16k. Among them, non-leaf nodes only have key values, and leaf nodes contain completed data

Applicable scene:

1) Tables that are frequently updated are suitable for handling multiple concurrent update requests.

2) Support transactions.

3) Can recover from disasters (via bin-log logs, etc.).

4) Foreign key constraints. Only he supports foreign keys.

5) Supports auto-increment column attribute auto_increment.

3. TokuDB (Fractal Tree-node with data)

The underlying storage structure of TokuDB is Fractal Tree. The structure of Fractal Tree is somewhat similar to B+ tree. In Fractal Tree, each child pointer needs to point to a child node and also has a Message Buffer. This Message Buffer is a FIFO Queue, used to cache update operations.

For example, an insert operation only needs to land on the Message Buffer of a certain node, and it can be returned immediately, without searching for leaf nodes. These cached updates are applied to the corresponding nodes at query time or asynchronously merged in the background.

TokuDB adds indexes online, does not affect read and write operations, and has very fast write performance. Fractal-tree has advantages in transaction implementation. It is mainly suitable for infrequently accessed data or historical data archives.

50 Redis interview questions

1. What is Redis?

Redis is completely open source and free, complies with the BSD protocol, and is a high-performance key-value database.

Redis and other key-value cache products have the following three characteristics:

Redis supports data persistence, which can save the data in memory to the disk, and can be loaded again for use when restarting.

Redis not only supports simple key-value type data, but also provides storage of data structures such as list, set, zset, and hash.

Redis supports data backup, that is, data backup in master-slave mode.

Advantages of Redis

Extremely high performance – Redis can read at a speed of 110,000 times/s and write at a speed of 81,000 times/s. Rich data types – Redis supports Strings, Lists, Hashes, Sets and Ordered Sets data types for binary cases.

Atomic – All Redis operations are atomic, meaning they either succeed or fail at all. Individual operations are atomic. Multiple operations also support transactions, that is, atomicity, wrapped by MULTI and EXEC instructions.

Rich features – Redis also supports publish/subscribe, notification, key expiration and other features.

2. How is Redis different from other key-value stores?

Redis has more complex data structures and provides atomic operations on them, which is an evolutionary path different from other databases. The data types of Redis are based on basic data structures and are transparent to programmers without additional abstraction. Redis runs in memory but can be persisted to disk, so memory needs to be weighed when reading and writing different data sets at high speed, because the amount of data cannot be larger than the hardware memory. Another advantage of in-memory databases is that it is very simple to operate in memory compared to the same complex data structures on disk, so Redis can do many things with high internal complexity. Also, they are compact in terms of on-disk format and are append-generated, since they do not require random access.

3. What is the data type of Redis?

Redis supports five data types: string (string), hash (hash), list (list), set (set) and zsetsorted set: ordered set).

In our actual projects, string and hash are commonly used. If you are an advanced user of Redis, you also need to add the following data structures HyperLogLog, Geo, Pub/Sub.

If you say you have played Redis Module, like BloomFilter, RedisSearch, Redis-ML, the interviewer's eyes will start to shine.

Memcached interview questions 24

1. What is Memcached and what is its function?

Memcached is an open source, high-performance memory storage software. From the name, Mem means memory, and Cache means cache. The role of Memcached: By temporarily storing all kinds of data in the database in the pre-planned memory space, it can reduce the direct high concurrent access of the business to the database, thereby improving the access performance of the database and accelerating the dynamic application service of the website cluster ability.

2. How to realize Memcached service distributed cluster?

Special note: Memcached clusters are different from web service clusters, and the sum of all Memcached data is the database data. Each Memcached is part of the data. (The data of a memcached is part of the data of the mysql database)

a. Program implementation

The program loads the ip list of all mcs by hashing the key (consistent hashing algorithm)

For example: web1 (key)===> corresponding to A, B, C, D, E, F, G... several servers. (implemented by hash algorithm)

b. Load balancer

By hashing the key (consistent hash algorithm), the purpose of the consistent hash algorithm is not only to ensure that each object only requests one corresponding server, but also when the node goes down, the update redistribution ratio of the cache server is minimized.

95 MongoDB interview questions

1. What is mongodb?

MongoDB is written in C++ language and is an open source database system based on distributed file storage. In the case of high load, adding more nodes can guarantee server performance. MongoDB aims to provide scalable high-performance data storage solutions for WEB applications.

MongoDB stores data as a document, and the data structure consists of key-value (key=>value) pairs. MongoDB documents are similar to JSON objects. Field values ​​can contain other documents, arrays and arrays of documents.

2. What are the characteristics of mongodb?

(1) MongoDB is a document storage-oriented database, which is relatively simple and easy to operate.

(2) You can set the index of any attribute in the MongoDB record (such as: FirstName="Sameer", Address="8 Gandhi Road") to achieve faster sorting.

(3) You can create data mirroring locally or over the network, which makes MongoDB more scalable.

(4) If the load increases (requires more storage space and stronger processing power), it can be distributed on other nodes in the computer network. This is called fragmentation.

(5) Mongo supports rich query expressions. The query command uses the markup in JSON form, which can easily query the embedded objects and arrays in the document.

(6) MongoDb can use the update() command to replace completed documents (data) or some specified data fields.

(7) Map/reduce in Mongodb is mainly used for batch processing and aggregation of data.

(8) Map and Reduce. The Map function calls emit(key, value) to traverse all the records in the collection, and passes the key and value to the Reduce function for processing.

(9) Map function and Reduce function are written in Javascript, and MapReduce operation can be executed through db.runCommand or mapreduce command.

(10) GridFS is a built-in function in MongoDB, which can be used to store a large number of small files.

(11) MongoDB allows scripts to be executed on the server side. You can write a function in Javascript and execute it directly on the server side.

You can store the definition of the function on the server side and call it directly next time.

131 Spring interview questions

1. What are the main functions of different versions of Spring Framework?

2. What is Spring Framework?

Spring is an open source application framework designed to reduce the complexity of application development. It is lightweight and loosely coupled. It has a layered architecture that allows users to select components while also providing a cohesive framework for J2EE application development. It can integrate other frameworks, such as Structs, Hibernate, EJB, etc., so it is also called the framework of the framework.

3. List the advantages of Spring Framework.

Due to the layered architecture of Spring Frameworks, users are free to choose the components they need. Spring Framework supports POJO (Plain Old Java Object) programming, which enables continuous integration and testability. JDBC is simplified due to dependency injection and inversion of control. It's open source and free.

92 Spring Boot interview questions

1. What is Spring Boot?

Spring has become more and more complex over the years as new features are added. Just by visiting the official website page, we will see the different features of all Spring projects that can be used in our application. If we have to start a new Spring project, we have to add build path or add Maven dependency, configure application server, add spring configuration. So starting a new spring project is a lot of effort as we now have to do everything from scratch.

Spring Boot is the solution to this problem. Spring Boot has been built on top of the existing spring framework. Using spring boot we avoid all the boilerplate code and configuration we had to do before. Therefore, Spring Boot can help us use existing Spring functions more robustly with the least amount of work

2. Why use Spring Boot

Spring Boot has many advantages, such as:

(1) Independent operation

Spring Boot also embeds various servlet containers, Tomcat, Jetty, etc. Now it no longer needs to be packaged into a war package and deployed to the container. Spring Boot can run independently as long as it is packaged into an executable jar package, and all dependent packages are In a jar package.

(2) Simplified configuration

The spring-boot-starter-web starter automatically depends on other components, simplifying the maven configuration.

(3) Automatic configuration

Spring Boot can automatically configure beans according to the classes and jar packages in the current classpath. For example, adding a spring-boot-starter-web starter can have web functions without other configuration.

(4) No code generation and XML configuration

There is no code generation in the Spring Boot configuration process, and all configuration work can be completed without XML configuration files. All of this is done with the help of conditional annotations, which is also one of the core functions of Spring 4.x.

(5) Application monitoring

Spring Boot provides a series of endpoints to monitor services and applications, and do health checks

There are too many content to show one by one, there are 35 interview questions for Spring Cloud, 32 interview questions for RabbitMQ, 40 interview questions for Dubbo, 28 interview questions for MyBatis, 49 interview questions for ZooKeeper, and 8 interview questions for data structure , 21 algorithm interview questions, 25 Kafka interview questions, 24 Elasticsearch interview questions, 50 microservice interview questions, and 48 Linux interview questions.


These interview questions are organized into a pdf document, with a total of more than 200 pages.

Welcome to pay attention to the public account: programmer chasing the wind, reply 003 to receive this sorted Java interview question manual.

at last

I hope it can help you review before the interview and find a good job, and also save you the time of searching for information on the Internet to learn.

おすすめ

転載: blog.csdn.net/Design407/article/details/106687406