BAT often ask Java foundation 39 often meet questions

Java multithreading interview questions

100 Java Interview Questions

Multithreading, concurrency, and threading fundamentals

Java interview questions for experienced programmers

The underlying JVM and Garbage Collection interview questions

3 years of work experience in Java interview questions

Java basic Concepts interview questions

Java Collections Framework interview questions

Java IO and NIO interview questions

Java Best Practices interview questions

Date, Time and Calendar interview questions

Unit test JUnit interview questions

Interview questions about OOP and design patterns

A variety of other Java interview questions

Java development job interview questions are summarized

First, Java foundation

Second, the Java IO

Third, Java Web

Fourth, the JVM

Open source framework

Vi. Multi-threading

7. Network communication

MySql database

9. Design mode

Ten, algorithm

Concurrency and performance tuning

Ali Advanced Java interview questions and answers

Interview topic:

Interview questions and reference answers:


BAT often ask Java foundation 39 often meet questions

1. The size of the eight basic data types, and their encapsulation classes

2. Reference data types

3. Can the Switch use string as a parameter

4. Equals ==

5. Automatic packing, constant pool

6. What are the common methods of Object

7.Java four kinds of references, weak and weak soft virtual, used in the scene

8. The role of Hashcode

9. What hashCode does for HashMap

10. Why override the hashCode method?

11. Differences between ArrayList, LinkedList and Vector

12. The difference between String, StringBuffer and StringBuilder

13. Features and usage of Map, Set, List, Queue and Stack

14. Differences between HashMap and HashTable

Implementation of HashMap in JDK7 and JDK8

16. The difference between HashMap and ConcurrentHashMap, the underlying source of HashMap

17. Can ConcurrentHashMap completely replace HashTable

18. Why is HashMap thread unsafe

19. How to use HashMap thread safely

20. Whether HashMap still generates an infinite loop under multiple concurrent conditions

21. Differences between TreeMap, HashMap, LindedHashMap

22.Collection package structure, the difference between Collections

23.try? catch? Finally, try has a return in finally

24.Excption and Error package structure, OOM what situation you have encountered, SOF what situation you have encountered

25.Java(OOP) Object oriented three characteristics and meaning

26.Override and Overload

27. The difference between Interface and Abstract class

28.Static? class? And non? static? The difference between the class

29. Comparison of foreach efficiency with normal for loop

30.Java? IO and NIO

31. How Java reflection works

32. Common features of generics

33. Principles and characteristics of several ways of parsing XML: DOM and SAX

Java1.7 and 1.8,1.9,10 new features

35. Design patterns: singletons, factories, adapters, chains of responsibility, observers, etc

36. The use of JNI

37. The AOP is what

38. The OOP is what

The difference between AOP and OOP

Java multithreading interview questions

1. What is the use of multithreading?

2. How threads are created

3. The difference between the start() and run() methods

4. Difference between Runnable interface and Callable interface

5. Difference between CyclicBarrier and CountDownLatch

The role of the volatile keyword

7. What is thread safety

How to obtain thread dump file in Java

9. What happens to a thread with a runtime exception

How do I share data between two threads

What’s the difference between sleep and wait

12. What is the role of the producer-consumer model

13. What does ThreadLocal do

14. Why wait() and notify()/notifyAll() are called in synchronous blocks

15. What is the difference between wait() and notify()/notifyAll() when giving up object monitors

16. Why use thread pools

17, how to check if a thread has object monitor

The difference between synchronized and ReentrantLock

19. What is the concurrency of ConcurrentHashMap

20. What is ReadWriteLock

21. What is FutureTask

How do I find which thread uses the longest CPU in Linux

Java programming to write a program that will cause a deadlock

24, How to wake up a blocked thread

25. How does immutable objects help multithreading

26. What is multithreaded context switching

27. What happens if the thread pool queue is full when you submit a task

28. What is the thread scheduling algorithm used in Java

What does thread.sleep (0) do

30. What is spin

What is the Java memory model

32. What is CAS

What is the optimistic lock and pessimistic lock

