Java exception Surface question

Source: Internet
Author: User
Tags throwable

1, final, finally, finalize the difference.

Final is used to declare properties, methods, and classes, respectively, that the property is immutable, that the method is not overridden, and that the class is not inheritable.

Internal classes to access local variables, local variables must be defined as final types, for example, a piece of code ...

Finally is part of the exception-handling statement structure, which indicates that it is always executed.

Finalize is a method of the object class that, when executed by the garbage collector, calls this method of the reclaimed object, and can override this method to provide garbage collection of other resource recycles, such as closing the file. The JVM does not guarantee that this method is always called.

2. What is the difference between error and exception?

Error indicates a serious problem in situations where recovery is not impossible but difficult. For example, memory overflow. It is impossible to expect the program to handle such situations.

Exception represents a design or implementation issue. That is, it means that if the program runs normally, it never happens.

3. The simple principle and application of exception handling mechanism in Java.

Exceptions are abnormal conditions or errors that occur when a Java program is run (not compiled), similar to real-life events, where real-life events can contain information about the time, place, people, and plot of an event, which can be represented by an object, and Java uses an object-oriented approach to handling exceptions. It encapsulates each exception that occurs in the program into an object that contains information about the exception.

Java classifies exceptions, different types of exceptions are represented by different Java classes, and the root class for all exceptions is java.lang.throwable,throwable two sub-classes are derived: Error and Exception,error Represents a serious problem that the application itself cannot overcome and recover, and the program has only a dead copy, such as a system problem such as memory overflow and thread deadlock. Exception that the program is also able to overcome and restore the problem, which is divided into the subject of abnormal and run-time anomalies, system anomalies are the software itself caused by defects, that is, the software developers to consider the problem caused by poor, software users can not overcome and restore this problem, In this case, however, the software system can continue to run or let the software die, for example, array scripting out of bounds (arrayindexoutofboundsexception), null pointer exception (NULLPOINTEREXCEPTION), Class Conversion Exception (classcastexception), common exception is the operation of the environment changes or anomalies caused by the problem, is the user can overcome the problem, for example, network disconnection, hard disk space is not enough, after such an exception, the program should not die.

Java provides a different solution for system exceptions and common exceptions, and the compiler enforces common exceptions that must try: Catch processing or using the throws declaration continues to be thrown to the upper call method processing, so the common exception is also called the checked exception, and the system exception can be handled or not handled, so the compiler does not enforce with try. catch processing or declaration with throws, so system exceptions are also known as unchecked exceptions.

Java exception Surface question

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.