Which of the following is NOT a primitive data type in Java?a)intb)dou...
In Java, the keyword "string" is not a valid primitive data type. The correct spelling is "String" (with a capital 'S') and it represents a class in Java.
Which of the following is NOT a primitive data type in Java?a)intb)dou...
The correct answer is option 'C' - String.
In Java, a primitive data type represents a basic type of data that is not an object. These data types are predefined by the language and are used to declare variables. There are eight primitive data types in Java:
a) int: Represents integer values, such as 1, 2, -3, etc. It is used to store whole numbers without any fractional part.
b) double: Represents floating-point numbers, such as 3.14, 2.718, etc. It is used to store numbers with decimal places.
c) String: This is NOT a primitive data type in Java. Instead, it is a class from the Java standard library that represents a sequence of characters. Strings are used to store textual data, such as names, sentences, etc.
d) boolean: Represents a boolean value, which can be either true or false. It is used for logical operations and to determine the flow of control in programs.
The String class in Java is not a primitive data type because it is an object. It is part of the Java standard library and provides various methods to manipulate and work with strings. Although strings are commonly used in Java programs, they are not considered primitive because they are instances of a class.
While primitive data types are simple and have a fixed size, objects like the String class can have variable lengths and provide additional functionality through their methods.
To declare and use a String variable in Java, you need to use the class name followed by the variable name, like:
String name = "John";
In summary, the String data type is NOT a primitive data type in Java. It is an object from the String class in the Java standard library that represents a sequence of characters.
To make sure you are not studying endlessly, EduRev has designed Software Development study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Software Development.