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