Bookmark Topic Watch Topic
  • New Topic

Same class name and data type.......  RSS feed

 
harsh garg
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Report post to moderator
why String (data type and class )of java have the same name?No other data type of java exist like this .....
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Report post to moderator
I'm not sure what you mean by "data type". String is a class, from which you can instantiate objects, like you can with all other classes.

The only specialties are that the compiler recognizes the "xyz" syntax as being a string literal and creates string objects accordingly, and that strings can be concatenated by overloading the "+" operator. Given how frequently strings are used, these seem like useful enhancements.

You could ask similar questions about the other primitive types (which have also corresponding classes that can -since Java 1.5- be used interchangeably with them).
 
Balagopal Kannampallil
Ranch Hand
Posts: 136
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
The String class cannot be termed as a primitive data type like the other eight primitives.
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Duplicate.

Please Use One Thread Per Question.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!