String constant

why r we not able to change a string constant in java?
[61 byte] By [bluestar420a] at [2007-11-26 17:33:37]
# 1
Um... because it's.... CONSTANT maybe?
jverda at 2007-7-9 0:01:37 > top of Java-index,Java Essentials,New To Java...
# 2
yeah what Jeff said. Or perhaps you are asking about Strings being immutable.
floundera at 2007-7-9 0:01:37 > top of Java-index,Java Essentials,New To Java...
# 3
> Or perhaps you are asking about> Strings being immutable.That's my guess. I just could resist though, when somebody asks, "Why can't I change a constant?" Poorly thought out, poorly worded questions like that just make my teeth itch.
jverda at 2007-7-9 0:01:37 > top of Java-index,Java Essentials,New To Java...
# 4

Lately, it seems like a lot of people are receiving really bad basic Java instruction. Maybe it's just me, but it seems like there's been a jump recently in questions like this one, or "What's better, String or StringBuffer?" as if they were completely interchangeable (in fact, over at JavaRanch, that exact question seems to be posted about once a week.) These same incompetent teachers are still telling their hapless students to use StringBuffer, Vector and Hashtable, as if Java had stopped evolving at version 1.1. One might almost suspect a conspiracy...

uncle_alicea at 2007-7-9 0:01:37 > top of Java-index,Java Essentials,New To Java...
# 5
> as if Java had stopped evolving at version 1.1Actually it is the teachers who stopped evolving.
floundera at 2007-7-9 0:01:37 > top of Java-index,Java Essentials,New To Java...
# 6

> Lately, it seems like a lot of people are receiving

> really bad basic Java instruction. Maybe it's just

> me, but it seems like there's been a jump recently in

> questions like this one, or "What's better, String or

> StringBuffer?" as if they were completely

> interchangeable (in fact, over at JavaRanch, that

> exact question seems to be posted about once a week.)

My eyes about popped out of my head a week or so ago when I saw here, roughly, "Which is better, interface or switch?"

jverda at 2007-7-9 0:01:37 > top of Java-index,Java Essentials,New To Java...
# 7
> My eyes about popped out of my head a week or so ago> when I saw here, roughly, "Which is better, interface> or switch?"Okay, Mr. Smarty Man, so which one is better, if you think you know so much?;o)~
yawmarka at 2007-7-9 0:01:37 > top of Java-index,Java Essentials,New To Java...
# 8

> > My eyes about popped out of my head a week or so

> ago

> > when I saw here, roughly, "Which is better,

> interface

> > or switch?"

>

> Okay, Mr. Smarty Man, so which one is better, if you

> think you know so much?

Mauve has the most RAM. Duh.

jverda at 2007-7-9 0:01:37 > top of Java-index,Java Essentials,New To Java...
# 9
I want to say, how string is immutable?what makes it immutable?
bluestar420a at 2007-7-9 0:01:37 > top of Java-index,Java Essentials,New To Java...
# 10
It's immutable because it was designed that way.You can make your own classes immutable (in fact, it's often a good idea to do so) by designing the interface as such (for example, by not creating any methods that change anything) and by using the final keyword.
paulcwa at 2007-7-9 0:01:37 > top of Java-index,Java Essentials,New To Java...
# 11

> I want to say, how string is immutable?what makes it

> immutable?

Q:Why do airplanes fly?

A:Because it was designed to fly.

Q:Why do ships float on water?

A:Because it was designed to float on water.

Q:Why do you ask such pathetic questions?

A:Well even i don't have an answer for this.

qUesT_foR_knOwLeDgea at 2007-7-9 0:01:37 > top of Java-index,Java Essentials,New To Java...
# 12

> > I want to say, how string is immutable?what makes

> it

> > immutable?

>

> Q:Why do airplanes fly?

> A:Because it was designed to fly.

>

> Q:Why do ships float on water?

> A:Because it was designed to float on water.

>

> Q:Why do you ask such pathetic questions?

> A:Well even i don't have an answer for this.

No matter how I love a good troll bashing, this makes no sense. You cannot answer every question with "because it was designed so". An airplane flies because of the pressure difference under and over the wing (I think :)) So it obviously *has* a reason. Sun having designed immutable strings, probably has a reason (Answers to be found everywhere)

SurfManNLa at 2007-7-9 0:01:37 > top of Java-index,Java Essentials,New To Java...
# 13
Just making a class final, can we be able to make it immutable?if we r designing an interface, we can be able to change the functionality of the methods in it ...so how can we able to make our own class immutable?
bluestar420a at 2007-7-9 0:01:37 > top of Java-index,Java Essentials,New To Java...
# 14
> Just making a class final, can we be able to make it> immutable?if we r designing an interface, we can be> able to change the functionality of the methods in it> ...so how can we able to make our own class immutable?Read reply #10 by paulcw
kajbja at 2007-7-9 0:01:37 > top of Java-index,Java Essentials,New To Java...
# 15

