© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

Home Placements Interview Questions Java Interview Questions And Answers Java Interview Questions On Flow Control and Exception Handling ▼

Java Interview Questions On Flow Control and Exception Handling

5. Explain About Do while statement behaviours

Answer
This is just similar to the while statement.    The main difference of the do-while and the while statements is, in while() the body of the loop will only be executed if the expression is true, where as in do-while loop the body is always executed , because the conditional testing is done at the end of the body. Thus the statements associated with a do-while are executed at least once.

6. Explain About break and continue statements?

Answer

As you saw in switch statement, break causes the flow of control to jump to the statement immediately following the current statement. There is another form of the break statement which will cause the entire loop to be abandoned. Generally you use continue statement within loops to jump to another statement. The continue statement can only be called within loops. If you use the continue in simple form, the loop skips to the end of the loop's body and evaluates the loop's test

7. What is mean by exceptions?

Answer

In general exceptions are bugs in a correct program. The situations that might generate exceptions are, user might enter a invalid file name, a file might contain corrupted data, a network connection failure might occurred or a bug in correct program, or referring an array element out of array length. These type of exceptions you need to handle them , otherwise the exceptions will appear to the caller. Exceptions are classes, all exceptions are subclasses of java.lang.Throwable class.

8. How the try and catch block work?

Answer

If your program might generate exceptions then try putting your code in try block, and to handle the exceptions write the code in catch block. To handle multiple exceptions write the multiple catch blocks.

9. Explain in detail about finally block?

Answer

No matter what happens to the code in the try and catch blocks the finally block is executed. The finally block cannot defined without try/catch blocks. If no exception occurs in try block then also the finally block is executed. If there is an exception in try block then also finally block is executed. If exception occurred but there is no catch block then also the finally block is executed.
The confusing part in exam is even if you code a return statement in either try or in catch blocks then also the finally block gets executed. The circumstances that might prevent executing the finally block is give below:

  • l An exception might arise in finally block itself.
  • l Code System.exit() in try/catch blocks.

Anyway if you switch off the CPU power there is no way to execute it.

Previous Next
1 2 3 4 5 6 7 8 9
SLogix Student Projects
bottom