What is widending in Java
2.3 Operators and Expressions
Expressions in Java are anything that provides a return value:
 Constants
 variables
 Methods
 Operators
Java has
 unary (singledigit, monadic) operators
 binary (twodigit, dyadic) operators
 a threedigit (ternary, tryadic) operator (the conditional operator "_? _: _")
Unary operators have a single operand. Examples are:

Binary operators have two operands. Examples are:

Arithmetic operators
The arithmetic operators can be applied to the following types
 byte
 short
 int
 long
 float
 double
operator  example  semantics 

+  a + b  Addition: sum of a and b 
  a  b  Subtraction: difference at a and b 
*  a * b  Multiplication: product of a and b 
/  a / b  Division: quotient of a and b 
%  a% b  Modulo: remainder of an integer division of a by b 
The division of integers always gives integer results!
Java works without a detection of the overflow of the value ranges. The developer must take the appropriate precautionary measures himself.
There are also singledigit (unary) arithmetic operators
operator  example  semantics 

+  + a  The value of a is retained (idempotent operation) 
  a  The value of a is negated 
++  a ++ ++ a  Post increment: The expression retains its original value. The value of a has been increased by 1 Preincrement: The value of a is increased by 1 and the expression receives the increased value of a 
  x x  Post decrement: The expression retains its original value. The value of a was decreased by 1 Predecrement: The value of a is decreased by 1 and the expression receives the decreased value of a 
The following three statements do the same thing:
a = a + 1; a ++; ++ a;However, for increments with simultaneous assignment, different values result for the assigned value
version 1  Value a  Value b  Variant 2  Value a  Value b 

a = 10; b = 4; b = a ++;  10 11  4 10 (!)  a = 10; b = 4; b = ++ a;  10 11  4 11 (!) 
example
Source code  Console output 

