Datatypes: ========== 3-things described: 1) type of the data 2) memory 3) range of values 1) Integral Datatypes: ====================== byte Datatype ==> byte 1-bite = 8-bits 256 values -128 to 127 short Datatype ==> short ========================= Syntax: short variable-name = value; size ==> 2-bytes = 16-bits total values ==> 2^16 ==> 65536 range of values: -32768 to + 32767 class Datatypes{ public static void main(String[] x) { short a; // declaration // a = -32768; // a = -32769; // a = 0; // a = 32767; a = 32768; System.out.println(a); } } ======================================== int datatype: ============ keyword: int ==> memory size = 4-bytes == 32-bits ==> total values ==> 2^32 ==> 4294967296 ==> Range ==> -2147483648 to 2147483647 -(2^32)/2 to ((2^32)/2)-1 ==> Syntax: int variable-name = value; class Datatypes{ public static void main(String[] x) { int a; // a = 2147483648; a = 0; System.out.println(a); } } ========================================== Long Datatype: ============== keyword: long Syntax: long variable-name = value; ==> memory size ==> 8-bytes ==> 64-bits ==> total value ==> 2^64 ==> range ==> -(2^64/2) to (2^64/2)-1 Strongly Typed Programming Language: ==================================== High-level programming languages C, C++, Python, Java etc. ==> classified into three types: based on the data definition 1) Statically typed 2) Dynamically Typed 3) Strongly Typed Order for integral datatypes: ============================= long ==> int ===> short ==> byte ==================================================== Floating-Point Datatypes: ========================= ==> two types: 1) float datatype ==> float ==> 4-bytes 1.230000 ==> single precision float data 2) double datatype ==> double ==> 8-bytes ==> double precision float data ex: 1.23000000000000 Note: ==== float data can always suffix with 'f'/'F' for the double data, no suffix is required. class Datatypes{ public static void main(String[] x) { float f; double d; f = 1.23f; // d = 1.23F; d = 1.233; System.out.print(f); System.out.println(d); } } ======================================== Order of data: ============== float >> int double >> float >> long >> int >> short >> byte =========================================== Boolean Datatypes: ================== keyword: Boolean Syntax: boolean var-name = value; memory: 1 byte values: true and false Note: ===== true ==> never be '1' in java false ==> never be '0' true + true ==> 2 double >> float >> long >> int >> short >> byte >> boolean ================================================== Character Datatype: =================== keyword: char ==> In C: char ==> 1-byte ==> ASCII (American Standard Code Information Interchange) defined with total 256 integer values. ex: A to Z ==> 65 to 90 a to z ==> 97 to 122 0 to 9 ==> 48 to 57 ==> char data can always define with single quotes. ==> with in the single quotes only one character we can place. ex: 'a', '1', '@' etc. 'ab' ==> Error ==> In Java: char ==> 2-bytes ==> 65536 characters Unicode dependent double >> float >> long >> char >> int >> short >> byte