First: What is a GC? Why do you have a GC?
A: GC is garbage collection (Gabage Collection) in C + +, C memory management is the most cumbersome thing to do not reclaim memory and the wrong recovery memory caused by system crashes and memory leaks GC automatically monitors the scope of the object to determine if the object exceeds the scope if it is more than the automatic recovery of memory There is no method in Java that shows the collection of allocated memory
Second: The advantages and principles of garbage collection. and consider 2 kinds of recycling mechanisms.
A: The GC automatically monitors the allocated objects to see if the object's scope can reach the object in Java where there is no ' scope ' but the variable that references the object has a ' scope ', The garbage collector is often used as a low-level thread to clear and reclaim dead and long-unused objects in the heap in unpredictable situations, which effectively prevents memory leaks and improves memory utilization
Garbage collection can be divided into: Generational replication garbage collection, token garbage collection, incremental garbage collection
Third: What is the basic principle of the garbage collector? Can the garbage collector reclaim memory right away? Is there any way to proactively notify a virtual machine for garbage collection?
A: When many objects are created, the GC records the object's address, size, usage, and the GC uses a graph to record and manage the objects in the heap in such a way that the GC is responsible for reclaiming the unreachable object's memory when the object is unreachable. We can proactively notify the GC to do garbage collection.
System.GC () But the JVM does not guarantee that it will execute
IV: How the Java language handles exception handling
Java uses an object-oriented approach to exception handling, classifies various exceptions, and provides a good interface. In Java, each exception is an object, which is an instance of the Throwable class or other subclass. When an exception is thrown, a method throws an exception object that contains the exception information, and the method that invokes the object can catch the exception and handle it.
Fifth: J is there a memory leak in Ava? Please describe it briefly.
Yes. such as: int i,i2; return (I-I2); When I is a positive number large enough, the i2 is a large enough negative number. The result is an overflow that causes an error.
Sixth: Mechanisms to implement polymorphism in Java
The overridden overriding and overloaded overloading of a method are different manifestations of Java polymorphism. Overriding overriding is a representation of polymorphism between a parent class and a subclass, and overloaded overloading is a representation of polymorphism in the same class.
seventh: What is Java serialization and How is Java serialization implemented?
Serialization is a mechanism for dealing with the flow of objects, the so-called object flow, which is to stream the contents of an object. It is possible to read and write to a Fluidized object, or to transfer the streamed object between the networks. serialization resolves an issue that is caused by read and write operations on an object stream.
Serialization implementation: Implement the Serializable interface for the class that needs to be serialized, and then use an output stream (for example: FileOutputStream) to construct an ObjectOutputStream (object flow) object, and 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, and then use the input stream to recover.
Eighth: Please say the thread synchronization method you know.
The two methods are synchronized,wait and notify respectively.
Wait (): causes a thread to be in a wait state and releases the lock of the object it holds.
Sleep (): Makes a running thread sleep, is a static method that calls this method to catch the interruptedexception exception.
Notify (): Wakes up a waiting thread, noting that when this method is called, it does not actually wake up a waiting state thread, but is determined by the JVM to wake up which thread, and not by priority.
Notifyall (): Wakes all the threads that are in the waiting state, noting that they do not give all the wake-up threads an object lock, but instead let them compete.
Nineth: How does the JVM load the class file mechanism?
The loading of classes in the JVM is implemented by ClassLoader and its subclasses , and Java ClassLoader is an important Java Runtime system component. It is responsible for locating and loading classes of class files at run time.
Java Interview FAQs