Tuesday, June 16, 2015

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
NDK Interview Question

What is Native Interface in JAVA?


Answer: JNI is the mechanism used to invoke methods written in languages such as c and C++. You can write code using language like c and c++ and declare its native methods and can use the same method in java using JNI.
JNI exposes JNI functions and pointers that can access java objects and methods.
What is Native Interface in JAVA?
Answer: Java Native Interface permits the developers to integrate the native code such as C or C++ into a java application. To take the advantages of C programming and implementing the Java GUI features together makes the applications more efficient and powerful.
JNI is used to handle situations where the entire application can not be written in java.

Explain the advantages and disadvantages of using JNI.

Advantages:
- Use the existing library that was previously written in another languages.
-Use of windows API functions
-Increasing the speed of execution
-Invoke API functions from server product that is developed in C or C++ from a java client.
-Using JNI, we can access c and c++ code which adds performance boost to JAVA.
-JNI allows JAVA to access some hardware features using other languages like c and c++.

Disadvantages:
-Write Once Run Anywhere is not possible
-Run time errors debugging is difficult in native code
- An applet can not call a native method
- Security risk is potential
-JNI uses native languages which mean it has portability issue.
-Code debug is big problem for the developers who use JNI features in JAVA.


Reference: