Found 346 Articles for Java Programming

Incremental Java infinite loop

Abhinanda Shri
Updated on 12-Mar-2020 12:18:35

120 Views

ExampleFollowing is the required program −Live Demopublic class Tester {    public static void main(String args[]) {       int i = 0;       do {          i++;          System.out.println(i);       }while (true);    } }The output will keep printing numbers in sequential order.

Infinite while loop in Java

Syed Javed
Updated on 27-Feb-2020 05:25:01

436 Views

Yes. Following while loop is a valid statement and causes an infinite loop.while(true);

Java labelled for loop

Vikyath Ram
Updated on 15-Jun-2020 09:14:32

962 Views

Following program is using labeled for loops.ExampleLive Demopublic class Tester {    public static void main(String args[]) {             first:          for (int i = 0; i < 3; i++) {             for (int j = 0; j< 3; j++){                if(i == 1){                   continue first;                }                      System.out.print(" [i = " + i + ", ... Read More

Java labelled statement

Kumar Varma
Updated on 15-Jun-2020 09:06:36

2K+ Views

Yes. Java supports labeled statements. You can put a label before a for statement and use the break/continue controls to jump to that label. ExampleSee the example below.Live Demopublic class Tester {    public static void main(String args[]) {       first:          for (int i = 0; i < 3; i++) {             for (int j = 0; j < 3; j++){                if(i == 1){                   continue first;               ... Read More

Java switch statement

Kumar Varma
Updated on 15-Jun-2020 07:38:32

220 Views

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.SyntaxThe syntax of enhanced for loop is −switch(expression) {    case value :       // Statements       break; // optional        case value :       // Statements       break; // optional        // You can have any number of case statements.    default : // Optional       // Statements }The following rules apply to ... Read More

Differences between | and || operators in Java

Vikyath Ram
Updated on 30-Jul-2019 22:30:21

3K+ Views

| is a bitwise operator and compares each operands bitwise.It is a binary OR Operator and copies a bit to the result it exists in either operands.Assume integer variable A holds 60 and variable B holds 13 then  (A | B) will give 61 which is 0011 1101.Whereas || is a logical OR operator and operates on boolean operands. If both the operands are false, then the condition becomes false otherwise it is true. Assume boolean variable A holds true and variable B holds false then (A && B) is true.| is to be used during bitwise operations and || is useful during logical operations.

Differences between & and && operators in Java.

Kumar Varma
Updated on 30-Jul-2019 22:30:21

7K+ Views

& is a bitwise operator and compares each operand bitwise.It is a binary AND Operator and copies a bit to the result if it exists in both operands.Assume integer variable A holds 60 and variable B holds 13 then  (A & B) will give 12 which is 0000 1100.Whereas && is a logical AND operator and operates on boolean operands. If both the operands are true, then the condition becomes true otherwise it is false. Assume boolean variable A holds true and variable B holds false then (A && B) is false.& is to be used during bitwise operations and && is useful during logical operations.

Java Unary Operator Examples

Ayyan
Updated on 30-Jul-2019 22:30:21

435 Views

The unary operator works on a single operand. Following are the examples of unary operators supported in java. Assume A = 60 and B = 20.OperatorDescriptionExample~ (bitwise compliment)Binary One's Complement Operator is unary and has the effect of 'flipping' bits.(~A ) will give -61 which is 1100 0011 in 2's complement form due to a signed binary number.++ (Increment)Increases the value of operand by 1.B++ gives 21-- (Decrement)Decreases the value of operand by 1.B-- gives 19

Java Operators Precedence

Anjana
Updated on 30-Jul-2019 22:30:21

2K+ Views

Operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator −For example, x = 7 + 3 * 2; here x is assigned 13, not 20 because operator * has higher precedence than +, so it first gets multiplied with 3 * 2 and then adds into 7.Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedence operators ... Read More

Java Boolean operators

Fendadis John
Updated on 30-Jul-2019 22:30:21

8K+ Views

There are following boolean operators supported by Java language.Assume variable A holds 10 and variable B holds 20, then −OperatorDescriptionExample== (equal to)Checks if the values of two operands are equal or not, if yes then condition becomes true.(A == B) is not true.!= (not equal to)Checks if the values of two operands are equal or not, if values are not equal then condition becomes true.(A != B) is true.> (greater than)Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.(A > B) is not true.< (less than)Checks if the ... Read More

Advertisements