34, What is AQS

Singleton thread safety

36. What does Semaphore do

37, Hashtable size() = “return count”;

38, Thread class constructor, static block is called by which thread

Synchronization method and synchronization block, which is the better choice

40. How can thread pools be used for high concurrency and short task execution times? How can thread pools be used for businesses with low concurrency and long task execution times? How can a business with high concurrency and long business execution time use thread pools?

100 Java Interview Questions

Multithreading, concurrency, and threading fundamentals

1) Can Volatile arrays be created in Java?

2) Can volatile make a nonatomic operation atomic?

3) What is the practice with volatile modifiers?

4) What guarantees do volatile variables provide?

5) Which is easier to write, 10-thread or 2-thread synchronization code?

6) How do you call wait ()? If block or loop? Why is that?

7) What is false sharing in multi-threaded environment?

Java interview questions for experienced programmers

8) What is Busy Spin? Why do we use it?

How to obtain a thread dump file in Java?

10) Is Swing thread-safe?

11) What are thread-local variables?

12) What are the differences between sleep and wait methods in Java?

13) What is an immutable object? How do you create an immutable object in Java?

14) Can we create an immutable object that contains mutable objects?

15) What data types should be used to represent prices in Java?

16) How to convert byte to String?

17) How to convert bytes to long in Java?

18) Can we cast int to a byte variable? What happens if the value is greater than the byte range?

19) Which class contains the Clone method? Is it Cloneable or Object?

20) Is the ++ operator in Java thread safe?

21) Not a thread-safe operation. It involves multiple instructions, such as reading variable values, increasing,

22) A = a + b

23) Can I assign a double to a variable of type long without casting?

24) 3*0.1 == 0.3 will return what? True or false?

25) Which takes up more memory, int or Integer?

26) Why are strings Immutable in Java?

27) Can we use String in Switch?

28) What is a constructor chain in Java?

The underlying JVM and Garbage Collection interview questions

29) The length of an int in a 64-bit JVM is the majority?

30) What are the differences between Serial and Parallel GC?

31) For 32-bit and 64-bit JVMS, is the length of a variable of type int the majority?

32) Difference between WeakReference and SoftReference in Java?

33) How does WeakHashMap work?

34) What does the JVM option -xx :+UseCompressedOops do? Why make

35) How to determine whether a JVM is 32-bit or 64-bit using a Java program?

36) What is the maximum heap memory for 32-bit and 64-bit JVMS?

37) What are the differences between the JRE, JDK, JVM and JIT?

3 years of work experience in Java interview questions

38) Explain Java heap space and GC?

39) Can you guarantee GC execution?

40) How to obtain the memory used by Java programs? What percentage of the heap is used?

41) What is the difference between heap and stack in Java?

Java basic Concepts interview questions

42) What is the difference between “a==b” and “a. quals(b)”?

43) What does a.hashcode () do? What does it have to do with A. als(b)?

44) What is the difference between Final, Finalize and finally?

45) What are compile-time constants in Java? What are the risks of using it?

Java Collections Framework interview questions

46) The difference between List, Set, Map and Queue (answer)

47) The difference between the poll() method and the remove() method?

48) What is the difference between LinkedHashMap and PriorityQueue in Java?

49) No difference between ArrayList and LinkedList?

50) What are the two ways to sort sets?

51) How to print an array in Java?

52) Is LinkedList unidirectional or bidirectional in Java?

53) What tree is used to implement TreeMap in Java? (the answer)

54) What is the difference between Hashtable and HashMap?

55) How does a HashSet in Java work internally?

56) Write code to remove an element while iterating through an ArrayList?

57) Can we write a container class ourselves and use the for-each loop code?

58) Default size of ArrayList and HashMap is majority?

59) Is it possible for two unequal objects to have the same Hashcode?

60) Can two identical objects have different hash codes?

61) What is the difference between Comparator and Comparable in Java?

62) Why do I need to override hashCode when overriding equals?

Java IO and NIO interview questions

63) How to create a ByteBuffer in Java?

Java Best Practices interview questions

