Shorthand Operation
Equivalence Operation
sum +=10;
sum = sum + 10;
sum -=10;
sum = sum - 10;
sum /=10;
sum = sum / 10;
sum *=10; sum = sum * 10; sum %=10; sum = sum % 10; (Similarly a variable within an expression on the right can also be used as :)
sum +=total; sum = sum + total;
attention@computerscienceexpertise.com PDF created with pdfFactory Pro trial version www.pdffactory.com
Increment & Decrement Operators
The increment operator is indicated by ++ and is used to increment the variable by 1.
eg. ++marks;
increments the value of the variable marks by 1. It can be used in two ways : as a prefix, (++var), meaning that the operator precedes the variable; and as a postfix, (var++), where the operator follows the variable.
In prefix the variable gets incremented first where as in postfix the variable gets incremented after the operation of function of its associate operator.
Decrement Operators are similar to Increment Operators except the fact for the operation of decrementation by 1. It can also be used both as prefix and postfix forms of its format. eg. --marks;
is used to decrement the value of marks by 1.
attention@computerscienceexpertise.com PDF created with pdfFactory Pro trial version www.pdffactory.com
Ternary Operator of JAVA
This is an excellent substitute to the control statement like IF/THEN/ELSE of BASIC language. It is denoted by the combinational characters ?: and follows the usage with the following format/syntax : value variable = (test expression) ? expression1 : expression2; which indicates that if the test expression is true then the transfer value for storage into the value variable is expression1 and if the test expression is false the transfer value becomes the expression2. for example:
grade = (total > 40) ? ‘P’ : ‘F’;
In the above example grade refers to the value variable, total>40 is the test expression, ‘P’ is the expression1 and ‘F’ is the expression2. The ? character follows the true condition and : follows the false condition.
attention@computerscienceexpertise.com PDF created with pdfFactory Pro trial version www.pdffactory.com
Control Statements of JAVA
Selection control statements :
The Selection control statements refer to transfer of control or execution depending on the given condition and a selection is made depending on the given options. The different course of action are performed according to the given condition. They are also termed as Decision Construct Statements as they help in taking decisions for further execution of the statements/instructions within the program.
Iteration control statements :
The Iteration Statements on the other hand act as an automatic looping statements. Here the block/compound statement is executed again and again until a given condition is met.
attention@computerscienceexpertise.com PDF created with pdfFactory Pro trial version www.pdffactory.com
IF Statement
Java Learning Made Easy
Start from the beginning
