Interview question module introduction

It contains nineteen modules: Java Basics, Containers, multithreading, reflection, object copy, Java Web modules, exceptions, networking, Design patterns, Spring/Spring MVC, Spring Boot/Spring Cloud, Hibernate, Mybatis, RabbitMQ, Kafka, Zookeeper, MySql, Redis, JVM.

Perhaps beginners do not need to see the framework and JVM module knowledge, readers can according to their own situation, choose the corresponding module to read.

First, Java foundation

1. What is the difference between JDK and JRE?

2. What is the difference between == and equals?

3. If two objects have the same hashCode(), equals() must also be true, right?

4. What does final do in Java?

5. How much is math.round (-1.5) in Java?

6. Is String a basic data type?

7. What are the classes for manipulating strings in Java? What’s the difference between them?

Is String STR =” I “the same as String STR =new String(” I”)?

9. How to reverse a string?

What are the common methods of the String class?

11. Must abstract classes have abstract methods?

12. What are the differences between ordinary classes and abstract classes?

13. Can abstract classes use final?

What is the difference between an interface and an abstract class?

15. How many IO streams are there in Java?

16. What is the difference between BIO, NIO and AIO?

17. What are the common methods of Files?

Second, the container

18. What are Java containers?

19. What’s the difference between Collections and Collections?

20. What is the difference between a List, a Set and a Map?

21. What is the difference between HashMap and Hashtable?

22. How do I decide to use HashMap or TreeMap?

23. How does HashMap work?

24. How does HashSet work?

25. What is the difference between ArrayList and LinkedList?

26. How to convert an array to a List?

27. What is the difference between an ArrayList and a Vector?

28. What’s the difference between Array and ArrayList?

29. What is the difference between poll() and remove() in a Queue?

30. Which collection classes are thread-safe?

31. What is an Iterator?

32. How to use Iterator? What are the characteristics?

33. What is the difference between Iterator and ListIterator?

34. How do I ensure that a collection cannot be modified?

Three, multi-threading

What is the difference between parallelism and concurrency?

36. What is the difference between threads and processes?

37. What is a daemon thread?

38. What are the ways to create a thread?

39. What is the difference between runnable and callable?

What are the states of threads?

41. What’s the difference between sleep() and wait()?

What is the difference between notify() and notifyAll()?

43. What is the difference between run() and start() for a thread?

44. What are the ways to create a thread pool?

What are the states of the thread pool?

46. What is the difference between submit() and execute() methods in the thread pool?

47. How to ensure the safety of multithreading in Java program?

48. What is the upgrade principle of multi-threaded lock?

49. What is a deadlock?

50. How do I prevent deadlocks?

51. What is ThreadLocal? What are the usage scenarios?

Talk about the underlying implementation of synchronized.

53. What is the difference between synchronized and volatile?

54. What’s the difference between synchronized and Lock?

What is the difference between synchronized and ReentrantLock?

56. How does atomic work?

Four, reflection

57. What is reflection?

58. What is Java serialization? When is serialization needed?

59. What is a dynamic proxy? What are the applications?

60. How to implement dynamic proxy?

5. Object copy

61. Why use cloning?

62. How to implement object cloning?

63. What is the difference between deep copy and shallow copy?

Six, Java Web

64. What is the difference between a JSP and a servlet?

65. What built-in objects does JSP have? What are the effects?

66. What are the four scopes of JSP?

67. What is the difference between session and cookie?

68. How does session work?

69. Can session be implemented if the client disables cookies?

70. What is the difference between Spring MVC and Struts?

71. How do I avoid SQL injection?

72. What is an XSS attack and how can it be avoided?

73. What is a CSRF attack and how can it be avoided?

Seven, abnormal

Throws throws 74.

75. What is the difference between final, finally and Finalize?

76. Which part of the try-catch-finally can be omitted?

77. In try-catch-finally, if a catch returns, finally will be executed?

78. What are the common exception classes?

Eight, the network

79. What do HTTP response codes 301 and 302 represent? What’s the difference?

