JAVA face questions - Exception

1, the difference between throw and the throws?

throw: be true to throw an exception;

throws: a statement may throw an exception.

 

2, final, finally, finalize what is the difference?

final: is a modifier, if modified class, which can not be inherited; if modification methods and variables, then this method and this variable can not be changed, only can be used.

finally: a try {} catch {} finally {} The last part shows no circumstances will be executed occurs, finally part can be omitted, but if present will finally the finally inside the code.

finalize: is a method of the Object class, will be called recycled object of this method at the time of execution of the garbage collector.

 

3, try-catch-finally in which part can be omitted? If the catch in return, finally will be implemented?

1) try-catch-finally catch which finally can be omitted and, at the same time but can not be omitted, that is to say when there try, it must be followed a catch or finally.

2) finally will be executed, even if the return is a catch, catch in the waiting will finally return after completion of code execution, it will be performed.

 

4. What are the common exception classes?

1) NullPointerException null pointer exception

2) ClassNotFoundException develop class does not exist

3) NumberFormatException abnormal string converted to digital

4) IndexOutOfBoundsException array subscript bounds exception

5) ClassCastException abnormal data type conversion

6) FileNotFoundException File not found abnormalities

7) NoSuchMethodException method there is no abnormality

8) IoException abnormal

9) SocketException Socket abnormal

Guess you like

Origin www.cnblogs.com/xiaomingwang/p/11574143.html