11

I was wondering, why is it "String" and not "string" when all other primitive data types are lowercase?

8 Answers 8

35

String isn't a primitive datatype - it's a class, a reference type. Now admittedly it's supported directly in the VM, and there are literals in the language - but it's still not a primitive type.

Sign up to request clarification or add additional context in comments.

2 Comments

Closest answer. String is a class, which contains a lot of methods. You can, for instance, not invoke method calls on primitive data types. A String contains a value of a byte[] array: {'v', 'a', 'l', 'u', 'e'}
How could I have missed that. Thanks.
4

It's not a primitive, the String class is an object.

http://download.oracle.com/javase/6/docs/api/java/lang/String.html

1 Comment

Your link is to an old version of Java.
2

because it's a class and not a primitive data type. String is effectively an array of characters.

3 Comments

String has an array of characters. That's an important distinction! In Java, a String is an Object, not a char array
tried to keep it clean and simple. one could replace "is" by represents, covers, encompasses...
So why haven't you done that? 'Clean and simple' does not exclude 'incorrect'.
1

Although the compiler has special support for Strings, such as converting string literals into String instances, and performing String concatenation, String is not a primitive type, but a Class. By convention, class names begin in uppercase.

See the JLS section Types,Values and Variables for description of primitive types and reference types.

Comments

0

String is a non premitive data type . You can use String as follows

int monthNumber = 2;
String monthName = "";
switch(monthNumber) {
    case 1:
        monthName = "January";
        break;
    case 2:
        monthName = "February";
        break;
    case 3:
        monthName = "March";
        break;
    case 4:
        monthName = "April";
        break;
}
System.out.println("The month is " + monthName);

Comments

-1

String in java borrows C syntax , the java compiler takes String as char array , so String is an abstract data type made by char array primitive data type

Comments

-1

String is class in java.lang pack but in.java al classes are also considered as data types so we can take string data type also.. We can.cal class is user definednd data type. This is because a user can create a class. String a; A is variable f the data type "string "

Comments

-2

String is a class in java and reference data type.String is a array of character so it is not a primitive data type.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.