80. What’s the difference between forward and redirect?

81. Describe the differences between TCP and UDP.

82. Why does TCP require three handshakes? Why is that?

How does TCP sticky packet come into being?

84. What are the OSI seven-tier models?

85. What are the differences between GET and POST requests?

86. How to achieve cross-domain?

87. How does JSONP work?

9. Design mode

88. Tell me about a design pattern you are familiar with.

89. What is the difference between a simple factory and an abstract factory?

Ten, Spring/Spring MVC

90. Why use Spring?

Explain what AOP is?

Explain what ioc is.

93. What are the main modules of Spring?

What are the common injection methods in Spring?

95. Are beans in Spring thread-safe?

96. How many scopes does Spring support for beans?

97. What are the methods for Spring to automate bean assembly?

What are the ways in which Spring transactions are implemented?

99. What about Transaction isolation in Spring?

100. What about the Spring MVC workflow?

101. What components does Spring MVC have?

What does 102.@RequestMapping do?

What does 103.@Autowired do?

Spring Boot/Spring Cloud

104. What is Spring Boot?

105. Why Spring Boot?

106. What is the Spring Boot core configuration file?

107. What are the types of Spring Boot configuration files? What’s the difference?

108. How can Spring Boot implement hot deployment?

109. What is the difference between JPA and Hibernate?

110. What is Spring Cloud?

111. What does the Spring Cloud circuit breaker do?

112. What are the core components of Spring Cloud?

Twelve, Hibernate

113. Why use Hibernate?

114. What is ORM Framework?

115. How to view printed SQL statements in The console in Hibernate?

How many query methods does Hibernate have?

117. Can Hibernate entity classes be defined as final?

118. What is the difference between using Integer and int for mapping in Hibernate?

119. How does Hibernate work?

120. The difference between get() and load()?

121. What about Hibernate’s caching mechanism?

122. What are the states of Hibernate objects?

What is the difference between getCurrentSession and openSession in Hibernate?

124. Do Hibernate entity classes have to have parameterless constructors? Why is that?

13, Mybatis

125. What is the difference between #{} and ${} in mybatis?

126. How many pagination methods are there in Mybatis?

127. Does RowBounds query all results at once? Why is that?

128. What is the difference between logical paging and physical paging in Mybatis?

129. Does Mybatis support lazy loading? What is the principle of lazy loading?

What about level 1 cache and level 2 cache in Mybatis?

131. What are the differences between Mybatis and Hibernate?

132. What executors do Mybatis have?

133. What is the implementation principle of mybatis paging plug-in?

134. How to write a custom plug-in for Mybatis?

14, the RabbitMQ

135. What are the usage scenarios for RabbitMQ?

136. What are the important roles of RabbitMQ?

137. What are the important components of RabbitMQ?

138. What is vhost for rabbitMQ?

139. How are rabbitMQ messages sent?

140. How does RabbitMQ ensure message stability?

141. How can RabbitMQ avoid message loss?

142. What are the conditions for successful message persistence?

143. What are the disadvantages of RabbitMQ persistence?

144. How many broadcast types are available for RabbitMQ?

145. How does RabbitMQ implement delayed message queuing?

146. What are rabbitMQ clusters for?

147. What are the types of RabbitMQ nodes?

148. What should I pay attention to when setting up rabbitMQ clusters?

149. Is each rabbitMQ node a full copy of the other nodes? Why is that?

150. What happens when the only disk node in the RabbitMQ cluster crashes?

151. Does RabbitMQ have a stop order for cluster nodes?

15, Kafka

Can Kafka be used independently of ZooKeeper? Why is that?

153. How many data retention strategies does Kafka have?

154. Kafka also sets 10 gigabytes of clean data for 7 days. On day 5, when the messages reach 10 gigabytes, what does Kafka do?

155. What can cause Kafka to run slowly?

156. What should I pay attention to when using kafka clusters?

16, a Zookeeper

157. What is Zookeeper?

158. What functions does ZooKeeper have?

159. How many deployment modes are available for ZooKeeper?

