Java Memory Topics

Source: Internet
Author: User

The difference between an abstract class and an interface.
Interfaces are defined only, and abstract classes can be defined and implemented
The field definition for an interface defaults to: public static final, abstract class field default is "friendly" (this package is visible)
Interfaces can be multiple implements, and abstract classes can only be extends by a single

When a feature needs to accumulate with an abstract class, there is no need to accumulate the interface.

Third, the difference between overload and override.

Override: The subclass overrides the method of the parent class. A method that passes a child class to a reference to the parent class, or to a subclass.
Overload (Heavy): Multiple methods with the same name are defined in a class, either with a different number of arguments or with different parameter types. The return value types of these methods can also be different.
Both are different manifestations of Java polymorphism.

Third, final, finally, finalize the difference.

A final decorated class cannot be inherited (a string is a final decorated class), and a final modified variable must be given an initial value at the time of declaration, but only in a subsequent reference, and cannot be modified. Typically used to declare a constant, or a value for a system setting. The final modified method can also be used only and cannot be overridden.

Finally used in exception handling, for things that must be handled, such as closing a connection.

The finalize-method name. Before the garbage collector clears the object from memory, call the Finalize method on the object and do the necessary cleanup work. This method is defined in the Object class, so all classes inherit it. Subclasses override the Finalize () method to organize system resources or perform other cleanup work.

What is the difference between super () and this ()?
This (): the object of the current class, and this represents the current object, and of course all resources can be accessed.
Super Parent class object. Super (): Access to the members and behavior of the parent class in the subclass must be constrained by the class inheritance rule

In the constructor, if the first line does not write super (), the compiler will insert it automatically.
But if the parent does not have a constructor without parameters, or the function is privatized. At this point you must join the instantiation construct of the parent class.

This does not have this requirement, because it is an instantiation of the structure itself.

The method used by super and this is pretty much the same. It's just super. Consider whether you can access the resources of its parent class.

Third, the Java event delegation mechanism and garbage collection mechanism.
Java Event Delegation Mechanism:
A source generates an event and sends it to one or more listeners.
In this scenario, the listener simply waits until it receives an event.
Once the event is accepted, the listener handles the event and then returns.
Garbage collection mechanism:
Garbage collection is the process of reclaiming or releasing memory that is allocated to an object but is no longer used.
If an object does not have a reference to it or its assignment is null, the object is suitable for garbage collection.

Iv. What is Java serialization and how do I implement Java serialization? (Write an instance)
The mechanism for dealing with object flow, the so-called object flow is to stream the contents of the object.
It is possible to read and write to a Fluidized object, or to transfer the streamed object between the networks.
Serialization is a problem that is raised when reading and writing to an object stream.

The implementation of serialization:
The class that needs to be serialized is implemented with the Serializable interface, which has no method to implement.
Implementsserializable just to mark that the object is serializable,
A ObjectOutputStream (object flow) object is then constructed using an output stream (for example: FileOutputStream).
Then, using the WriteObject (Object obj) method of the ObjectOutputStream object, you can write out (that is, save its state) the object with the parameter obj.
The input stream is used to restore the word.

19. What is the reflection mechanism of a class?
Classes (class objects) can be used to derive the fields, method, Construtor, interface, superclass, modified, etc. of the current class.
It is possible to instantiate an instance, set properties, and wake methods through a class.
Everything in spring is a flyback, struts, and hibernate are all developed through the class's flyback.

Java Memory Topics

Related Article

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: 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.