aspose file tools*
The moose likes Beginning Java and the fly likes asking about string as a object in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "asking about string as a object in java" Watch "asking about string as a object in java" New topic
Author

asking about string as a object in java

kumar abhay
Ranch Hand

Joined: Oct 02, 2001
Posts: 53
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

Joined: Mar 16, 2001
Posts: 986

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.


Please ignore post, I have no idea what I am talking about.
Michael Bruesch
Ranch Hand

Joined: Sep 23, 2001
Posts: 158
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


Michael J Bruesch<br /><i>I code, therefore I am.</i>
Rizwan, Ahmed
Greenhorn

Joined: Jun 13, 2001
Posts: 10

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

Joined: Sep 23, 2001
Posts: 158
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).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: asking about string as a object in java