Java interview questions---JavaSE way

1. The difference between HashMap and HashTable: The main difference between the two is that Hashtable is thread-safe, and HashTable is not thread-safe. Therefore, HashMap is faster, so it is recommended to use Hashmap if there is no special requirement. If HashMap is used in a multi-threaded environment, the synchronizedMap() method should be used to obtain a thread-safe collection. The second is that hashmap allows null values, and the hash calculation method is different, but the implementation methods of both are array and linked list.

2. Common exceptions: arithmetic exceptions, null pointer exceptions, type conversion exceptions, array out-of-bounds exceptions, file read exceptions, input and output exceptions, and database operation exceptions.

3. HashMap data structure: In the Java language, one of the most basic data structures is an array and the other is a reference. HashMap is actually a data structure of a linked list hash table, that is, a combination of an array and a linked list. When accessing, first calculate the hash value, and then get the position of the element in the array according to the hash value. If there is already an element in this position, it is stored in the form of a linked list at this position, and the first added is stored in the head of the linked list. The one added first is placed at the end of the list.

4. The difference between arrayList and vector: Vector's methods are all synchronized and thread-safe, while ArrayList's methods are not, so ArrayList has better performance. When the element exceeds the initial size, the vector doubles, and the ArrayList increases by 50%.

5. The difference between list, set and map, list and set implement the collection interface, in which ilst is ordered and can allow repeated objects. Commonly used implementation classes are ArrayList, LinkedList, and vector. Set is just the opposite. Duplicate objects are not allowed. Unordered containers cannot guarantee the storage order of each element. Only one null is allowed. Common implementation classes include Haseeset and Treeset. Map is not a subclass or implementation class of collection. Map is an interface, which is stored in the form of key-value pairs. Several popular implementation classes are: HashMap, LInkedHashMap, HashTable, TreeMap.

6. Deadlock problem in Java multithreading: Java programs basically involve multithreading, and multithreading will inevitably encounter deadlock problems. Deadlocks are wild threads competing for resources, causing them to be blocked. avoid deadlocks,

7. Differences and similarities between Interface and abstract: Refer to the differences and similarities between abstract classes and interfaces.

8. Implementation methods of multi-threading and synchronization: The implementation methods of multi-threading are: Runnable interface and inheritance Thread class. There are two ways to achieve synchronization, one is to use the synchronization method, the other is to use the synchronization block. A synchronized method is to add synchronized after the method return type, and a synchronized block is written directly: synchronized.

9. What is serialization and how to implement it: Serialization is a mechanism used to process object streams. The so-called object stream is to stream the object content, and can read and write the streamed objects. Serialization is to solve the problem of The problem caused by the read and write operations of the object stream. Serialization implementations need to implement the Serializabile interface, which has no methods to implement.

10. The difference between equals and == in Java: equals indicates whether two variables correspond to a reference to the same object, that is, whether the contents of the heap are the same. The == operation compares whether the values ​​of two variables are equal, that is, whether the contents of the heap are the same. In short, equals compares whether the contents of two objects are the same, and == compares whether two objects are the same object.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325708507&siteId=291194637