The Java knowledge that Xiaobai must understand

Object-oriented features

https://blog.csdn.net/qq_43037478/article/details/114319125

Access modifier access scope in Java


What is the difference between String and StringBuffer and StringBulider?

String is immutable, a block of memory space is allocated for each modification

StringBuffer is thread-safe and variable length

StringBuilder is non-thread-safe and variable length

The difference between JDK and CGLib

  • JDK dynamic proxy can only generate proxy for the class that implements the interface, but not for the class
  • CGLib is to implement proxy for classes, mainly to generate a subclass for the specified class (use bytecode technology to generate proxy class), and overwrite the methods (inheritance)

Spring is choosing the basis for JDK or CGLib

  • When the Bean implements the interface, Spring will use the dynamic proxy of the JDK
  • When the Bean does not implement the interface, Spring uses CGLib to implement

What is the difference between abstract class and interface?

1. An abstract class can have a constructor, but an interface cannot have a constructor.

2. There can be ordinary member variables in the abstract class, but there are no ordinary member variables in the interface

3. The abstract class can contain non-abstract ordinary methods, all methods in the interface must be abstract, and there can be no non-abstract ordinary methods.

4. The access type of the abstract method in the abstract class can be public, protected and (default type, although

No error is reported under eclipse, but it should not work), but the abstract method in the interface can only be of the public type, and the default is the public abstract type.

5. The abstract class can contain static methods, but the interface cannot contain static methods

6. Both abstract classes and interfaces can contain static member variables. The access type of static member variables in abstract classes can be arbitrary, but the variables defined in the interface can only be of public static final type, and the default is public static final type.

7. A class can implement multiple interfaces, but can only inherit one abstract class.

What is the difference between a normal class and an abstract class?

Ordinary class: can not have abstract methods, can be instantiated directly

Abstract class: can have abstract methods, cannot be instantiated directly

What is the difference between an enumeration class and a constant class?

1. Enumeration constants are simpler. Enumeration only needs to define each enumeration item and does not need to define enumeration values, while interface constants (or class constants) must define values ​​(also require modifier public static final), otherwise compile Can't pass

2. Enumerations have built-in methods, because each enumeration is a subclass of java.lang.Enum. This class provides comparison methods such as ordinal and compareTo, which simplifies constant access.

Such as: for (enumeration class s: enumeration class. values() ){              system.out.print(s);         }

3. Enumeration constants are stable: XX enumeration has been limited without verification. If you want to enter an int type, it will not pass. This is also where we most value enumeration: limit the type at compile time

4. Disadvantages of enumeration constants: it is not inheritable and cannot be extended, but the general constants are defined at the time of construction and do not need to be extended.

JAVA three built-in annotations

@Override annotation: method override

@Suppresswarnings Annotation: can achieve the purpose of suppressing the compiler to generate warnings during compilation

@Deprecated Annotation: Classes, methods, variables, etc. modified by @Deprecated are not recommended, and errors may occur

The HashCode is the same, but the object must be the same?

Answer: The HashCode is the same, and the objects are not necessarily the same, because Hash collision may occur when calculating the HashCode through the object, resulting in the same Hash value for different objects. If the objects are the same, the HashCode must be the same.

The loading process of Java classes? (It is more important, the interview asks a lot, but also to examine your understanding of memory allocation)

1. Class loading

Find and load the binary data of the class

2. Link

The bytecode verifier verifies whether the generated bytecode is correct

Allocate memory and initialize default static variables

The memory reference is replaced by the original reference in the method area

3. Initialization

In the final stage of class loading, assign initial values ​​to all static variables and execute static block code

See here for the specific loading process: https://blog.csdn.net/weixin_37766296/article/details/80545283?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control&depth_1-utm_source=distribute.pc_relevant.none- task-blog-BlogCommendFromMachineLearnPai2-2.control

What is the difference between Set, List and Map?

Detailed difference portal: https://blog.csdn.net/qq_43037478/article/details/112439992

What is the difference between get and post request?

GET request parameters will be completely retained in the browser history, while POST parameters will not be retained.

The parameters transmitted in the URL of a GET request are limited in length, but not for POST.

GET requests will be actively cached by the browser, while POST will not, unless manually set.

GET is less secure than POST, because parameters are directly exposed on the URL, so it cannot be used to transmit sensitive information.

GET parameters are passed through the URL, and POST is placed in the Request body.

What is the difference between deep copy and shallow copy?

Shallow copy: just point to the copied memory address, if the original address changes, then the shallow copied object will also change accordingly.

Deep copy: Open up a new memory address in the computer to store the copied object.

What is the difference between == and equals?

One, the object type is different

1. equals(): is a method in the superclass Object.

2. ==: is an operator.

Two, the objects of comparison are different

1. equals(): Used to detect whether two objects are equal, that is, whether the contents of the two objects are equal.

2. ==: It has different functions when used to compare references and compare basic data types.

How many ways are there to call a third-party interface?

Remote rpc, pom file dependency, direct jar package import

 

Guess you like

Origin blog.csdn.net/qq_43037478/article/details/114699313