Java Tutorials
251. Unsigned right shift operator in Java
By: Baski : 2007-09-07
Description: The >> operator automatically fills the high-order bit with its previous contents each time a shift occurs. This preserves the sign of the value. However, sometimes this is undesirable. For example, if you are shifting something that does not represent a numeric value, you may not want sign extension to take place. This situation is common when you are working with pixel-based values and graphics. In these cases you will generally want to shift a zero into the high-order bit no matter what its
252. ? - ternary (three-way) operator - in Java
By: Jagan : 2007-09-07
Description: Java includes a special ternary (three-way) operator that can replace certain types of if then- else statements. This operator is the ?, and it works in Java much like it does in C and C++. It can seem somewhat confusing at first, but the ? can be used very effectively once mastered. The ? has this general form:
253. switch in java
By: Jagan : 2007-09-07
Description: The switch statement is Java's multiway branch statement. It provides an easy way to dispatch execution to different parts of your code based on the value of an expression. As such, it often provides a better alternative than a large series of if-else-if statements. Here is the general form of a switch statement:
254. while loop in java
By: Jagan : 2007-09-07
Description: The while loop is Java's most fundamental looping statement. It repeats a statement or block while its controlling expression is true. Here is its general form:
255. do-while loop in java
By: Jagan : 2007-09-07
Description: If the conditional expression controlling a while loop is initially false, then the body of the loop will not be executed at all. However, sometimes it is desirable to execute the body of a while loop at least once, even if the conditional expression is false to begin with. In other words, there are times when you would like to test the termination expression at the end of the loop rather than at the beginning. Fortunately, Java supplies a loop that does just that: the do-while. The do-while loop always executes its body at least once, because its conditional expression is at the bottom of the loop. Its general form is
256. for loop in java
By: Abinaya : 2007-09-07
Description: The for loop operates as follows. When the loop first starts, the initialization portion of the loop is executed. Generally, this is an expression that sets the value of the loop control variable, which acts as a counter that controls the loop. It is important to understand that the initialization expression is only executed once. Next, condition is evaluated. This must be a Boolean expression. It usually tests the loop control variable against a target value. If this expression is true, then the body of the loop is executed. If it is false, the loop terminates. Next, the iteration portion of the loop is executed. This is usually an expression that increments or decrements the loop control variable. The loop then
257. Using break to Exit a Loop
By: Baski : 2007-09-07
Description: By using break, you can force immediate termination of a loop, bypassing the conditional expression and any remaining code in the body of the loop. When a break statement is encountered inside a loop, the loop is terminated and program control resumes at the next statement following the loop. Here is a simple example:
258. Using break as a Form of Goto
By: Baski : 2007-09-07
Description: In addition to its uses with the switch statement and loops, the break statement can also be employed by itself to provide a "civilized" form of the goto statement. Java does not have a goto statement, because it provides a way to branch in an arbitrary and unstructured manner. This usually makes goto-ridden code hard to understand and hard to maintain. It also prohibits certain compiler optimizations. There are, however, a few places where the goto is a valuable and legitimate construct for flow control. For example, the goto can be useful when you are exiting from a deeply nested set of loops.
259. Use of continue statement in Java
By: Emiley J : 2007-09-07
Description: Sometimes it is useful to force an early iteration of a loop. That is, you might want to continue running the loop, but stop processing the remainder of the code in its body for this particular iteration. This is, in effect, a goto just past the body of the loop, to the loop's end. The continue statement performs such an action. In while and do-while loops, a continue statement causes control to be transferred directly to the conditional expression that controls the loop. In a for loop, control goes first to the iteration portion of the for statement and then to the conditional expression. For all three loops, any
260. Use of return statement in Java
By: Emiley J : 2007-09-07
Description: The last control statement is return. The return statement is used to explicitly return from a method. That is, it causes program control to transfer back to the caller of the method. As such, it is categorized as a jump statement. A brief look at return is presented here.