Hot interview Topic-java Abnormal __java

Source: Internet
Author: User

Java anomalies are often asked in the interview, many people are prepared but in the actual interview, still can not be very accurate answer Java exception problems. Exactly how the interviewer will ask questions. How will you dig deep into your answers? Today, the small series through an interview scene simulation, to help ape apes better understand the Java anomaly, to fix the interviewer.



Interviewer title


Please talk about your understanding of Java anomalies. Distinguish between run-time exceptions and general anomalies. What are some of the exception classes you encounter in your normal work, detailing how these anomalies are generated.



Test Centers Analysis


According to this topic, we can divide it into three small problems, to answer, mainly to our understanding of the anomaly, as well as the depth of the study of the Java Foundation, such as in the topic of your work encountered in the anomalies, which is the depth of your knowledge of the excavation; The problem also mentions the causes of these anomalies, It is also to dig deeper into which direction you are studying.


Reply


0,java an unusual understanding.

Exceptions primarily handle errors that cannot be caught at compile time. Continue to perform smoothly without causing the program to terminate when problems occur. Ensure the robustness of the program.

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

Throwable: Exception class; Error: System anomaly; Exception: normal anomaly; recoverable.

Use try/catch/finally to handle exceptions.

When you get to the top of something, some interviewers will ask you when to use finally. You should answer this, some things (in addition to memory) after the exception processing needs to revert to the original state, such as: Open files, network connections and so on.



1, what is the difference between runtime anomaly and general anomaly?


The anomalies are divided into runtime exception and checked exception.

The checked Exception:java compiler enforces this type of exception, such as IO exceptions, and SQL exceptions.

Runtime exception: Do not need mandatory processing, once the exception, to the virtual machine to take over.


2, what are the exception classes that are encountered?


NullPointerException: null pointer.

ArrayIndexOutOfBoundsException: Array out of bounds.

IllegalArgumentException: Invalid parameter.

Bufferoverflowexception: Cache overflow.

ClassNotFoundException: The specified class could not be found at compile time.

ClassCastException: Type is strongly turned.

Exceptionininitializererror: Exception occurred during static initial value or static variable initial value.

Unsatisfiedlinkerror:jni is not found when loading DLL or so file.

Noclassdeffounderror: The appropriate class can be found at compile time, and the appropriate class cannot be found at run time.

It says so many common exception classes, let's talk a little bit about the OutOfMemoryError (memory overflow) anomaly here.


The reason for the result:

1. The amount of data loaded in memory is too large, such as fetching too much data from the database at once.

2. The collection class has references to objects that are not emptied after use, making the JVM unable to recycle. , 3,

3. Object entities in the code that have dead loops or loops that produce too many duplicates.

4. Bugs in Third-party software used.

5. The startup parameter memory value set too small.


Focus on the following points:


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

2. Check if there is a recurring cycle to produce new object entities.

3. Check whether there is a query in the database query that gets all the data. In general, if you take 100,000 records to memory at a time, it can cause a memory overflow. This problem is more covert, before the line, the data in the database is less, not easy to problem, online, the database more data, a query may cause memory overflow. Therefore, the database query as far as possible in the way of paging query.

4. Check the list, map and other collection objects have been used after the problem has not been cleared. Collection objects such as List and map always have references to objects so that they cannot be reclaimed by GC.

5. Check whether the reading of large files is in the form of a class NiO.

Free live public class in Java please add teacher QQ578024144

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.