Java interview questions basic summary (1)

1. Data types supported by Java: byte short int long float double Boolean char . Autoboxing: A conversion done by the Java compiler between a primitive data type and the corresponding object wrapper type.

2. Method overriding: The subclass redefines the parent class, the method name, parameter list, and return type are the same. Method overloading: same method name, different parameters and return value.

3. Constructor: When a variable is newly created in Java, it will be called. Copy constructor is not supported. But there is a clone mechanism that can be used to copy references.

4. Multiple inheritance is not supported, only single inheritance is supported, and interfaces support multiple inheritance.

5. Java supports the creation of interfaces and abstract classes. However, an interface cannot have method implementations. A class can only inherit one abstract method. A class can not implement all the methods of the interface. An abstract class can be implemented without providing interface method implementation. Interface, the variables in the interface are final, the methods are public by default, the interface is absolutely abstract and cannot be instantiated.

6. For basic variables, pass by value does not change the value of the original variable. For object variables, pass by reference generally passes a copy of the object address.

7. A process is an executing application, a thread is an internal execution sequence, a process can have multiple threads, and Xianheng divides the Xiaoyu process. Processes occupy resources, threads share resources, communication between cities is difficult, and communication between threads is convenient.

8. Inherit the Thread class and implement the runnable interface. Generally, more things are used in this way of the runnable interface. Thread pool Executor method.

9. Create, wait, run, block

10.  Synchronization method: Use this or the current class object as the lock, and the synchronization code block can choose what to lock.

11.  How to achieve thread synchronization inside the monitor: The monitor and the lock are used together in the Java virtual machine. The monitor monitors the synchronized code block to ensure that only one thread executes the synchronized code block.

12. Deadlock: A deadlock caused by multiple processes competing for resources, mutual exclusion, no preemption, request retention, and circular waiting.

13. Collection class framework: specifies a group of objects called elements, Collection represents a group of objects, Set does not contain duplicate elements, List has an ordered collection, and map can map keys to values. Divided into two categories: map, collection, where set and list interfaces inherit collection, one is ordered, the other is unordered, while arraylist and linkedlist implement the list interface, hashset implements the set interface, hashmap and hashtable implement the map interface, and Hashtable is thread safe, while hashmap performs better.

14. Cloneable and Serializable are related to the specific implementation, so it should be determined by the specific implementation. clone or serialize.

15. Iterator: Provides a lot of methods for iterating over collection elements. You can delete the underlying elements through the remove method of the iterator.

16. The safety failure of Iterator is to make a copy of the underlying collection, which is not affected by the modification of the original collection. The fast failure will throw an exception, and the safety failure will never throw such an exception.

17. Hashmap is not thread safe, hashtable is thread safe. Both keys and values ​​of Hashmap allow null to exist, while hashtable does not. Hashmap is efficient, and hashmap is suitable for single thread, but now hashmap is generally used.

18. Array array, array list arraylist, one static and one dynamic. Arraylist and linkedlist are implemented in different ways. One is a data interface for indexing, and the bottom layer is an array. The other is to store data in the form of a list of elements, and insertion and deletion are relatively faster.

19. The compareble interface of the CompareTo method sorts two objects and returns a negative number of 0, but Comparable implements sorting by a method inside the collection, and Comparator implements sorting outside the collection.

20. Garbage collection does not occur in the permanent generation. If the permanent generation exceeds the critical value, garbage collection will occur.

21. Two types of exceptions: checked exceptions and unchecked exceptions. Unchecked exceptions do not need to be declared on methods or constructors.

22. Throw is used inside the method, and Throws is used in the method declaration. Throw is followed by an exception object, and Throws is followed by an exception type. Throw can only be followed by one exception object. After Throws, multiple exception types can be declared at one time.

23. Servlet is a Java class used to process client requests and generate dynamic web pages, process data submitted by forms to generate dynamic content, and manage state information under the stateless http protocol.


Guess you like

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