> Just making a class final, can we be able to make it

> immutable?

No, making a class final makes it impossible to create a subclass of this class.

> if we r designing an interface, we can be

> able to change the functionality of the methods in it

An interface has methods, but does not contain the implementation.

> ...so how can we able to make our own class immutable?

Make sure the fields are private, there are no setters, and the getters returns copies/clones of the values.

SurfManNLa at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 16

> > > I want to say, how string is immutable?what

> makes

> > it

> > > immutable?

> >

> > Q:Why do airplanes fly?

> > A:Because it was designed to fly.

> >

> > Q:Why do ships float on water?

> > A:Because it was designed to float on

> water.

> >

> > Q:Why do you ask such pathetic questions?

> > A:Well even i don't have an answer for

> this.

>

> No matter how I love a good troll bashing, this makes

> no sense. You cannot answer every question with

> "because it was designed so". An airplane flies

> because of the pressure difference under and over the

> wing (I think :)) So it obviously *has* a reason. Sun

> having designed immutable strings, probably has a

> reason (Answers to be found everywhere)

Please care to read what i have quoted.The question which i have quoted is "I want to say, how string is immutable?what makes it immutable?"

He's not asking here why strings are immutable.Hes asking some **** like what makes it immutable?Now how much sense does that make?

qUesT_foR_knOwLeDgea at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 17
I assumed that "I want to say, how string is immutable?what makes it immutable?" was equivalent to WHY.... I think the English skills of the OP kinda pushed me that way....
SurfManNLa at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 18

> He's not asking here why strings are immutable.Hes

> asking some **** like what makes it immutable?Now how

> much sense does that make?

It's a perfectly valid question. It's also a good reason for the OP to refrain from [url=http://forum.java.sun.com/thread.jspa?threadID=5133944]trying to tackle J2EE applications[/url] until s/he has a good understanding of the fundamentals.

~

yawmarka at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 19
> An airplane flies because of the pressure difference > under and over the wing (I think :))Actually it flies because it pushes air downward (and Newton takes care of the rest :) ).
EvilBroa at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 20

> > An airplane flies because of the pressure

> difference

> > under and over the wing (I think :))

>

> Actually it flies because it pushes air downward (and

> Newton takes care of the rest :) ).

Isn't that because of the pressure difference?

CaptainMorgan08a at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 21
> Isn't that because of the pressure difference?No, it is just like that becaue that's what the airplane wants to happen.
kajbja at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 22

> Actually it flies because it pushes air downward (and

> Newton takes care of the rest :) ).

Reduced pressure on the upper wing surface provides lift, i.e., increased upward pressure on the underside of the wing. How are you understanding that an airplane wing pushes air downward?

[EDIT] I googled and found the "Coanda effect". Disregard my previous question. :o)

~

yawmarka at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 23

> ...so how can we able to make our own class immutable?

1. Don't provide any methods that modify the object (mutators)

2. Ensure that no methods may be overridden

3. Make all fields final

4. Make all fields private

5. Ensure exclusive access to any mutable components

YoGeea at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 24

I hate to bump a pointless thread, but something has always bugged the hell out of me.

Why is it all noobs to this forum use "u", "r", "n", etc. in place or "you", "are", "and", etc., respectively? This happens often when people post their homework from college or AP Computer Science courses.

Why do people in AP courses or in college courses feel the need to type "u", "r", etc.? Do they not realize how retarded it makes them look?

Has anyone here ever typed like that? I must admit, I used to when I was TWELVE. Then, when I was about 12 1/2, I realized how utterly absurd it is.

So, I guess my question is: WHY?

That cannot be answered, can it?

Djaunla at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 25
> Q:Why do you ask such pathetic questions?Ironic, coming from you questie. You're one of the most pathetic question asker I've ever encountered around here.
warnerjaa at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 26
> So, I guess my question is: WHY?The question is: Y?;oP~ Ywmrk
yawmarka at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 27

> Ironic, coming from you questie. You're one of the

> most pathetic question asker I've ever encountered

> around here.

I don't remember asking questions here at the forum other than asking reviews about the books i would want to buy?Now stop tailing me for christs sake.

qUesT_foR_knOwLeDgea at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 28
> Why is it all noobs to this forum use "u", "r", "n",> etc. in place or "you", "are", "and", etc.,Presumably habit & laziness developed when texting on their cell phones. It's terribly annoying, and it will never stop.
jverda at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 29

> > Ironic, coming from you questie. You're one of the

> > most pathetic question asker I've ever encountered

> > around here.

>

> I don't remember asking questions here at the forum

> other than asking reviews about the books i would

> want to buy?Now stop tailing me for christs sake.

Sorry Quest, but I thought the same thing as warnerja did when I read that. To be honest you have been a pain with the questions you asked in the past. Lately you have been attempting to help, but at first you appeared to be a troll with an attitude.

