Java Interview 2015 edition (definitely worth the long version of the collection) (d) __java

Source: Internet
Author: User

72. There are several types of streams in Java. The JDK provides some abstract classes for each type of stream for inheritance, say what classes they are respectively.

byte streams, stream of characters. The stream of bytes inherits from the InputStream OutputStream, and the character streams inherit from the Inputstreamreader,outputstreamwriter.

75. Describe the principle mechanism of the JVM loading class file?

The load of classes in the JVM is implemented by ClassLoader and its subclasses, Javaclassloader is an important Java Run-time system component. It is responsible for finding and loading classes of class files at run time.

76, heap and stack what is the difference.

Java memory is divided into two classes, one is stack memory, the other is heap memory. Stack memory is when a program enters a method that allocates a private storage space for this method to store local variables within the method, and when the method ends, the stack assigned to the method is released, and the variables in the stack are released.

A heap is a memory that differs from the stack and is typically used to hold data that is not placed on the current method stack, for example, objects created with new are placed in the heap, so it does not disappear with the end of the method. The local variables in the method are placed in the heap instead of on the stack after the final modification is used.

77, what is GC? Why should there be a GC?

GC is the meaning of garbage collection (gabagecollection), memory processing is where programmers are prone to problems, forgetting or wrong memory recycling can cause a program or system instability or even crash, Java provides a GC feature that automatically monitors whether an object is out of scope to automatically reclaim memory, and the Java language does not provide a display operation to free allocated memory.

78, the advantages and principles of garbage collection. and consider 2 kinds of recycling mechanisms.

A notable feature of the Java language is the introduction of a garbage collection mechanism that solves the problem of the most troublesome memory management problems of C + + programmers, making it unnecessary for Java programmers to consider memory management when writing programs. Because there is a garbage collection mechanism, objects in Java no longer have the concept of scope, only references to objects have scope. Garbage collection can effectively prevent memory leaks and effectively use memory that can be used. The garbage collector is usually run as a separate low-level thread, unpredictable in the case of dead or long time unused objects in the heap to clear and recycle, the programmer can not call the garbage collector in real time to garbage collection of an object or all objects. The recycle mechanism has generational replication garbage collection and tag garbage collection, incremental garbage collection.

79. What is the basic principle of the garbage collector? Can the garbage collector reclaim memory immediately? What is the way to actively notify the virtual machine for garbage collection.

For GC, when a programmer creates an object, the GC begins to monitor the address, size, and usage of the object. Generally, the GC uses a heap to record and manage all the objects in the heap (). In this way, determine which objects are "accessible" and which objects are "unreachable." When the GC determines that some objects are "unreachable," the GC is responsible for reclaiming the memory space. OK. The programmer can manually execute System.GC () to notify the GC to run, but the Java language specification does not guarantee that the GC will execute.

81, there will be memory leaks in Java, please describe briefly.

A memory leak means that an object or variable that is no longer being used by a program is occupied in memory. In Java, there is a garbage collection mechanism that guarantees that an object is no longer referenced, that the object is programmed to be orphaned, and that the object is automatically purged from memory by the garbage collector. Because Java uses a graph-like approach to garbage collection management, you can eliminate the problem of reference loops, such as having two objects that reference each other, so that GC can recycle them as long as they are not up to the root process. Memory leaks in Java: Long lifecycle objects holding references to short lifecycle objects are likely to have memory leaks

82

The methods of abstract cannot be modified by private, nor can it be added to final modification.

Variables that are final decorated cannot be modified.

Static method cannot call Non-staticmethods directly.

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