Classify the following as primitive or non primitive data types:
i) char
ii) String
iii) int
iv) class
Answers
Answer:
i) char : The CHAR data type. The CHAR data type stores character data in a fixed-length field. Data can be a string of single-byte or multibyte letters, numbers, and other characters that are supported by the code set of your database locale. The size of a CHAR column is byte-based, not character-based.
ii) String : A string is a data type used in programming, such as an integer and floating point unit, but is used to represent text rather than numbers. It is comprised of a set of characters that can also contain spaces and numbers. For example, the word "hamburger" and the phrase "I ate 3 hamburgers" are both strings.
iii) int : Integer: Keyword used for integer data types is int. Integers typically requires 4 bytes of memory space and ranges from -2147483648 to 2147483647. Keyword used for character data type is char. Characters typically requires 1 byte of memory space and ranges from -128 to 127 or 0 to 255.
iv) class : Other than the primitive data types, all data types are classes. In other words, data is either primitive data or object data. Every object in Java is an instance of a class. A class definition has to exist first before an object can be constructed.