64) What best practices do you follow when writing multithreaded programs in Java?

65) Name a few best practices for using Collections in Java

66) Name 5 IO best practices (answers)

67) Name a few best practices for method overloading in Java?

Date, Time and Calendar interview questions

68) Is SimpleDateFormat thread-safe in a multithreaded environment?

Unit test JUnit interview questions

69) How do I test static methods?

70) How to convert a string to an integer in Java?

Interview questions about OOP and design patterns

71) What is the interface? Why use interfaces instead of directly using concrete classes?

72) What is the difference between abstract classes and interfaces in Java?

73) Besides singletons, what other design patterns have you used in production?

74) Under what circumstances is Demeter’s Law violated? Why is this a problem?

75) What is the adapter pattern? When to use it?

76) What are “dependency injection” and “inversion of control”? Why do people use it?

77) What is abstract class? How is it different from an interface? Why have you ever used abstract classes?

78) Which is better, constructor injection or setter dependency injection?

79) What is the difference between dependency injection and engineering patterns?

80) What is the difference between adapter mode and decorator mode?

81) What was the difference between the adapter pattern and the proxy pattern?

82) What is the template method pattern?

83) When to use the visitor pattern?

84) When to use composite mode?

85) What is the difference between inheritance and composition?

86) Describe overloading and overwriting in Java?

87) What is the difference between nested public static classes and top-level classes in Java?

88) What is the difference between composition, aggregation, and association in OOP?

89) Give me an example of a design pattern that conforms to the open close principle.

90) What is the difference between abstract factory pattern and prototype pattern?

91) When to use the premium mode?

A variety of other Java interview questions

What is the difference between a nested static class and a top-level class?

93) Can you write a regular expression to determine if a string is a number?

94) What is the difference between checked and unchecked exceptions in Java?

Throws throws (throws) throws (throws

96) How does Serializable differ from Externalizable in Java?

97) What is the difference between DOM and SAX parsers in Java?

98) Name three new features in JDK 1.7?

99) Name five new features introduced in JDK 1.8?

100) What is the difference between Maven and ANT in Java?

Java development job interview questions are summarized

First, Java foundation

1. Why is the String class final

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

List, Set, Queue, Map implementation classes.

4. Describe the respective implementations and differences between ArrayList and LinkedList

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

6. The difference between class. forName and classloader in reflection.

7. New features of Java7 and Java8

8. The operation efficiency of Java array and linked list structures, in which cases (start from the beginning, start from the end, start from the middle), which operations (insert, find, delete) are efficient.

9. Investigate and locate the problem of Java memory leak: the use of JMAP, JStack, etc.

10. The difference between String, StringBuilder and StringBuffer

11. Differences between hashTable and HashMap

13. Structure of exceptions, run-time exceptions and non-run-time exceptions, for example.

14. A common String method

16. What are the types of Java references

17. Distinction between abstract classes and interfaces

18. Java base types and byte sizes

19. The Hashtable, HashMap, ConcurrentHashMap underlying implementation principle and thread safety.

20. What would you do if you implemented a Map instead of using Java Jdk tools? For a long time, I said HashMap source code, if I do, I will draw on the principle of HashMap, said a HashMap implementation.

21. What about Hash conflicts? What are the ways to resolve hash conflicts?

22. How do you resolve HashMap conflicts with the worst performance? Order n to log n.

23. rehash

24. HashCode () and equals() generate the algorithm and how to rewrite the method.

Second, the Java IO

1. Talk about common classes in IO, byte streams, character streams, interfaces, implementation classes, method blocking.

2. Tell me about the NIO

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

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

5. Recursively read files under the folder, how to achieve the code?

Third, 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 issues related to servlets

3. Webservice-related problems

4. JDBC connection, forname mode step, how to declare using a transaction.

5. Configure web. XML without a framework

6. The difference between JSP and servlet

Fourth, the JVM

1. Java memory model and GC algorithm

2. What does JVM performance tuning do

3. Introduce the seven regions in the JVM, and then explain how each region can cause memory overflow.

