Java Interview Golden Code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.