Java Interview Questions - Control Structure
1. What are the controls structures present in java?
Java supports five type of control structure.
- Conditional control structured
- Repetition control structured
- Selection control structured
- Jump control structured
- Sequential control structured
It is used for a finite number of times to repeat a portion of the program. If we already knows that loop will continue for n times, then for loop is suitable.
3. What is the situation to use while loop?
It is used for unknown number of times. If we don’t know how many times the loop will continue , then the while loop is suitable.
4. What is the use of jump control structure?
To restrict the flow of control.
5. Difference between do…While and while loop?
A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do while statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do while statement will always execute the body of a loop at least once.
6. What is nested loop?
A nested loop is a (inner) loop that appears in the loop body of another (outer) loop. The inner or outer loop can be any type: while, do while, or for.
7. What is selection control structure?
The selection control structure allows one set of statements to be executed if a condition is true and another set of actions to be executed if a condition is false.
8. Which loop is suitable for Array and collection program?
For each loop is suitable for array and collection program.
9. In case of which loop no initialization, no condition, no updation, checking done by user explicitly?
10. Which control structure is suitable for menu driven program?
switch case is suitable for menu driven program.
11. Which control structure only accepts integer or character?
Switch, case only accepts integer or character.
12. State the use of “break”?
It is a statement which transfers the control to outside of the loop.
13. Define Function recursion and its use?
When a function called to self it is referred as function recursion. Function recursion is use for tree traversal, tower of Hanoi, etc.
14. State the diff. b/w break and continue?
Break: It is a statement which transfers the control to outside of the loop. Continue: It is used to transfer the control to the beginning of the loop.
15. What’s the purpose of using break in each case Statement?
To restrict the control jump to next case.