1, declaring the constructor function as private
The constructor is privatized to ensure that the class cannot be instantiated directly outside of the class, in which case, to create an instance of this class, you can only provide a public static method, like the factory method pattern, because the constructor is privatized and cannot be inherited.
2, when the TRY statement block is inserted into the return statement, will the finally statement execute?
When you exit the Try statement, the finally statement block is executed. What happens when the finally statement is not executed: the virtual machine exits during the execution of the Try/catch statement block, and the thread executing the TRY statement block is terminated
The difference between 3,final,finally,finalize
Final: Applied to the base type variable, the value of the variable cannot be changed, applied to the reference variable, the variable cannot point to other objects on the heap, is applied to a method, cannot be overridden, applied to a class, and cannot be inherited;
Finally: After the Try/catch block, you can choose to add a finally statement block to write code that recycles resources and cleans up
Finalize: When the garbage collector determines that no references point to an object instance, it calls the Finalize method before the object is destroyed, typically to clean up resources, close files, etc.
4,java generics, "Syntax Sugar"
Java generics are valid at compile time, the compiled bytecode is no longer generic, and is deleted at run time, that is, all generic parameter types will be erased after compilation.
Object reflection of 5,java
Object reflection provides a way to obtain reflection information for Java classes and objects, to perform operations such as getting information about the methods and fields of a class at run time, creating an instance of a class, and getting and setting object fields directly by getting field references, regardless of the modifier.
Object reflection: Helps to observe or manipulate the run-time behavior of an application, helps to debug or test a program, because we can access methods, constructors, and member fields directly, and call methods by name.
Java Interview Golden Code