|
1. Explain various Operator in Java with example.
2. Explain conditional operator. The conditional operator is “?”. The syntax of conditional
operator is
Where expression1 denotes the true condition and expression2 denotes false condiotion. For example:
This means that if a is greater than the b then the expression
will return the value true otherwise it will return false.
3. What is Entry-Controlled and Exit-Controlled statement? Explain with example. In Entry controlled loop the test condition is checked first and if that condition is true than the block of statement in the loop body will be executed while in exit controlled loop the body of loop will be executed first and at the end the test condition is checked, if condition is satisfied than body of loop will be executed again. The example of Entry-Controlled loop is for loop, while
loop while the example of Exit-Controlled loop is do…while loop.
4. Why we use break and return statement? Explain. Sometimes when we apply loops we need to come out of the loop on occurrence of particular condition. This can be achieved by break statement. Following program illustrate the use of break statement in the for loop. class breakDemo
Similarly we can use the return statement which is useful
for returning the control from the current block.
5. What is Garbage collection? Since objects are dynamically allocated by using the new operator, you might be wondering how such objects are destroyed and their memory released for later reallocation. In some languages, such as C++, dynamically allocated objects must be manually released by use of a delete operator. Java takes a different approach; it handles deallocation for you automatically. The technique that accomplishes this is called garbage collection. It works like this: when no references to an object exist, that object is assumed to be no longer needed, and the memory occupied by the object can be reclaimed. There is no explicit need to destroy objects as in C++. Garbage collection only occurs sporadically (if at all) during the execution of your program. It will not occur simply because one or more objects exist that are no longer used. Furthermore, different Java run-time implementations will take varying approaches to garbage collection, but for the most part, you should not have to think about it while writing your programs. |
|
See also
Ask It in The Java Forum Java Books
Return to : Java Programming Hints and Tips All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|