|
| 1 | +package Java_Technical_Training; |
| 2 | + |
| 3 | +class Parents { |
| 4 | + |
| 5 | +} |
| 6 | + |
| 7 | +class A extends Parents { |
| 8 | + |
| 9 | +} |
| 10 | + |
| 11 | +class B extends Parents { |
| 12 | + |
| 13 | +} |
| 14 | + |
| 15 | +public class javaOperators { |
| 16 | + public static void main(String[] args) { |
| 17 | + // ! Types of operators: |
| 18 | + /* |
| 19 | + * Arithmetic operators (+,-,*,/) |
| 20 | + * Logical operators (&&, ||, ! ) |
| 21 | + * Unary operators => (++x, --x, x++, x--) |
| 22 | + * Arithmetic Assignment operators (+=, -=, *=, /=) |
| 23 | + * Ternary operators (? : ) |
| 24 | + * Relational operators (>,<, <=, >=, ==, = , !=) |
| 25 | + * Bitwise operators (&, !, ^, ~) |
| 26 | + * shifting operators are part of Bitwise operators ( >>, <<, >>>) |
| 27 | + */ |
| 28 | + |
| 29 | + byte a = 10; |
| 30 | + byte b = 34; |
| 31 | + |
| 32 | + byte c = (byte) (a + b); |
| 33 | + // ? type conversion |
| 34 | + |
| 35 | + Parents obj = new A(); |
| 36 | + Parents obj1 = new B(); |
| 37 | + |
| 38 | + System.out.println(obj instanceof A); |
| 39 | + System.out.println(obj1 instanceof B); |
| 40 | + System.out.println(obj1 instanceof A); |
| 41 | + System.out.println(obj instanceof B); |
| 42 | + |
| 43 | + System.out.println(c); |
| 44 | + |
| 45 | + System.out.println("Logcal operators"); |
| 46 | + System.out.println("100 & 39 == " + (100 & 39)); |
| 47 | + System.out.println("100 | 39 == " + (100 | 39)); |
| 48 | + Boolean res = true; |
| 49 | + System.out.println(!res); |
| 50 | + System.out.println(!!res); |
| 51 | + |
| 52 | + // ? when we use Arithmetic Assignment operators, we don't need to typecast the |
| 53 | + // variables |
| 54 | + System.out.println("Arithmetic Assignment operators: " + a + " " + b); |
| 55 | + System.out.println(a += b); |
| 56 | + System.out.println(a -= b); |
| 57 | + System.out.println(a *= b); |
| 58 | + |
| 59 | + System.out.println("Ternary operators"); |
| 60 | + System.out.println(" a is " + a); |
| 61 | + String aa = a >= 50 ? "it is greater than 50" : "it is lower than "; |
| 62 | + System.out.println(aa); |
| 63 | + |
| 64 | + System.out.println(" a is " + a); |
| 65 | + System.out.println(" a is " + (a >> 1)); |
| 66 | + System.out.println(" a is " + (a >> 2)); |
| 67 | + System.out.println(" a is " + (a >> 3)); |
| 68 | + System.out.println(" \n a is " + a); |
| 69 | + System.out.println(" a is " + (a << 1)); |
| 70 | + System.out.println(" a is " + (a << 2)); |
| 71 | + |
| 72 | + // ! difference between right shift and unsigned right shift |
| 73 | + |
| 74 | + int tt = 15; |
| 75 | + System.out.println(" tt = " + (tt >> 2)); |
| 76 | + System.out.println(" tt = " + (tt >>> 2)); |
| 77 | + // ? change left most digit while using unsigned right shift |
| 78 | + } |
| 79 | +} |
0 commit comments