Found 10102 Articles for Object Oriented Programming

What is the ‘if...else if...else’ statement in Java and how to use it?

Rahul Sharma
Updated on 25-Feb-2020 09:43:08

307 Views

An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement.When using if, else if, else statements there are a few points to keep in mind.An if can have zero or one else's and it must come after any else if's.An if can have zero to many else if's and they must come before the else.Once an else if succeeds, none of the remaining else if's or else's will be tested.Syntaxif(Boolean_expression 1) {    // Executes when the Boolean expression 1 is true }else if(Boolean_expression 2) ... Read More

What is the ‘nested if’ statement in Java and how to use it?

Johar Ali
Updated on 25-Feb-2020 09:44:15

156 Views

It is always legal to nest if-else statements which means you can use one if or else if statement inside another if or else if statement.Syntaxif(Boolean_expression 1) {    // Executes when the Boolean expression 1 is true    if(Boolean_expression 2) {       // Executes when the Boolean expression 2 is true    } }Exampleclass Test {    public static void main(String args[]) {       int x = 30;       int y = 10;       if( x == 30 ) {          if( y == 10 ) {             System.out.print("X = 30 and Y = 10");          }       }    } }OutputX = 30 and Y = 10

What is the ‘if else’ statement in Java and how to use it?

Amit Sharma
Updated on 25-Feb-2020 09:46:03

117 Views

An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.Syntaxif(Boolean_expression) {    // Executes when the Boolean expression is true }else {    // Executes when the Boolean expression is false }If the boolean expression evaluates to true, then the if the block of code will be executed, otherwise else block of code will be executed.Examplepublic class Test {    public static void main(String args[]) {       int x = 30;       if( x < 20 ) {          System.out.print("This is if statement");        }else {           System.out.print("This is else statement");       }    } }OutputThis is else statement

What is the ‘if’ statement in Java and how to use it?

Ali
Ali
Updated on 25-Feb-2020 09:47:19

110 Views

An if statement consists of a Boolean expression followed by one or more statements.SyntaxFollowing is the syntax of an if statement −if(Boolean_expression) {    // Statements will execute if the Boolean expression is true }If the Boolean expression evaluates to true, then the block of code inside the if statement will be executed. If not, the first set of code after the end of the if statement (after the closing curly brace) will be executed.Examplepublic class Test {    public static void main(String args[]) {       int x = 10;       if( x < 20 ) {          System.out.print("This is if statement");       }    } }OutputThis is if statement.

How to use ‘for loop’ in Java?

Rishi Raj
Updated on 18-Jun-2020 09:39:45

91 Views

A for loop is a repetition control structure that allows you to efficiently write a loop that needs to be executed a specific number of times.A for loop is useful when you know how many times a task is to be repeated.SyntaxThe syntax of a for loop is:for(initialization; Boolean_expression; update) {    // Statements }Here is the flow of control in a for loop −The initialization step is executed first, and only once. This step allows you to declare and initialize any loop control variables and this step ends with a semicolon (;).Next, the Boolean expression is evaluated. If it is ... Read More

How to use ‘do while loop’ in Java?

Rahul Sharma
Updated on 25-Feb-2020 09:49:15

115 Views

A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.SyntaxFollowing is the syntax of a do...while loop −do {    // Statements }while(Boolean_expression);Notice that the Boolean expression appears at the end of the loop, so the statements in the loop execute once before the Boolean is tested.If the Boolean expression is true, the control jumps back up to do statement, and the statements in the loop execute again. This process repeats until the Boolean expression is false.Examplepublic class Test {    public static void main(String args[]) {   ... Read More

How to use ‘while loop’ in Java?

Johar Ali
Updated on 25-Feb-2020 09:53:13

165 Views

A while loop statement in Java programming language repeatedly executes a target statement as long as a given condition is true.SyntaxThe syntax of a while loop is −while(Boolean_expression) {    // Statements }Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any non-zero value.When executing, if the boolean_expression result is true, then the actions inside the loop will be executed. This will continue as long as the expression result is true.When the condition becomes false, program control passes to the line immediately following the loop.Here, the key point of ... Read More

What is the difference between Java and JavaScript?

radhakrishna
Updated on 02-Jan-2020 08:27:50

451 Views

JavaScriptJavaScript is a dynamic computer programming language. It is lightweight and most commonly used as a part of web pages, whose implementations allow a client-side script to interact with the user and make dynamic pages.JavaScript do not create stand-alone applications. JavaScript is implemented using JavaScript statements that are placed within the ... .JavaJava programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as a core component of Sun Microsystems' Java platform (Java 1.0 [J2SE]).Here are the differences:The JavaScript programming language is developed by Netscape, Inc and not part of the Java ... Read More

What is the difference between >> and >>> operators in Java?

Samual Sam
Updated on 30-Jul-2019 22:30:21

817 Views

>> Binary Right ShiftThe left operand value is moved right by the number of bits specified by the right operand.>>> Shift right zero fillThe left operand value is moved right by the number of bits specified by the right operand and shifted values are filled up with zeros.

What is dot operator in Java?

Debarpito Sarkar
Updated on 05-Sep-2022 10:27:17

4K+ Views

This article will help you understand what a dot operator in Java Programming language is. Before jumping into Dot Operator, let us revise about Operators. OPERATORS In computer programming we often need to perform some arithmetical or logical operations. In such circumstances, we need operators to perform these tasks. Thus, an Operator is basically a symbol or token, which performs arithmetical or logical operations and gives us meaningful result. The values involved in the operation are called Operands. Here is a basic Pictorial representation of Operators. Now, let us discuss the types of Operators available. TYPES OF OPERATORS There ... Read More

Advertisements