160. How does ZooKeeper synchronize the status of the primary and secondary nodes?

161. Why have a primary node in a cluster?

162. There are three servers in the cluster and one node is down. Is ZooKeeper still available?

163. What is the notification mechanism of ZooKeeper?

The 17th and MySql

164. What are the three paradigms of databases?

Mysql > alter table alter table alter table alter table alter table alter table alter table alter table alter table alter table alter table alter table alter table

166. How do I obtain the current database version?

167. What is ACID?

168. What is the difference between char and varchar?

169. What is the difference between float and double?

170. What is the difference between inner join, left join, right join in mysql?

171. How is the mysql index implemented?

172. How to verify that the mysql index meets the requirement?

173. What about transaction isolation of databases?

174. What is the common mysql engine?

175. What about row and table locks in mysql?

176. What about optimistic and pessimistic locks?

177. What are the methods used to troubleshoot mysql problems?

178. How to optimize mysql performance?

Eighteen, Redis

179. What is redis? What are the usage scenarios?

180. What functions does Redis have?

181. What’s the difference between Redis and memecache?

182. Why is Redis single threaded?

183. What is cache penetration? How to solve it?

184. What data types are supported by Redis?

185. What Java clients does Redis support?

186. What are the differences between Jedis and Redisson?

187. How to ensure the consistency of cache and database data?

188. How many ways can REDis persist?

189. How does Redis implement distributed lock?

190. What are the defects of redis distributed locks?

191. How does Redis optimize memory?

192. What are the Redis elimination strategies?

193. What are the common performance issues with Redis? How to solve it?

In the 19th, the JVM

194. What are the main components of the JVM? And its role?

195. What about the JVM runtime data area?

196. What is the difference between stacks?

197. What are queues and stacks? What’s the difference?

198. What is the parental delegation model?

199. What about the execution of class loading?

200. How to determine whether an object can be reclaimed?

The answer

Java based

1. What is the difference between JDK and JRE?

· JDK: Short for Java Development Kit, Java Development Kit provides Java Development environment and running environment.

· JRE: Short for Java Runtime Environment, which provides the required Environment for Java operation.

Specifically, the JDK actually contains the JRE, as well as the compiler javac that compiles Java source code, as well as many tools for debugging and analyzing Java programs. Simply put: if you need to run Java programs, just install the JRE, and if you need to write Java programs, install the JDK.

2. What is the difference between == and equals?

= = interpretation

The effect is different for the base type and the reference type ==, as shown below:

· Basic type: whether the comparison values are the same;

· Reference type: the comparison is whether the reference is the same;

Code examples:

String x ="string"; String y ="string"; String z =newString("string"); System.out.println(x==y); //trueSystem.out.println(x==z); //falseSystem.out.println(x.equals(y)); //trueSystem.out.println(x.equals(z)); //true Copy the code

Since x and y refer to the same reference, == is also true, and the new String() method reopens the memory space, so == is false, and equals always compares values, so it is true.

Equals reading

Equals is essentially equal to ==, except that String and Integer and others have overridden the equals method to make it a value comparison. Take a look at the code below.

First, equals compares an object with the same value by default, as follows:

classCat{publicCat(String name){this.name = name; } private String name; public StringgetName() {returnname; } publicvoidsetName(String name){this.name = name; }} Cat c1 =newCat("Wang lei"); Cat c2 =newCat("Wang lei"); System.out.println(c1.equals(c2)); //false Copy the code

The output is false to our surprise. Equals equals equals equals equals equals equals equals equals equals equals equals equals equals

publicbooleanequals(Object obj){               return(this== obj); }Copy the code

Equals is essentially equal to ==.

Why do two strings with the same value return true? The code is as follows:

String s1 =newString("Wang"); String s2 =newString("Wang"); System.out.println(s1.equals(s2)); //true Copy the code

Similarly, when we go to String equals, we find the answer as follows:

