Java - Primitive data types
Java - Primitive Data Types Primitive types in Java include integer types, floating-point numbers, UTF-16 code units and a boolean type. There are no unsigned types in Java except char type, which is used to represent UTF-16 code units. The lack of unsigned types is offset by introducing unsigned right shift operation, which is not present in C++. A primitive type is predefined by the language and it is a reserved keyword. The eight primitive data types supported by the Java language are these: byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 inclusive. short: The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 inclusive. int: The int data type is a 32-bit signed two's complement integer. Int can hold integers only and not double unlike double can hold integers. Int x = 55; double y= 65.9; double: The double data type is for holding decimal values. Ex. Double x = 2.6, double y=6 :this is valid as 6=6.0 long: The long data type is a 64-bit two's complement integer. Use this data type when you need a range of values wider than those provided by int. float: The float data type is a single-precision 32-bit IEEE 754 floating point. As with the recommendations for byte and short, use a float (instead of double) if you need to save memory. boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information. char: The char data type is a single 16-bit Unicode character, that holds a single character ex. single letter, number, or symbol. For example, 'apple' is a character, so is '1' and '&'. Those are all characters. watch single quotes for char value. This is different from Strings which must have double quotes. Like String city = “Singapore” The Java language also provides support for strings via the java.lang.String class. String: Use double quotes to convert a character string to new String object; for example, String str = “be good and god"; Java string is an object to represent array of char (character)
Java - Primitive Data Types Primitive types in Java include integer types, floating-point numbers, UTF-16 code units and a boolean type. There are no unsigned types in Java except char type, which is used to represent UTF-16 code units. The lack of unsigned types is offset by introducing unsigned right shift operation, which is not present in C++. A primitive type is predefined by the language and it is a reserved keyword. The eight primitive data types supported by the Java language are these: byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 inclusive. short: The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 inclusive. int: The int data type is a 32-bit signed two's complement integer. Int can hold integers only and not double unlike double can hold integers. Int x = 55; double y= 65.9; double: The double data type is for holding decimal values. Ex. Double x = 2.6, double y=6 :this is valid as 6=6.0 long: The long data type is a 64-bit two's complement integer. Use this data type when you need a range of values wider than those provided by int. float: The float data type is a single-precision 32-bit IEEE 754 floating point. As with the recommendations for byte and short, use a float (instead of double) if you need to save memory. boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information. char: The char data type is a single 16-bit Unicode character, that holds a single character ex. single letter, number, or symbol. For example, 'apple' is a character, so is '1' and '&'. Those are all characters. watch single quotes for char value. This is different from Strings which must have double quotes. Like String city = “Singapore” The Java language also provides support for strings via the java.lang.String class. String: Use double quotes to convert a character string to new String object; for example, String str = “be good and god"; Java string is an object to represent array of char (character)