Java Basics-005

Source: Internet
Author: User

The purpose of garbage collection in 27.Java and the timing of recycling

The purpose of garbage collection is to identify and discard objects that are no longer used to free and reuse resources.

If the object's reference is set to NULL, the garbage collector does not immediately release the memory occupied by the object.

when garbage collection is done depends largely on the JVM. Refer to http://www.cnblogs.com/lrh-xl/p/5292495.html

28. System.GC () and RUNTIME.GC ()

These two methods are used to prompt the JVM for garbage collection. However, it is up to the JVM to start or delay the start of garbage collection immediately.

The behavior of the two methods is no different, essentially the same.

29. Finalize () method

When the garbage collector decides to recycle an object, it runs the Finalize () method of the object, but in Java, if there is enough memory, the garbage collection may never occur, that is, Finalize () may never be executed, and it is not reliable to do the finishing work on it. (When garbage collection depends on the type of JVM and what garbage collection algorithm The JVM uses, the memory allocation recycle policy, and so on). The main purpose of the Fianlize () method is to reclaim the memory requested by the special channel. Java programs have a garbage collector, so in general the memory problem is not a programmer's concern, but there is a jni (Java Native Interface) Call Non-java Program (c + +), Finalize () is to reclaim this part of memory.

30.Java Heap and permanent generation

The JVM's heap is the run-time data area, and the instances and arrays of all classes allocate memory on the heap. It is created when the JVM is started. The memory that is occupied by the object is collected by the automatic memory management system, which is the garbage collector.

Heap memory is made up of surviving and dying objects, which are surviving objects that can be accessed by the application, are not recycled, and are objects that are inaccessible to the application and not reclaimed by the garbage collector until the garbage collector has reclaimed the objects until they have been recycled.

Learn more about the runtime data area can refer to http://www.cnblogs.com/lrh-xl/p/5277585.html

31. Differences between the serial collector and the throughput collector

The throughput collector uses a parallel version of the new generation garbage collector, which is used for medium-sized and large-scale data applications. The serial collector is sufficient for most small applications, which require about 100M of memory on modern processors.

Learn more about the garbage collector can refer to http://www.cnblogs.com/lrh-xl/p/5309141.html

32.JVM Permanent Generation garbage collectiongarbage collection does not occur in a permanent generation (not very accurate). Full GC is also called Major GC if the permanent full or the threshold is exceeded.

Refer to http://www.cnblogs.com/lrh-xl/p/5312877.html and http://www.cnblogs.com/lrh-xl/p/5292495.html for garbage collection

Two types of exceptions in 33.Java

There are two types of exceptions in Java: checked (checked) exceptions and unchecked (unchecked) exceptions. An unchecked exception does not need to be declared on a method or constructor, even if the execution of a method or constructor may throw such an exception, and an unchecked exception can be propagated to the outside of the method or constructor. Instead, the checked exception must be declared with a throws statement or a constructor.

exception and error in 34.java

Both exception and error are subclasses of Throwable. Exception is used for exceptions that can be captured by the user program. Error defines an exception that is not expected to be caught by the user.

35.throw and throws

The Throw keyword is used to explicitly throw an exception in a program, whereas an throws statement is used to indicate an exception that the method cannot handle. Each method must specify which exceptions cannot be handled, so the caller of the method will be able to ensure that the exceptions that may occur are handled, and that multiple exceptions are separated by commas.

36.finally code block and Fianlize () method

The finally code block executes regardless of whether or not an exception is thrown, and it is primarily used to release resources used by the utility.

The Finalize () method is the protected () method of the object class, which is called by the Java Virtual machine before the object is garbage collected.

Java Basics-005

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.