|
| 1 | +// package com.rit; |
| 2 | + |
| 3 | +public class JavaLecture6 { |
| 4 | + |
| 5 | + public static void main(String[] args) { |
| 6 | + |
| 7 | + // Types of Languages |
| 8 | + // 1 - Statically-typed Languages (C/C++, Java, Scala, C#, Go, Rust, Dart, TS, Kotlin, ...) |
| 9 | + // - Type checking at compile time |
| 10 | + // 2 - Dynamically-typed Languages (PHP, Perl, Lua, R, Ruby, JS, Python, Julia, ...) |
| 11 | + // - Type checking at runtime |
| 12 | + |
| 13 | + // Java Data Types |
| 14 | + // All Java Data-Types are separated into two groups: |
| 15 | + // 1 - Primitive types or Value types or Simple types |
| 16 | + // 2 - References types or Non-Primitive types or Object types or Complex types |
| 17 | + |
| 18 | + // 1 - Primitive types (storing simple values) |
| 19 | + // - Java has 8 primitive data types. They can be divided into 4 groups: |
| 20 | + // - Integer Numbers: byte, short, int, long |
| 21 | + // - Floating-Point Numbers: float, double |
| 22 | + // - Logical Type: boolean |
| 23 | + // - Characters: char |
| 24 | + // - The most used primitive types are "int", "long", "double", "boolean", and "char". |
| 25 | + |
| 26 | + // 2 - References types (storing complex structure/objects) |
| 27 | + // - String |
| 28 | + // - Objects |
| 29 | + // - Arrays |
| 30 | + // - Classes |
| 31 | + // - Interfaces |
| 32 | + |
| 33 | + // Sizes and Ranges of Primitive types |
| 34 | + // boolean: It represents only 1-bit of information, but its size is not something that's precisely defined. true or false |
| 35 | + // byte: the size is 08-bits (1 byte ), the range is from -128 to 127 |
| 36 | + // char: the size is 16-bits (2 bytes), the range is from 0 to 65536 (unsigned) |
| 37 | + // short: the size is 16-bits (2 bytes), the range is from -32768 to 32767 |
| 38 | + // int: the size is 32-bits (4 bytes), |
| 39 | + // long: the size is 64-bits (8 bytes), |
| 40 | + // float: the size is 32-bits (4 bytes), approximately 6-7 significant decimal digits |
| 41 | + // double: the size is 64-bits (8 bytes), approximately 14-16 significant decimal digits |
| 42 | + |
| 43 | + // Default Values of Primitive types |
| 44 | + // boolean - false |
| 45 | + // char - \u0000 |
| 46 | + // byte, short, int, long - 0 |
| 47 | + // float, double - 0.0 |
| 48 | + |
| 49 | + // Primitive types Variables |
| 50 | + byte age = 26; |
| 51 | + short s = 5569; |
| 52 | + int v1 = 712928; |
| 53 | + long v2 = 32_754_921L; |
| 54 | + long v3 = 4242L; |
| 55 | + |
| 56 | + int decNum = 190; |
| 57 | + int octNum = 0457; |
| 58 | + int hexNum = 0xFA; |
| 59 | + int binNum = 0b1101; |
| 60 | + |
| 61 | + int minInt = Integer.MIN_VALUE; |
| 62 | + int maxInt = Integer.MAX_VALUE; |
| 63 | + |
| 64 | + float p1 = 424.42F; |
| 65 | + double p2 = 3523184.428d; |
| 66 | + double eps = 5e-3; // 5 * 10^(-3) = 0.0005 |
| 67 | + // System.out.println(Double.SIZE); // 64-bits |
| 68 | + double minDbl = Double.MIN_VALUE; |
| 69 | + double maxDbl = Double.MAX_VALUE; |
| 70 | + |
| 71 | + char ch = 'C'; |
| 72 | + char b = 'a' + 1; // the 'b' character |
| 73 | + char d = 'b' + 2; // the 'd' character |
| 74 | + char ch1 = 101; // the 'e' character |
| 75 | + char ch2 = '\u0040'; // the '@' character |
| 76 | + |
| 77 | + boolean r1 = true; |
| 78 | + boolean r2 = false; |
| 79 | + boolean r3 = 5 > 2; |
| 80 | + |
| 81 | + // References types Variables |
| 82 | + String msg1 = "Java Programming "; |
| 83 | + String msg2 = new String("Hi Java String"); |
| 84 | + String newStr = msg1.concat("for Android"); |
| 85 | + System.out.println(newStr); |
| 86 | + |
| 87 | + // Happy Learning :) |
| 88 | + } |
| 89 | +} |
0 commit comments