Computer Applications

Define the following with an example:

(a) variable

(b) constant

(c) boolean data type

(d) coercion

(e) primitive data type

(f) non-primitive data type

Values & Data Types Java

7 Likes

Answer

(a) Variable — Variables are identifiers that are used to name a data that holds a value in the memory. The value can change depending upon our requirements in the program.

Example, int mathScore = 95;

(b) Constant — The keyword final before a variable declaration makes it a constant. Its value can't be changed in the program.

Example: final int DAYS_IN_A_WEEK = 7;

(c) Boolean Data Type — A boolean data type is used to store one of the two boolean values — true or false. The size of boolean data type is 8 bits or 1 byte.

Example: boolean bTest = false;

(d) Coercion — In a mixed mode expression, when the data type of the result gets converted into the higher most data type available in the expression without any intervention of the user, is known as Implicit Type conversion or Coercion.

Example:

int a = 42;
long b = 50000;
long c = a + b;

Here, a is int, b is long so the result of a + b automatically gets converted into long and assigned to variable c which is of long type.

(e) Primitive Data Type — Primitive data types are the basic or fundamental data types used to declare a variable. Examples of primitive data types in Java are byte, short, int, long, float, double, char and boolean.

(f) Non-Primitive Data Type — A non-primitive data type is one that is derived from primitive data types. A number of primitive data types are used together to represent a non-primitive data type. Examples of non-primitive data types in Java are Class and Array.

Answered By

6 Likes


Related Questions