Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String listed as Java primitive data type #109

Open
swapnilmadavi opened this issue Dec 14, 2021 · 2 comments
Open

String listed as Java primitive data type #109

swapnilmadavi opened this issue Dec 14, 2021 · 2 comments

Comments

@swapnilmadavi
Copy link

For the question
Can you list 8 primitive types in java?
in Objects and Primitives section, String is listed as an extra Primitive data type.

According to the Java documentation (here),

The String class is not technically a primitive data type

@MalaRuparel2023
Copy link

In Java, there are eight primitive data types:

byte: 8-bit signed integer. Range: -128 to 127.
short: 16-bit signed integer. Range: -32,768 to 32,767.
int: 32-bit signed integer. Range: -2^31 to 2^31 - 1.
long: 64-bit signed integer. Range: -2^63 to 2^63 - 1.
float: 32-bit floating point. Range: approximately ±3.40282347E+38F (6-7 significant decimal digits).
double: 64-bit floating point. Range: approximately ±1.79769313486231570E+308 (15 significant decimal digits).
char: 16-bit Unicode character. Represents a single character. Range: '\u0000' to '\uffff'.
boolean: Represents true or false values.

@KaranSuthar099
Copy link

Java provides eight premitive data types which include -

  1. byte: 8-bit signed integer (-128 to 127).
    Saves memory in large arrays.
    byte b = 100;

  2. short: 16-bit signed integer (-32,768 to 32,767).
    Also useful for memory savings in large arrays.
    short s = 10000;

  3. int: 32-bit signed integer (-2^31 to 2^31-1).
    Can be used as an unsigned integer (0 to 2^32-1) in Java SE 8+.
    int i = 100000;

  4. long: 64-bit signed integer (-2^63 to 2^63-1).
    Can be used as an unsigned integer (0 to 2^64-1) in Java SE 8+.
    long l = 100000L;

  5. float: 32-bit single-precision floating point.
    Not for precise values like currency.
    float f = 10.5f;

  6. double: 64-bit double-precision floating point.
    Default for decimal values, not for precise values.
    double d = 10.5;

  7. boolean: Represents true/false values.
    boolean flag = true;

  8. char: 16-bit Unicode character ('\u0000' to '\uffff').
    char c = 'A';

String in Java

Is a reference type. Strings are an object they are instances of the java.lang.String class. For string manipulation wide range of methods are provided which includes concatenation, comparison, and substring extraction. String objects are immutable, any modification results in the creation of a new String object.

Strings being an important DataType have been provided a special initialization technique:
String str1 = "Hello, World!";

however, java also support initialization using new keyword like reference types :
String str2 = new String("Hello, World!");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants