Skip to content

Commit 237f575

Browse files
Operators & Expressions
1 parent d507152 commit 237f575

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

8.Operators_and_expressions/README.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Java Tutorial: Operators, Types of Operators & Expressions in Java
2+
- An operator is a symbol that the compiler to perform a specific operation on operands.
3+
- Example : a + b = c
4+
- In the above example, 'a' and 'b' are operands on which the '+' operator is applied.
5+
6+
## Types of operators :
7+
### 1. Arithmetic Operators :
8+
- Arithmetic operators are used to perform mathematical operations such as addition, division, etc on expressions.
9+
- Arithmetic operators cannot work with Booleans.
10+
- % operator can work on floats and doubles.
11+
- Let x=7 and y=2
12+
13+
![image](https://user-images.githubusercontent.com/70385488/150535449-0074c214-cb1d-4a29-8306-e9632986a628.png)
14+
15+
### 2. Comparison Operators :
16+
- As the name suggests, these operators are used to compare two operands.
17+
- Let x=7 and y=2
18+
19+
![image](https://user-images.githubusercontent.com/70385488/150535594-fec270da-1c59-40f3-a0bf-537bf3f9ec5f.png)
20+
21+
### 3. Logical Operators :
22+
- These operators determine the logic in an expression containing two or more values or variables.
23+
- Let x = 8 and y =2
24+
25+
![image](https://user-images.githubusercontent.com/70385488/150535778-ba37d847-d57a-4840-a84d-7855ad808fc7.png)
26+
27+
### 4. Bitwise Operators :
28+
- These operators perform the operations on every bit of a number.
29+
- Let x =2 and y=3. So 2 in binary is 100, and 3 is 011.
30+
31+
![image](https://user-images.githubusercontent.com/70385488/150536221-5e7263d7-e2f1-4865-8164-f428bd54c8d4.png)
32+
33+
## Precedence of operators
34+
- The operators are applied and evaluated based on precedence. For example, (+, -) has less precedence compared to (*, /). Hence '*' and / are evaluated first.
35+
- In case we like to change this order, we use parenthesis ()
36+
37+
## Code as Described in the Video
38+
```
39+
package com.company;
40+
41+
public class CWH_Ch2_Operators {
42+
public static void main(String[] args) {
43+
// 1. Arithmetic Operators
44+
int a = 4;
45+
// int b = 6 % a; // Modulo Operator
46+
// 4.8%1.1 --> Returns Decimal Remainder
47+
48+
// 2. Assignment Operators
49+
int b = 9;
50+
b *= 3;
51+
System.out.println(b);
52+
53+
// 3. Comparison Operators
54+
// System.out.println(64<6);
55+
56+
// 4. Logical Operators
57+
// System.out.println(64>5 && 64>98);
58+
System.out.println(64>5 || 64>98);
59+
60+
// 5. Bitwise Operators
61+
System.out.println(2&3);
62+
// 10
63+
// 11
64+
// ----
65+
// 10
66+
}
67+
}
68+
```
69+
70+
### Handwritten Notes: [Click To Download](https://api.codewithharry.com/media/videoSeriesFiles/courseFiles/java-tutorials-for-beginners-8/Chapter2.pdf)
71+
72+
### Ultimate Java Cheatsheet: [Click To Download](https://api.codewithharry.com/media/videoSeriesFiles/courseFiles/java-tutorials-for-beginners-8/UltimateJavaCheatSheet.pdf)

0 commit comments

Comments
 (0)