DifferenceModerate2 marks
Write one difference between primitive data types and composite data types.
Topic: Primitive and composite data types
Previous-year question practice database
Answer
Exam answer
The difference is shown in the table.
Explanation
The essential contrast is single value versus collection of values, or equivalently value versus reference. Give one clear difference and examples of each — the examples usually carry half the marks. A quick recognition test worth adding: primitives are written in lower case, composite types with a capital first letter. That is why String is composite despite being used as freely as a primitive.
Comparison
| Primitive data types | Composite (non-primitive) data types |
|---|---|
| Built into the language; each holds a single value directly. | Built by the programmer or the library; each holds a reference to something that may contain many values. |
| Examples: int, char, double, boolean (eight in all). | Examples: String, arrays, classes, interfaces. |
More from Revision Tour I
The full form of JVM is:2026Which of the following occupies 2 bytes of storage?2026In a statement c = c + (x * d + e); which variable is an accumulator?2026Assertion (A): The result of the Java expression 3 + 7/2 is 6.
Reason (R): According to the hierarchy of operators in Java, addition is done first followed by division.2026Evaluate the Java expression:
x = a * b % (++c) + (++a) + (--b);
if a = 7, b = 8, c = 22026System.out.println('Z' + 32); will display:2025