Monday 30 April 2012

JAVA interview questions 26

Q251. Which class act as root for entire java Exception hierarchy? 
Ans. Throwable class act as root for entire java Exception hierarchy. 

Q252. What is the difference between Error and Exception? 
Ans. Throwable class contain two child classes. 
Exception:- These are mostly caused by our program and are recoverable. 
Error:- These are not caused by our program, mostly caused by lake of system resources. These are non recoverable. 

Q253. What is difference between checked exception and unchecked exception? 
Ans. The exceptions which are checked by the compiler for smooth execution of the program at Runtime is called checked exception. Example: IOException, InterruptedException.The 
exceptions which are not checked by the compiler are called unchecked exception. Example: ArithmeticException,RuntimeException. 

Q254.What is difference between partially checked and fully checked Exception? 
Ans. A checked exception is said to be fully checked if and only if all the child classes also checked otherwise it is called partially checked exception. 
Example: 
IOException:- fully checked exception 
Exception:- partially checked exception 
Throwable:- partially checked exception 
RuntimeException:- unchecked exception 

Q255. What is a customized Exception? 
Ans. Sometimes based on our programming requirement we have to create our own exception such type of exception are called customize Exception. 
Example: 
TooYoungException 
TooOldException 
InsufficientFundException 

Q256. Explain the process of creating the customized Exception. 
Ans. Creating customized Exception: 
Class TooYoungException extends RuntimeException{ TooYoungExcetpion(String desc){ 
Super(desc); 


Class TooOldException extends RuntimeException { 
TooOldException(String desc){ 
super(desc); 


Class custExcepiton{ 
Public static void main(String[] args){ int age=Integer.parseInt(args[0]); 
if(age>60) 

Throw new TooYoungException(“Please wait some more time, definitely you will get best match”); 

else if(age<18) { 
Throw new TooOldException(“Your age is already crossed of marriage, no chance to getting marriage”); 

else { 
System.out.println(“Congratulation! You will get match details soon by your
email”);
}
}

Q257. Explain control flow in try, catch, finally.
Ans. try{
Statement1;
Statement2;
Statement3;
}
catch(X e){ 
Statement4; } 
Finally{ 
Statement5; } 
Statement6; 
Case1: 
If there is no Exception then output is 
Statement1 
Statement2 
Statement3 
Statement5 
Statement6 
Normal termination 
Case2: 
If an exception raised at statement2 and corresponding catch block has matched then output is Statement1 
Statement4 
Statement5 
Statement5 
Normal termination 
Case3: 
An exception raised at statement2 and corresponding catch has not matched then output is Statement1 
Statement5 
Abnormal termination 
Case4: 
An exception occurs at statement4 it always Abnormal termination but before that finally block will be executed and output is 
Statement1 
Statement2 
Statement5 
Abnormal termination 
Case5: 
If an exception raised at statement5 or statement6, it is always abnormal termination. 

Q258. Can you give the most common occurred exception in your previous project. 
Ans. NullPointerException, ArrayIndexOutofBoundException, StackOverFlowError, 
ClassCastException, NoClassDefFoundError, ExceptionInitilizerError, 
IllegalArgumentException, NumberFormatException, IllegalStateException, AssertionError. 

Q259. What is Multitasking? 
Ans. Executing several task simultaneously is called multitasking. 

Q260. What is the difference between process-based and Thread-based Multitasking? 
Ans.Process-based multitasking:- Executing several task simultaneously where each task is a 
separate independent process such type of multitasking is called process based Multitasking. 
Example:-While typing a program in the editor we can listen MP3 audio songs. At the same time we download a file from the net. all these task are executing simultaneously and each task is 
a separate independent program. hence it is process based multitasking. It is best suitable at operating system level. Thread-based multitasking:-Executing several task simultaneously where each task is a separate independent part of the same program is called Thread-based multitasking. and every independent part is called a thread. This type of multitasking is best suitable at programmatic level. 

No comments:

Post a Comment