90% of 2020 interviews will be asked 20 technical questions, and the standard answers are here!

Preface

The autumn recruitment in 2020 is too difficult. Many friends say they don’t know how to pass the interview smoothly. Obviously, they know these technical questions, but they still can’t answer every time the interviewer asks them. I have done this type of project, or have done the same type of project, but I am very worried and don't know how to answer these questions. Today I will sort out the answers to these questions for your reference and study.
Recently, it is the best time to find a job. I have collected some interview questions from major manufacturers and the latest data this year (2020). The following are some screenshots of the data (all data have been integrated into documents, and pdf compressed and packaged) .
If you have a friend in need, you can click here to get the information, code: qf
Insert picture description here
1. The difference between String and StringBuffer
JAVA platform provides two classes: String and StringBuffer, they can store and manipulate strings, that is, characters containing multiple characters Data This String class provides an immutable string of values, and the string provided by this StringBuffer class is modified. When you know the character data will change, you can use StringBuffer. Typically, you can use StringBuffers to dynamically construct character data.

2. Tell me about the storage performance and characteristics of ArrayList, Vector, LinkedList.
ArrayList and Vector both use arrays to store data. The number of elements in this array is greater than the actual stored data in order to add and insert elements. They all allow direct indexing of elements by sequence number, but insert Elements involve memory operations such as array element movement, so indexing data is fast and inserting data is slow. Vector uses the synchronized method of thinking (thread safety), which is usually inferior to ArrayList in performance, while LinkedList uses a doubly linked list for storage, indexing data by sequence number Need to traverse forward or backward, but when inserting data, you only need to record the items before and after this item, so the insertion speed is faster

3. The difference between
HashMap and Hashtable HashMap is a lightweight implementation of Hashtable (non-thread-safe implementation). They have completed the Map interface. The main difference is that HashMap allows null (key). Because of non-thread safety, The efficiency may be higher than the Hashtable JAVA Chinese station community portal oC)| g| ax, HashMap allows Null to be used as an entryde key or value, while Hashtable does not allow HashMap to remove the Hashtable’s contains thinking method and change it to contains value and containsKey because of the contains idea The method is easy to misunderstand that Hashtable inherits from the Dictionary class, and HashMap is an implementation of the Map interface introduced by Java 1.2.

最大的区别是,Hashtable的思路方法是Synchronize的,而HashMap不是,在多个线程访问Hashtable时,不需要自己为它的思路方法实现同步,而HashMap 就必须为的提供外同步。

Hashtable和HashMap采用的hash/rehash算法都大概一样,所以性能不会有很大的差异。

4. The difference between final, finally, finalize
final is used to declare properties, methods, and classes, respectively, indicating that properties are immutable, methods cannot be overridden, and classes cannot be inherited.

Finally is part of the structure of the exception handling statement, which means that it is always executed.

Finalize is a method of the Object class. This method of the recycled object will be called when the garbage collector is executed. This method can be overridden to provide other resource recovery during garbage collection, such as closing files.

5. Can swtich be used on byte, long, or on String?
Only byte short int char can be used in swtich

6. There are several implementation methods for multithreading, what are they? Which one is better? There are several implementation methods for synchronization, what are they?
There are two implementation methods for multithreading, which are inheriting the Thread class and implementing the Runnable interface.

It is better to implement the Runnable interface, because the implementation class can implement multiple interfaces, but can only inherit one class.

There are two implementation aspects of synchronization, namely synchronized, wait and notify

7. How many types of streams are there in java? JDK provides some abstract classes for each type of stream for inheritance. Please tell which class they are
byte stream and character stream. Byte stream inherits from inputStream/outputStream, and character stream inherits from inputStreamReader/outputSteamWriter.

8: What if the main method is declared as private?
Answer: It can compile normally, but it will prompt "main method is not public" when running.

9: What is the difference between passing by reference and passing by value in Java?
Answer: Passing by reference means passing the address rather than the value itself, passing by value means passing a copy of the value.

10: If you want to rewrite the equals method of an object, what else should you consider?
Answer: hashCode.

11: How does Java implement "write once, run everywhere"?
Answer: Java programs will be compiled into class files composed of bytecodes. These bytecodes can run on any platform, so Java is platform independent.

12: Explain the role of each keyword in the public static void main(String args[]) statement.
Answer: The public: main method is the first method called when the Java program is running, so it must be visible to the Java environment. So the visibility is set to pulic.

static: Java platform will not create an instance of this class when calling this method, so this method must be declared as static.

void: The main method has no return value.

String is the type of parameters passed in from the command line, and args refers to the array of strings passed in from the command line.

13: The difference between == and equals
Answer: == compare whether two objects are the same object in the memory, that is, the storage locations in the memory are the same. The two String objects store the same value, but they may be stored in different places in memory.

The comparison is the reference and the equals method is the content. public boolean equals(Object obj) This method is provided by the Object object and can be overridden by subclasses. The default implementation will return true only when the object is compared with itself, this time andAre equivalent. String, BitSet, Date, and File all rewrite the equals method. For two String objects, equal values ​​mean that they contain the same sequence of characters. For packaging classes of basic types, equal values ​​mean that the values ​​of the corresponding basic types are the same.

public class EqualsTest {
    
    
               public static void main(String[] args) {
    
    
                               String s1 = “abc”;
                               String s2 = s1;
                               String s5 = “abc”;
                               String s3 = new String(”abc”);
                               String s4 = new String(”abc”);
                               System.out.println(== comparison :+ (s1 == s5));
                               System.out.println(== comparison :+ (s1 == s2));
                               System.out.println(”Using equals method :+ s1.equals(s2));
                               System.out.println(== comparison :+ s3 == s4);
                               System.out.println(”Using equals method :+ s3.equals(s4));
               }
}
结果:

== comparison : true
== comparison : true
Using equals method : true
false
Using equals method :true

14: What happens if the static modifier of the main method is removed?
Answer: The program can compile normally. NoSuchMethodError will be thrown at runtime.

15: Why is the oracle type4 driver called a thin driver?
Answer: Oracle provides a type 4 JDBC driver, which is called a thin driver. This driver includes an oracle's own implementation of TCP/IP Net8 which is completely implemented in Java, so it is platform independent and can be downloaded by the browser at runtime without relying on any client-side oracle implementation. The client connection string uses the TCP/IP address port instead of the tnsname of the database name.

16: Introduce the finalize method.
Answer: final: constant declaration. finally: handle exceptions. finalize: help with garbage collection.

The variables declared in the interface are final by default. The final class cannot be inherited, that is, there is no subclass. This is done for the safety of basic types, such as String and Integer. This also allows the compiler to perform some optimizations, making it easier to ensure thread safety. The final method cannot be overridden. The value of final variables cannot be changed. The finalize() method is called before an object is destroyed and recycled. Finally, usually used for exception handling, it will be executed regardless of whether an exception is thrown. For example, closing the connection is usually done in the finally block.

17: What is the Java API?
Answer: Java API is a collection of a large number of software components, they provide a large number of useful functions, such as GUI components.

18: What is the GregorianCalendar class?
Answer: GregorianCalendar provides support for traditional Western calendars.

19: What is the ResourceBundle class?
Answer: ResourceBundle is used to store the resources of the specified language environment. The application can load these resources according to the runtime language environment to provide display in different languages.

20: Why are there no global variables in Java?
Answer: Global variables are globally visible. Java does not support globally visible variables because: global variables violate the principle of referential transparency. Global variables cause conflicts in namespaces.

Guess you like

Origin blog.csdn.net/SpringBoot_/article/details/108694230