package s1.block2.cript; public class PrePostFixTest {public static void main (String [] args) {int x = 10; int y = 100; System.out.println ("x =" + x + "; y =" + y); x ++; System.out.println ("x ++ results in" + x); ++ x; System.out.println ("++ x results in" + x); System.out.println ("Set x to 0"); x = 0; System.out.println ("x =" + x + "; y =" + y); y = x ++; System.out.println ("y = x ++ (Postfix)"); System.out.println ("x =" + x + "; y =" + y); y = ++ x; System.out.println ("y = ++ x (Prefix)"); System.out.println ("x =" + x + "; y =" + y); }  . . . . . x = 10; y = 100. x ++ results in 11. ++ x results in 12 Set x to 0. x = 0; y = 100. y = x ++ (postfix) x = 1; y = 0. y = ++ x (prefix) x = 2; y = 2. 
Integer arithmetic
 All operations on integers result in integers again. This is not necessarily expected from the division!
 Attempts to divide by 0 (zero) will throw an ArithmeticException exception.
Floating point arithmetic
In the case of arithmetic with floating point numbers, in contrast to the integers, overflows are recognized. The floating point numbers have a number of constants:
constant  semantics 

POSITIVE_INFINITY  Positive infinite 
NEGATIVE_INFINITY  Negative infinite 
MAX_VALUE  Largest representable value 
MIN_VALUE  Smallest representable value 
NaN  "Not a number" This value is not equal to all other values in the value range 
Comparison operators
Equality or inequality refers to the value of the variables x and y
operator  example  Semantics (meaning) 

==  x == y  is x equal to y? 
!=  x! = y  is x not equal to y? 
<  x  is x smaller than y? 
<=  x <= y  is x less than or equal to y? 
>  x> y  is x greater than y? 
>=  x> = y  is x greater than or equal to y? 
Logical operators
The logical operators act on the type Boolean which only knows the value true or false.
operator  example  Semantics (meaning) 

!  ! a  negation 
&  a & b  And 
  a  b  Or (inclusive) 
^  a ^ b  Either ... or 
&&  a && b  conditionally evaluating and 
  a  b  conditionally evaluating or 
Conditional operator
The threedigit (ternary) condition operator (conditional operator) allows an assignment to be made dependent on the result of a condition. It has the form:
<ausdruck1> ? <ausdruck2> : <ausdruck3>expression1 must result in a boolean value. Becomes expression1 true so will expression2 assigned to the corresponding variable. Becomes expression1 untrue, so it will be expression3 assigned
This can be used to formulate assignments like the following
int maximum; int x = 1; int y = 2; maximum = (x> y)? x: y;The result is 2 because y (= 2) is greater than x (= 1).
Conditionally evaluating logical && and  Operators
The conditional evaluating operators only evaluate terms until the end result is fixed. This makes them look efficient.
For example:
boolean a = ((1 <3)  (4> 5));becomes the term (4>5) no longer evaluated. There (1<3) is true, the end result is already clear.
In addition to their speed advantage, the conditionally evaluating logical operators are also used with pleasure in order to avoid potential errors and exceptions.
An example of this is:
if ((a> 0) && (Math.sqrt (a)> 2))The root is only evaluated if a is greater than zero.
Attention: Due to the conditional evaluation, different results can arise if a value is changed in an expression at the same time!
Example:
conditional "or" operator  simple "or" operator  

Source code  public static void t1 () {int a = 3; int b = 5; if ((a> 1)  (a System.out.println ("Hello"); } System.out.println ("b =" + b); }  public static void t2 () {int a = 3; int b = 5; if ((a> 1)  (a 
output  Hello b = 5  Hello b = 6 
Bit operators
With bit operators, all bits of a variable are manipulated individually.
operator  example  importance 

~  ~ a  complement 
&  a & b  And 
  a  b  Or 
^  a ^ b  exclusive or 
example
package s1.block2.cript; public class BitOperator {public static void main (String [] args) {int a = 7; int b = 6; int result; result = a & b; System.out.println (" a=" + a + " ; b=" + b + " result=" + result); result = a  b; System.out.println (" 0" bit.< td>example
package s1.block2.cript; public class ShiftingBits {public static void main (String [] args) {int x = 4; int result; int shift = 1; result = x << shift; System.out.println ("x =" + x + "; shift =" + shift + "result =" + result); result = x >> shift; System.out.println ("x =" + x + "; shift =" + shift + "result =" + result); result = result >> shift; System.out.println ("x =" + x + "; shift =" + shift + "result =" + result); result = result >> shift; System.out.println ("x =" + x + "; shift =" + shift + "result =" + result); result = result >> shift; System.out.println ("x =" + x + "; shift =" + shift + "result =" + result); }}Result
The internal representation of the values used:
Decimal value  Binary value 

8  0 0000000 00000000 00000000 00001000 
4  0 0000000 00000000 00000000 00000100 
2  0 0000000 00000000 00000000 00000010 
1  0 0000000 00000000 00000000 00000001 
0  0 0000000 00000000 00000000 00000000 
The equals sign = is used as an assignment operator in Java. The instruction
x = y + z;is not to be understood as a mathematical equation, but as an assignment of the expression on the real side (y + z) to the variable x on the left side.
Assignments like:
x = y = 8;are also possible. They have the same meaning as
y = 8; x = y;For most binary operators there are compound operators with which you can assign something to a variable and at the same time use the old value:
Compound operator  corresponds to 

a + = b  a = a + b 
a  = b  a = a  b 
a * = b  a = a * b 
a / = b  a = a / b 
a% = b  a = a% b 
a & = b  a = a & b 
a  = b  a = a  b 
a ^ = b  a = a ^ b 
a << = b  a = a << b 
a >> = b  a = a> b 
a >>> = b  a = a >>> b 
For expressions with multiple operators, the following rules apply to the order of evaluation:
 Partial expressions in round brackets are evaluated first, as in mathematics
 Expressions with unary operators are then evaluated
 Finally, subexpressions with multidigit operators are evaluated
Unary operators all have the same priority
Order of execution of operators
The execution order of operators determines how a term is resolved.
Tip: It is good programming style to make terms clear. If in doubt, use brackets!
rank  operator  description 

1  =, +=, =, *= ...  Assignment operator 
2  ?:  Conditional operator 
3    Logical or 
4  &&  Logical and 
5    logical or bitwise or 
6  ^  logical or bitwise eitheror 
7  &  logical or bitwise and 
8  ==, !=  Comparison operators: equal, not equal 
9  <, <=, >, >=  Comparison operators 
10  <<, >>, >>>  Shift operators 
11  +,   Addition, subtraction, concatenation of strings 
12  *, /, %  Multiplication, division, remainder 
13  ++, , +, , ~, !  unary (onedigit) operators 
Evaluation of operators with the same priority
It can happen that an expression has several operators with the same priority. In these cases the order of evaluation is determined by the associativity of the operators.
Operator associativity 

The associativity of operators is the order in which operands are linked by operators of the same priority 
If an operator is leftassociative, the left operand is evaluated first. The example shows the plus and minus operator. Both have the same priority. Here is the operand first a + b evaluated.
Some operators in Java are rightassociative. An example of this is the assignment operator
Evaluation order of the operands of an operator
Evaluation order of the operands 

In Java, the operands of an operator are evaluated strictly from left to right. 
This rule is particularly important because methods and various operators can have side effects. This means that these operators change the value of variables while evaluating the overall expression. Examples are the increment and decrement operators.
j = i i;is a legal expression in Java. The value assigned to j is always 1;
The evaluation of this assignment takes place in the following steps:
 Evaluation of the subtrahend (and intermediate storage)
 Decrement of i
 Evaluation of the minuend and calculation of the difference
 Assignment of the difference to j
A sample program for testing:
package s1.block2.cript; public class PrePostInkrement {public static void main (String [] args) {
int i = 4;
int j;
j = i i;
System.out.println ("i:" + i + ", j =" + j);
}
}
Output:
i: 3, j = 1The evaluation of the expression and the assignment j = i i; takes place as follows:
i  j  j = i i;  comment 

4  0  j = 4  i;  Determination of the minuend of the subtraction 
3  0  j = 4  i;  Post decrement from i 
3  0  j = 4 3;  Determination of the subtrahend of the subtraction 
3  0  j = 1;  Determination of the difference 
3  1  allocation 
Java can perform all arithmetic operations even if the number types in the expression are different. The result of the calculation depends on the types of expression. It applies in the following order:
 Is one of the guys doubleso the result becomes the type double converted.
 If not, the result becomes a float Types converted if a type is a float Type is.
 If not, the result becomes a long Types converted if a type is a long Type is.
 If not, both operands become one first int Types converted.
Anonymous (not verified)
Sun, 12/16/2012  13:47
Permalink
Stefan Schneider
Sun, 12/16/2012  14:54
Permalink
In reply to Typpfehler by Anonymous (not verified)
Correctly.
Thanks. I corrected the mistake.
Anonymous (not verified)
Sun, 12/16/2012  13:53
Permalink
Multiple assignment
You write that "x = y = 8;" has the same meaning as "x = 8; y = 8;". But x is assigned the value of y and not directly the number 8, right? So "x = y = 8;" be equivalent to "y = 8; x = y" (since the expressions are evaluated from right to left). Or?
Stefan Schneider
Sun, 12/16/2012  15:05
Permalink
In reply to multiple assignment by Anonymous (not verified)
Right consideration
You are very, very likely right.
For the final clarification, one would have to look at the generated bytecode or come between the two assignments in the debugger.
The following Java code is a strong indication that you are right:
int x, y;x = y = 8;
// (x = y) = 8; // You can't do that
x = (y = 8); // Something like that works. This bracket is probably redundant at this point. y is guaranteed to be preassigned here.
x = (y = 8) +1; // Something like that works too. This takes the principle to the extreme. x is now given the value 9.
System.out.println (x);
System.out.println (y);
Hane changed the text according to your suggestion.
Anonymous (not verified)
Wed, 01/16/2013  13:35
Permalink
Hello course WIBI12C
DHBWMannheim  Java lecture  here we are right now, right?
Who looks everything and finds the comment ???
___________ c $$$$$$$$$$$$$$$$$$$$$$$$$$ h,
________ c $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
____ d $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
____ $$$, d $$$$$$$$$$$$$$$$$$$$$$$$$ hc`? $$$$
___ $$$ u $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ h,? $$
___ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ b $$$
___ $$$$$ P $$? $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
___ $$$$$$$ `$$$$$$$$$$$$$$$$$$$$$$$$$ d $$$$$$
____ $$$$$$ c, nn,? $$$$$$$$$$$$$$$ ,, `$$$$$$$$
_____ $$ MMMMM` $$$$$$$$$$$$ F, MMMb` $$$$$$$$
______ $$$ MMTTM.?$$$$$$$$$$$,MMM $$$$$$$$
_______ `$$$$$, M ;;;` $$$$$$$$$$ ´M ,, `, $$$$$$
__________?$$$$, ____________?$$$$,( ) $$$$$$$$$$ (´ ),$$$
____________`$$$$.`´ $$$$$$$$$$,`´,$$$´
____________ $$$$$ hh $$$$$ ???? $$$ hc $$$$$$$ ´
___________ d $$$$$$$$$ `====== ´ $$$$$$$;
___________ $$$$$$$$$$$$ c ,,,, c $$$$$$$$$
____________? $$$$ P $$$$$$ ????? $$ ?? $$$$
______________________$$$$$
_____________________ 4 $$$$$ c
____________________,$$$$$$$
__________________ z $ ________________> z $ _________________ ________________ `$ _________________? L $$$$$$$$$$$: $
__________________? $$$$$$$$$$$ d´
___________________ `$$$$$$$$$$ F
____________________ `? $ c` ?? 3 $ F
____________________CCC_CCC
____________________ ,; CC_CC ;;
____________________ `CC__CCC
. ,,,,, bitten CCCCCCCCC__CCCCCCCCCCCCCCC
Cci CCCCCCCCCCC, CCCCCCC, CCCCC
CciCCCCCCCCCCCC ___ CCCCC´`´CCCCCCCCCC
Anonymous (not verified)
Tue, 01/22/2013  16:39
Permalink
invoice
public class PrePostInkrement {
public static void main (String [] args) {
int i = 4;
int j;
j = i i;
System.out.println ("i:" + i + ", j =" + j);
}
}
Shouldn't 0 come out here for j? And i = 3?
The operator  (i.e. i;) only takes place after the assignment, doesn't it?
Stefan Schneider
Tue, 01/22/2013  20:22
Permalink
In reply to Invoice by Anonymous (not verified)
Explanation
I built the exact sequence into the script.
The decrement takes place after the minuend has been determined.
This means that the decrement takes place after the minuende has been assigned. Not after assigning to j!
The assignment of the minuend can be understood as an assignment to a temporary variable.
Anonymous (not verified)
Sun, 11/23/2014  17:56
Permalink
Anonymous (not verified)
Fri, 10/11/2019  11:24
Permalink
Typing error
The unary arithmetic operators use "predecrement" instead of "predecrement".
 How long will it take to have pilotless planes?
 Is Utah a dry state
 What does 2 1 mean in speakers
 Why is Putin against Hillary Clinton
 What information does the barcode reader capture
 How do shopkeepers lose their customers
 What technologies are driving Meetup com
 Can Einstein be wrong about gravity
 Where can I learn copywriting
 What makes movie quotes unforgettable 1
 Why don't people like to work
 What are good cake selling ideas
 What should everyone know about Kanpur
 Where can I learn French in California
 How are American tourists treated in Ukraine
 Why do we have to dance
 What are some beauty trends in Vietnam
 What's wrong with Somalia
 Robots will kill people
 Stress can cause forgetfulness
 Willie Nelson wrote Just Breath
 What is the salary in remote sensing
 Does the Pima Medical Institute offer financial assistance
 What was MC Escher trying to portray
 How is the street food in Kolkata
 How do people die when they are babies
 Which game is better PUBG or COD
 Are whales more intelligent than humans
 Why do people question their beliefs
 Why do people die of viruses
 How to lock an unlocked phone
 Drama originated in the UK
 What is translated into English
 Why does Benadryl last 12 hours