3.6 The operators

Hello, in this course section, we will see what operators, operands and expressions are. So what are operators? Well, Java operators are special symbols, which perform specific operations on one, two or three operands, and then return a result. There are many other operators in Java. So, what is an operand. An operand is a term used to describe any object manipulated by an operator. For example here X and Y are operands and + is an operator. And an expression is a combination of operators and operands. It can be calculated and it always has a type. All right, now we’re going to explore the operators using code, so we’re going to open intellij. And now we’re doing calculations using the operators. So int result = 1 + 2; // 1 + 2 = 3 A comment allows you to insert text that will not be compiled or interpreted. It is useful to explain what the source code does. So here we will post it. Here we put a + (it’s a Concatenation), it allows to concatenate two strings of characters, that is to say to put them end to end. Here we go the addition result = result - 1 for example. 3 – 1 = 2 And the mutliplcation therefore result = result * 2 // 2 * 2 = 4 And also there is the modulo, which allows to have the rest of the division, therefore result = result % 3; // 4 % 3 = 1 There are also increment operators. This type of operator allows you to easily increase or decrease a variable. For example: we made// result = result + 1 We can abbreviate this statement by typing result ++ ; The value of the last operation gave us 1. It will be 1 + 1 = 2 Here we will decrease the last value which is 2 So result -- ; // 2 – 1 = 1. We also have assignment operators. These operators make it possible to simplify operations. For example to the bound to do // result = result + 2 We can just do result += 2;