publicbooleanequals(Object anObject){if(this== anObject){returntrue; }if(anObject instanceofString){ String anotherString =(String)anObject; int n = value.length;if(n == anotherString.value.length){char v1[]= value; char v2[]= anotherString.value; int i =0;while(n--! = 0) {if(v1[i]! = v2[i])returnfalse; i++; }returntrue; }}returnfalse; }Copy the code

String overrides Object’s equals method, changing reference comparison to value comparison.

Summary: == is a value comparison for primitive types and a reference comparison for reference types; Equals by default is a reference comparison, but many classes override the equals method (String, Integer, etc.) to make it a value comparison, so in general equals compares whether the values are equal.

3. If two objects have the same hashCode(), equals() must also be true, right?

HashCode () is the same for both objects and equals() is not necessarily true.

Code examples:

String str1 ="Call"; String str2 ="Important"; System.out.println(String.format("| str2 str1: % d: % d", str1.hashCode(),str2.hashCode())); System.out.println(str1.equals(str2));Copy the code

Results of execution:

Str1:1179395 | str2:1179395

false

HashCode () is the same as hashCode(), but equals() is false, because in a hash table hashCode() equals the hash values of two key-value pairs. However, the hash values are equal, which does not necessarily result in the key-value pairs being equal.

4. What does final do in Java?

· Final classes are final classes and cannot be inherited.

· Final modifier methods cannot be overridden.

· Final variables are called constants. Constants must be initialized. After initialization, the value cannot be changed.

5. How much is math.round (-1.5) in Java?

Is equal to 1.

6. Is String a basic data type?

Strings are not part of the base type. There are eight basic types: byte, Boolean, char, short, int, float, long, and double. Strings are objects.

7. What are the classes for manipulating strings in Java? What’s the difference between them?

Classes that operate on strings are: String, StringBuffer, StringBuilder.

The difference between String and StringBuffer and StringBuilder is that String declares an immutable object. Each operation generates a new String and then points to a new String. StringBuffer and StringBuilder can operate on existing objects, so it’s best not to use strings if you’re constantly changing the contents of strings.

The big difference between StringBuffer and StringBuilder is that StringBuffer is thread-safe and StringBuilder is non-thread-safe, but StringBuilder performs better than StringBuffer, So StringBuilder is recommended for single-threaded environments and StringBuffer is recommended for multi-threaded environments.

Is String STR =” I “the same as String STR =new String(” I”)?

No, because memory is allocated differently. String STR =” I “, which the Java virtual machine allocates to the constant pool; String STR =new String(” I “) is allocated to the heap.

9. How to reverse a string?

Use the Reverse () method of StringBuilder or stringBuffer.

Sample code:

// StringBuffer reverseStringBuffer stringBuffer =newStringBuffer(); stringBuffer.append("abcdefg"); System.out.println(stringBuffer.reverse()); // gfedcba// StringBuilder reverseStringBuilder stringBuilder =newStringBuilder(); stringBuilder.append("abcdefg"); System.out.println(stringBuilder.reverse()); // gfedcbaCopy the code

What are the common methods of the String class?

· indexOf() : returns the indexOf the specified character.

· charAt() : Returns the character at the specified index.

· Replace () : string replacement.

· Trim () : Removes whitespace at both ends of the string.

· Split () : Split string, returns a split array of strings.

· getBytes() : Returns a byte array of strings.

· length() : Returns the length of the string.

· toLowerCase() : converts string toLowerCase.

· toUpperCase() : converts the string toUpperCase characters.

· Substring () : intercepts a string.

· equals() : string comparison.

Due to the word limit of the article, this paper only shows the answers to the first ten questions

The rest of the interview answers to obtain: forward + pay attention to my private reply [interview materials] can be taken away for free

Remember to forward + forward + forward yo, WISH you get the desired offer!

Java Face Book

SpringMVC interview topics

SpringCloud interview topics

Java Advanced Interview Guide

The interview scene of the big factory in nineteen

Screenshot of this document

Interview answers and materials to obtain: forward + pay attention to my private reply [interview materials] can be taken away for free

Remember to forward + forward + forward, WISH you get the desired offer!