4. Describes abnormal references to GC and GC Root

5. From the classload loading mode, loading mechanism, from the program runtime data area, to the memory allocation, to the String constant pool, to the JVM garbage collection mechanism, algorithm, hotspot.

6. How the JVM allocates direct memory, how new objects are not allocated on the heap but on the stack, constant pool resolution.

7. The size of the array is placed in the older JVM

8. Access to arrays in the old days

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

10. Who gets GC and when.

11. What if you want to avoid GC

12. What if you want to survive a GC

Open source framework

1. Differences between Hibernate and IBatis

2. Talk about connection pooling in Mybatis

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

4. Principle of springMVC

5. Meaning of springMVC annotations

6. Spring beanFactory and ApplicationContext

7. Several ways of Spring injection

8. How does Spring implement transaction management

9. springIOC

10. Principles of Spring AOP

Level 1 and Level 2 caches in Hibernate

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

Vi. Multi-threading

1. Java calls the difference between start() and run() directly after creating a thread

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

3. NewFixedThreadPool This thread pool if the number of threads reaches the maximum.

4. Synchronization of communication between multiple threads. Synchronized locks are objects, which can be derived from many specific issues related to synchronized, such as whether an object can be accessed at the same time when different methods of the same class have synchronized locks. Or the effect of a class’s static constructor plus synchronized locks.

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

6. Understanding of the source code of synchronized data structures such as concurrentHashMap and its internal implementation, why it is synchronous and efficient.

7. Understanding and use of thread-safe operation keywords such as AtomicINTEGER and Volatile

8. Communication between threads, wait and notify

9. Use of timed threads

10. Scenario: In a main thread, a large number (many, many) of child threads are required to execute before the main thread is finished. Multiple ways, consider efficiency.

11. The difference between processes and threads

12. What is thread safety?

13. Several states of threads

14. Concurrent, synchronous interfaces or methods

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

16. Use of common classes under J.U.C. An in-depth look at ThreadPool; Use of BlockingQueue. (take, poll, put, offer) Implementation of atomic classes.

17. A brief introduction to multithreading, starting with creating a thread. And then how do you control the synchronization process, the common methods and structures of multithreading

18. Understanding of volatile

19. There are several ways to implement multithreading. How to do multithreading synchronization?

7. Network communication

1. HTTP is stateless communication. What are the HTTP request methods?

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

3. Use of socket communication model, AIO and NIO.

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

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

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

7. Differences between GET and Post in HTTP

8. Describe the relationship between HTTP, TCP, and UDP.

9. Tell me how the browser visited http://www.taobao.com.

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

11. TCP congestion causes fast return, and IP packets are discarded

12. HTTPS processes a process, symmetric encryption and asymmetric encryption

13. What are the characteristics and differences of head

14. Tell me how the browser visited http://www.taobao.com.

MySql database

1. MySql storage engine is different

2. Single index, union index, and primary key index

Mysql > select * from user where user = ‘Mysql’; select * from user where user = ‘Mysql’

4. After dividing tables, you want to make multiple tables with one ID to be self-increasing, which is efficient

5. Configure the master/slave real-time backup synchronization of MySql, and the principle (read the master binlog from the secondary database), read/write separation.

6. Write SQL statements and SQL optimization

7. Index data structure, B+ tree

8. Four characteristics of transactions, and their respective characteristics (atoms, isolation, etc.), how the project solves these problems.

9. Database lock: row lock, table lock; Optimistic lock, pessimistic lock

10. Several granularity of database transactions

11. Difference between relational and non-relational databases

9. Design mode

1. Singleton mode: full and hungry. And delayed loading in Hanzhong, double check.

2. Factory mode, Decorator mode, observer mode.

3. Advantages of factory method mode (low coupling, high cohesion, open and closed principle)

Ten, algorithm

1. Use the random algorithm to generate a number, which requires all the numbers between 1-1000W to be generated.

2. Merge sort of two ordered arrays

3. An array in reverse order

Calculate the positive square root of a positive integer

5. In plain English, common search and sort algorithms and their respective time complexity.

