Java common interview questions summary

1. Java Basics

 

1. Why is the String class final?

2. HashMap source code, implementation principle, and underlying structure.

3. Talk about a few Java collection classes you know: list, set, queue, and map implementation classes. . .

4. Describe the implementation and difference between ArrayList and LinkedList

5. What are the queues in Java and what are the differences.

6. In reflection, the difference between Class.forName and classloader

7. New features of Java7 and Java8 (asked by baidu, good BT)

8. The operation efficiency of the two structures of Java array and linked list, in which cases (starting from the beginning, starting from the end, starting from the middle), and which operations (insertion, search, deletion) are efficient

9. Investigation and positioning of Java memory leaks: the use of jmap, jstack, etc.

10、string、stringbuilder、stringbuffer区别

11. The difference between hashtable and hashmap

13. The structure of exceptions, runtime exceptions and non-runtime exceptions, for example

14. String a = "abc" String b = "abc" String c = new String("abc") String d = "ab" + "c" . The result of comparing them with ==

15. Common methods of String class

16. What are the reference types in Java?

17. Difference between abstract class and interface

18. The basic type and byte size of java.

19. Hashtable, HashMap, ConcurrentHashMap underlying implementation principles and thread safety issues (it is recommended to be familiar with the jdk source code to answer calmly)

20. If you are not allowed to implement a Map by yourself with the tools provided by Java Jdk, what should you do? After talking for a long time, I talked about the HashMap source code. If I do it, I will learn from the principle of HashMap and talk about the implementation of HashMap.

21. How to deal with Hash conflict? What are the ways to resolve hash collisions?

22. HashMap conflict is very strong, the worst performance, how would you solve it? From O(n) to log(n), I talked about it with the idea of ​​binary sorting tree

23、rehash

24. How to rewrite hashCode() and equals() generation algorithms and methods

 

二 、 Java IO

 

1. Talk about common classes in IO, byte stream, character stream, interface, implementation class, method blocking.

2. Talk about NIO.

3. What is the difference between String encoding UTF-8 and GBK?

4. When to use byte stream and when to use character stream?

5. How to recursively read the files under the folder, how to implement the code

 

3. Java Web

 

1. The difference and connection between session and cookie, the life cycle of session, and session management when multiple services are deployed.

2. Some related problems of servlet

3. Webservice related issues

4, jdbc connection, the steps of the forname method, how to declare the use of a transaction. Example and specific code

5. Configure the main configuration content of web.xml without framework

6. The difference between jsp and servlet

 

4. JVM

 

1. Java memory model and GC algorithm

2. What did jvm performance tuning do?

3. Introduce 7 areas in the JVM, and then explain the situation that each area may cause memory overflow

4. Introduce the abnormal reference of GC and GC Root.

5. Let’s talk about the loading method and loading mechanism from the classload, from the data area of ​​the program runtime, to the memory allocation, to the String constant pool, to the JVM garbage collection mechanism, algorithm, and hotspot. Anyway, all kinds of expansion

6. How does the jvm allocate direct memory, how does the new object not allocate on the heap but on the stack, constant pool analysis

7. The size of the array is placed in the old age of the JVM (not just setting PretenureSizeThreshold , it is usually how big it is, you will know if you don’t ask)

8. Access to arrays in the old age

9. GC algorithm, how to GC permanent generation objects, and how to deal with GC loops

10. Who will be GCed and when?

11. What if you want to avoid being GCed?

12. What if you want to survive 1 time in the GC

 

5. Open source framework

 

1. The difference between hibernate and ibatis

2. Talk about the connection pool of mybatis.

3. Which jar packages need to be referenced in the spring framework, and the purpose of these jar packages

4. The principle of springMVC

5. The meaning of springMVC annotations

6. The connection and difference between beanFactory and ApplicationContext in spring

7. Several ways of spring injection (cycle injection)

8. How does spring implement transaction management

9、springIOC

10. The principle of spring AOP

11. How to use level 1 and level 2 cache in hibernate and the principle of difference (understanding of Lazy-Load)

12. Hibernate's principle architecture, five core interfaces, three state transitions of Hibernate objects, and transaction management.

 

6. Multithreading

 

1. After Java creates a thread, the difference between directly calling the start() method and run()

2. Common thread pool modes and usage scenarios of different thread pools

3. What will happen if the number of threads in the newFixedThreadPool thread pool reaches the maximum value, the underlying principle.

4. The synchronization problem of communication between multiple threads. The synchronized lock is the object, and there are many specific problems related to synchronization. For example, different methods of the same class have synchronized locks, and whether an object can be accessed at the same time. Or the static constructor of a class plus the effect of the synchronized lock.

5. Understand the meaning of reentrant locks and the difference between ReentrantLock and synchronized

6. Synchronous data structures, such as the source code understanding of concurrentHashMap and the internal implementation principle, why it is synchronous and efficient

7. Understanding and use of keywords for thread-safe operations such as atomicinteger and volatile

8. Inter-thread communication, wait and notify

9. The use of timing threads

10. Scenario: In a main thread, it is required that a large number (many, many) of sub-threads are executed before the main thread is executed. A variety of ways, considering efficiency.

11. The difference between a process and a thread

12. What is thread safety? for example

13. Several states of the thread

14. Concurrent and synchronous interfaces or methods

15. Is HashMap thread safe and why is it not? ConcurrentHashMap, thread safety, why is it safe. What is the underlying implementation like.

16. Use of common classes under JUC. An in-depth study of ThreadPool; the use of BlockingQueue. (The difference between take and poll, the difference between put and offer); the implementation of atomic classes.

17. Briefly introduce the situation of multi-threading, starting from the establishment of a thread. Then how to control the synchronization process, the methods and structures commonly used by multithreading

18. Understanding of volatile

19. There are several ways to achieve multi-threading, how to do multi-thread synchronization, and talk about the methods commonly used in several threads

 

Seven, network communication

 

1. HTTP is stateless communication. What are the request methods of HTTP? Can you define a new request method by yourself?

2. Socket communication, as well as long connection, subcontracting, and abnormal disconnection processing.

3. The use of socket communication model, AIO and NIO.

4. The use of the socket framework netty, and the implementation principle of NIO, why is it asynchronous and non-blocking.

5. Synchronous and asynchronous, blocking and non-blocking.

6. OSI seven-layer model, including some basic knowledge of TCP and IP

7. The difference between get post in http

8. Talk about the relationship and difference between http, tcp and udp.

9. Talk about the process of the browser accessing www.taobao.com.

10. HTTP protocol, HTTPS protocol, SSL protocol and complete interaction process;

11. Congestion of tcp, fast return, and discard of ip packets

12. A process of https processing, symmetric encryption and asymmetric encryption

13. Features and differences of head

14. Talk about the process of the browser accessing www.taobao.com.

 

Eight, database MySql

 

 

1. The difference of MySql storage engine

2. Single index, joint index, primary key index

3. How does Mysql divide the table, and what to do if you want to query by conditional paging after the table is divided (if it is not queried by the fields of the divided table, it is almost inefficient and has no solution)

4. After the table is divided, I want multiple tables with an id to be self-increasing, and the efficiency is realized

5. The configuration of MySql's master-slave real-time backup synchronization, and the principle (reading the binlog of the master library from the library), read-write separation

6. Write SQL statements. . .

7. Indexed data structure, B+ tree

8. The four characteristics of transactions and their respective characteristics (atomic, isolation), etc., how does the project solve these problems

9. Database locks: row locks, table locks; optimistic locks, pessimistic locks

10. Several granularities of database transactions;

11. The difference between relational and non-relational databases

 

9. Design Patterns

 

1. Singleton mode: full man, hungry man. And lazy loading in Hungry, double checked

2. Factory pattern, Decorator pattern, Observer pattern.

3. The advantages of the factory method pattern (low coupling, high cohesion, open and closed principle)

 

10. Algorithm

 

1. Use a random algorithm to generate a number, and it is required to generate all these numbers between 1-1000W. (examine high efficiency and resolve conflicting problems)

2. Merge sort of two sorted arrays

3. Reverse order of an array

4. Calculate the positive square root of a positive integer

5. To put it bluntly, it is the common search and sorting algorithms and their respective time complexity

6. Binary tree traversal algorithm

7. DFS, BFS algorithm

9. Basic understanding and general implementation of more important data structures, such as linked lists, queues, and stacks.

10. Sorting algorithm and space-time complexity (why is quicksort unstable, why is your project still in use)

11. Reverse Polish calculator

12. Hoffman coding

13. Search tree and red-black tree

 

11. Concurrency and performance tuning

 

1. There are 5k requests per second to query the written test questions of the location of the mobile phone number (I don’t remember it completely, not listed), how to design the algorithm? No matter how many requests, such as 5w, how to design the whole system?

2. In the case of high concurrency, how does our system support a large number of requests

3. How does the cluster synchronize session state

4. The principle of load balancing

5. If there is a particularly large amount of access to the database, how to optimize it (DB design, DBIO, SQL optimization, Java optimization)

6. If there is a large area of ​​concurrency, how to solve the problem of untimely server response without adding servers.”

7. If your project has a performance bottleneck, what aspects do you think it might be and how to solve the problem.

8. How to find the location that caused the performance bottleneck, and which location is the performance bottleneck.

9. Have you used a caching mechanism in your project? Is there a user non-local cache

 

12. Others

 

1. Common commands under linux

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326705861&siteId=291194637