zadoka at 2007-7-21 17:07:07 > top of Java-index,Java Essentials,New To Java...
# 30
@OP: I believe there's a chapter in Effective Java by Joshua Bloch that goes into this. The easiest thing is just for you to read it now than for us to reiterate it in a forum.
paulcwa at 2007-7-21 17:07:11 > top of Java-index,Java Essentials,New To Java...
# 31

> Sorry Quest, but I thought the same thing as warnerja

> did when I read that. To be honest you have been a

> pain with the questions you asked in the past.

> Lately you have been attempting to help, but at

> first you appeared to be a troll with an attitude.

Quest,

Also, I don't think I am the only one that feels this way. Have you forgotten how you originally acted?

Take a look at reply #19 here:

http://forum.java.sun.com/thread.jspa?forumID=54&threadID=792419

zadoka at 2007-7-21 17:07:11 > top of Java-index,Java Essentials,New To Java...
# 32

> Sorry Quest, but I thought the same thing as warnerja

> did when I read that. To be honest you have been a

> pain with the questions you asked in the past.

> Lately you have been attempting to help, but at

> first you appeared to be a troll with an attitude.

The only time i remember getting involved in a question was the one on multithreading and that too involving only jverd.Oh ya and one on suns implementation of interfaces and after that a lot on books and initially a few altercations.But that was at the beginning.Even i consider myself a troll when i think of the way i was then.But now it's warner who's trying to pick a quarrel with me everytime.Keep up the good work warner while i enjoy ignoring you.

qUesT_foR_knOwLeDgea at 2007-7-21 17:07:11 > top of Java-index,Java Essentials,New To Java...
# 33

> The only time i remember getting involved in a

> question was the one on multithreading and that too

> involving only jverd.Oh ya and one on suns

> implementation of interfaces and after that a lot on

> books and initially a few altercations.But that was

> at the beginning.Even i consider myself a troll when

> i think of the way i was then.But now it's warner

> who's trying to pick a quarrel with me everytime.Keep

> up the good work warner while i enjoy ignoring you.

I did point out that your behavior has changed. However, you have to realize that the bad taste your first impression left in our mouths will take a while to go away. (Assuming you don't go back to trolling).

zadoka at 2007-7-21 17:07:11 > top of Java-index,Java Essentials,New To Java...
# 34

> > Sorry Quest, but I thought the same thing as

> warnerja

> > did when I read that. To be honest you have been

> a

> > pain with the questions you asked in the past.

> > Lately you have been attempting to help, but at

> > first you appeared to be a troll with an

> attitude.

>

> Quest,

>

> Also, I don't think I am the only one that feels this

> way. Have you forgotten how you originally acted?

>

> Take a look at reply #19 here:

>

> http://forum.java.sun.com/thread.jspa?forumID=54&threa

> dID=792419

As i just to told you i don't disagree with the rest and infact i considered myself a troll then.But i have put all those things behind my back.

qUesT_foR_knOwLeDgea at 2007-7-21 17:07:11 > top of Java-index,Java Essentials,New To Java...
# 35
(referring to the R U 2 text-speak) Perhaps one of those posters is [url= http://i.realone.com/assets/rn/img/1/3/2/2/10352231-10352233-large.jpg]Prince[/url].
DrLaszloJamfa at 2007-7-21 17:07:11 > top of Java-index,Java Essentials,New To Java...
# 36
> (referring to the R U 2 text-speak) Perhaps one of> those posters is> [url= http://i.realone.com/assets/rn/img/1/3/2/2/103522> 31-10352233-large.jpg]Prince[/url].Crappy music from a crappy voice.
qUesT_foR_knOwLeDgea at 2007-7-21 17:07:11 > top of Java-index,Java Essentials,New To Java...
# 37
> But now it's warner> who's trying to pick a quarrel with me everytime.Keep> up the good work warner while i enjoy ignoring you.It appears the message is getting through to you afterall. Good.
warnerjaa at 2007-7-21 17:07:11 > top of Java-index,Java Essentials,New To Java...
# 38
> It appears the message is getting through to you> afterall. Good.Which message are you talking about?
qUesT_foR_knOwLeDgea at 2007-7-21 17:07:11 > top of Java-index,Java Essentials,New To Java...
# 39
> > It appears the message is getting through to you> > afterall. Good.> > Which message are you talking about?Everything you claim to have been ignoring.
warnerjaa at 2007-7-21 17:07:11 > top of Java-index,Java Essentials,New To Java...
# 40

> > > It appears the message is getting through to you

> > > afterall. Good.

> >

> > Which message are you talking about?

>

> Everything you claim to have been ignoring.

Whatever.Catch me sometime else.And to get to your notice you can't provoke even the hell out of me to get involved in any altercation with you.

qUesT_foR_knOwLeDgea at 2007-7-21 17:07:11 > top of Java-index,Java Essentials,New To Java...