Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

asking about string as a object in java

 
kumar abhay
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi sir,
i hope u r doin' fine.i have an question about string.In java string is taken as object rather than data type.in other languages it is taken as data type.why it is so in java. i hope you will help me to solve it.take care.
with regards
kumar abhay
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean object versus primative? How would you have a string primative? What other languages have strings as primatives or data types? Characters you can have as a data type, but not a string.
 
Michael Bruesch
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, in C++, they mask String's so that they almost have the appearance of primitives, however this is not the case. They fully appear as objects in Java, because, unless you use string literals, you actually have to use the String constructor. As far as I know, you can't have Strings as a primitive.
------------------
Michael J Bruesch
Codito, ergo sum...
I code, therefore I am.
http://www.geocities.com/mjbruesch
 
Rizwan, Ahmed
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi there u had a good Questuion There ...
and i think u will not be convinced by above replies ...
i will try to sort u out from there ...

in java
String is a class that has particular specifictaions ...
and more Strings as n C++/c are char arrays ... which are ccreated by combining different chars ...

for example
in c
string is represnted as
'a','s','t','r','i','n','g'
but in java u have
simply
String a = "astring";
and that is all ...
now the memory allocated will be of totalbytes in a string

 
Michael Bruesch
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, that is exactly why they're not primitives. The lowest form you can break sentences down to is single letters (aka: chars). If you want to form complete sentences or thoughts, you must combine multiple letters (aka chars) together. There is no way no make this into a primitive form seeing as how there are literally infinite ways of putting separate chars together. Therefore, it must be made into a class where the user decides on the order in which the chars be put together. Hence...Strings.
------------------
Michael J Bruesch
Codito, ergo sum...
I code, therefore I am.
My Java Games, I'm quite proud

(Marilyn fixed url)
[This message has been edited by Marilyn deQueiroz (edited October 26, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic