- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 272 Articles for Java8
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
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
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.
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.
434 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
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
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
709 Views
Widening refers to passing a lower size data type like int to a higher size data type like long. No casting is required in such a case.public class MyFirstJavaProgram { public static void main(String []args) { int a = 300; long b = a; System.out.println(b); } }
2K+ Views
Narrowing refers to passing a higher size data type like int to a lower size data type like short. It may lead to data loss. Casting is required for narrowing conversion. Following program output will be 44. public class MyFirstJavaProgram { public static void main(String []args) { int a = 300; byte b = (byte)a; // narrowing System.out.println(b); } }
108 Views
We can convert one data types into another data type using casting. Narrowing ConversionNarrowing refers to passing a higher size data type like int to a lower size data type like short. It may lead to data loss. Following program output will be 44.public class MyFirstJavaProgram { public static void main(String []args) { int a = 300; byte b = (byte)a; // narrowing System.out.println(b); } }Widening/Promotion ConversionWidening refers to passing a lower size data type like int to a higher size data type like long. public class MyFirstJavaProgram { public ... Read More
To Continue Learning Please Login
Login with Google