Java 2018 Interview

Source: Internet
Author: User

What is the role of 1.Java references? What's the delivery?

Java references can be used to manipulate objects, passing the address of an object

2. What are the references divided into several? What is the difference between them? Where are weak references used?
Four kinds: Strong reference, soft reference, weak reference, virtual reference

A "strong" strong reference can never be garbage collected when it points to a reference variable;

"Soft" an object if it has a soft reference, enough memory space, the garbage collector will not recycle it;

"Weak" When the JVM is garbage collected, weak references will inevitably be recycled;

A virtual virtual reference is used in association with a reference queue, and when a virtual reference is reclaimed, it is added to the reference queue associated with it.

  

  

3. Familiar Design patterns? How is the singleton pattern implemented? Where is this pattern used?

Singleton mode: Ensures that each class has only one instance and instantiates itself and provides the instance to the system as a whole

Advantage: Avoid duplicate creation of instance, save memory more

Factory mode: Define an interface for creating objects, let subclasses decide which class to instantiate, defer instantiation of a class to subclasses, and can be seen as a substitute for a new object.

Pros: In database development, if you use JDBC to connect to a database, the database is switched from MySQL to Oracle, and the driver name is the place to change

Proxy mode: Provides a proxy for other objects to control access to this object

Java 2018 Interview

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.