Java Exceptions Common interview questions

Source: Internet
Author: User

Java Exception Common interview question one, Java exception understanding

Exceptions are mainly handling errors that cannot be caught at compile time. The problem can continue to execute smoothly, without causing the program to terminate, to ensure the robustness of the program.

Processing: When an abnormal state is generated, if the current context does not have the ability to handle the current exception, a new exception object is created on the heap, stopping the current execution path and throwing the resulting exception object to a higher-level context.

Throwable: Exception class Error: System exception; unrecoverable; Exception: normal exception; recoverable

Handling Exceptions using try/catch/finally

When do you use finally?

Some things (except memory) need to revert to their original state after the exception has been processed, such as: Open files, network connections, etc.

What are the similarities and differences between runtime anomalies and general anomalies:

An exception represents an unhealthy state that may occur during a program's run, and a run-time exception that represents an exception that may be encountered in a typical operation of a virtual machine.

is a general common run-down error. The Java compiler requires the method to declare a non-runtime exception that might occur, but does not require that a declaration be thrown

A run-time exception that was not captured.

Exceptions are divided into runtime exception and checked exception

The checked Exception:java compiler enforces the requirement to catch such exceptions, such as IO exceptions, SQL exceptions.

Runtime exception: No mandatory processing is required, and once an exception occurs, the virtual machine takes over.

Third, what are the exception classes encountered? The cause of the production?

Nullpointexception: null pointer

ArrayIndexOutOfBoundsException: Array out of bounds

IllegalArgumentException: Invalid Parameter

Bufferoverflowexeption: Cache Overflow

ClassNotFoundException: Unable to find the specified class at compile time

ClassCastException: Type Strong turn

Exceptionininitializererror: Exception occurred during static or static variable initial value

Unsatisfiedlinkerror:jni loading DLL or so file not found

Noclassdeffounderror: You can find the right class at compile time, but you can't find the right class at runtime.

Iv. outofmemoryerror (Memory overflow)

Cause:

1, the amount of data loaded in memory is too large, such as the last time to remove too much data from the database.

2, the collection class has a reference to the object, after use is not emptied, so that the JVM can not be recycled.

3. There are dead loops or loops in the code that produce too many duplicate object entities.

4. Dug in the use of third-party software

5, the start parameter memory value setting too small

Focus on the points to check:

1. Check if there is a dead loop or recursive loop in the code

2, check whether there are cycle duplicate generation of new object entities.

3, check the database query, whether there is a query to get all the data, in general, if you take out 100,000 records in memory, can cause memory overflow, this problem

Relatively covert, before the online, the database less data, not prone to problems, on-line, the database more data, a query may cause memory overflow, so for database queries as far as possible to use paging

Query in the same way.

4, check whether the list, map and other collection objects have been used, not clear problems, List, map and other collection objects will always have a reference to the object, so that these objects can not be recycled by GC.

5. Check whether the read of large files is using NiO-like methods.

Java Exceptions Common interview questions

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.