6. Binary tree traversal algorithm

7. DFS and BFS algorithm

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

10. Sorting algorithms and temporal complexity (why fast sorting is unstable and why your project is still using it)

11. Reverse Polish calculator

12. Hoffman encoding

13. Find trees and red black trees

Concurrency and performance tuning

1. There are 5K requests per second to query the location of the mobile phone number. How to design the algorithm? More requests, say 5W, how do you design the whole system?

2. How does our system support a large number of requests under high concurrency

3. How does the cluster synchronize session status

4. Principle of load balancing

5. If there is a particularly large number of visits to the database, how to do optimization (DB design, DBIO, SQL optimization, Java optimization)

6. If large area of concurrency occurs, how to solve the problem of delayed server response without adding more servers?

7. If there is a performance bottleneck in your project, what do you think it might be and how to solve the problem?

8. How to find the location causing the performance bottleneck and identify the location as the performance bottleneck.

9. Do you use caching in your projects? There is no user non-local cache

 

Ali Advanced Java interview questions and answers

Interview topic:

1. What are the algorithms of machine learning that you are familiar with? Talk about the processes and differences of these algorithms

2. What are the five layers of the network architecture and what are the protocols in each layer

3, what is the difference between TCP and UDP, if you want to send instant messages should use which protocol

4, TCP connection establishment and disconnection process (three times handshake and four times wave), how to ensure that TCP sent information is correct, and ensure that the order is not tampered with

5. How much do you know about HTTP, what is the difference between HTTP and HTTPS, and how is HTTPS security implemented

6, usually use mysql with what engine

7. What are the features of database transactions

8, what are the possible problems caused by transaction concurrency, what are the isolation levels of the database, what is the default isolation level of mysql, what are the problems that can be avoided by this default isolation level?

9, how to judge whether the SQL query operation is slow SQL, how to optimize

10, the difference between process and thread, communication between processes

What are deadlocks and how to handle deadlocks

12. What are the handling methods for critical sections in process synchronization

Spring MVC, Spring AOP source code

14. Spring loop references

15. Spring Transaction propagation mechanism

16, Java NIO, BIO, AIO, operating system underlying NIO implementation principle

17, Java thread programming understand?

18. What is the data structure of HashMap, how is it implemented, is it thread-safe (no), and what are its thread-safe alternatives?

Interview questions and reference answers:

What challenges did you encounter in the project?

Reference: Worked on a high concurrency project for seckill.

1. What if traffic spikes at one point and then plummets?

Reference answer:

  • Flow peak cutting and valley filling
  • Queues messages on both the client and server as a caching mechanism
  • The access layer and all modules use cache to increase QPS

2. How does redis message queue delete expired/invalid information

Reference answer:

  • Add an expiration time upper limit
  • Different queues are used for information in different groups. When the number of groups is full, the queues are deleted

3. Redis persistence mechanism?

  • RDB and AOF

4. Why parent delegates are used for JAVA class loading

  • Example: The Object class is unique

5. How to achieve synchronization

  • The Synchronized keyword
  • Volatile variables
  • The Lock object

6. What types of JAVA locks are available

  • Sychronized
  • ReentrantLock

7. The difference between the two locks

  • Synchronized is implemented by the JVM
  • ReentrantLock is implemented by the JDK

6. Know about AQS?

  • AQS (Abstract Queue Synchronizer) Queue Synchronizer
  • It consists of a Valotaile variable marking State and a CLH (synchronization, FIFO) queue

Concrete implementation class:

  • CountdownLatch: Waits for multiple threads to complete;
  • CyclicBarrier: synchronization barrier;
  • Semaphore: Controls the number of concurrent threads.

7. Scenario: Add a timeout exception to a method

  • Use AspectJ for AOP development
  • The method call is cut Around
  • A Future object is used to create a thread that is timed while the method is called
  • Throws a timeout exception if the Future returns a value first
  • Otherwise, it is called normally

Corresponding interview questions to obtain answers: pay attention to the following public account can be obtained

There are also corresponding video explanation