Interview Question
1 - When should we create our own custom exception classes?
Answer: The term exception lets the programmer to know that there is something exceptional has occurred in the program. Apart from Java exception class library, a custom exception can be created by the developer. This customization gives the power to deal with application centric exceptions. For instance, in a banking application a customer tries to withdraw amount which results in below the minimum balance. In this scenario, the developer needs to implement a customized exception.
2 - Enumerations vs final variables in java
Answer: Enumeration is type safe. Where as final variables are not.
Enumeration supports to have a blend of various values. Where as final variables does not support multiple values.
Enumeration constants can be names. Where as final constants can not be named.
3 - What is the disadvantage of garbage collector?
Answer: Although garbage collector runs in its own thread, still it has impact on performance. It adds overheads since JVM has to keep constant track of the object which are not referenced and then free these unreferenced objects.
Garbage collector can be force to run using “System.gc” or “Runtime.gc”.
Reference:
http://www.careerride.com