• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is immutable class ?  RSS feed

 
Moguluri Ravi Kiran
Ranch Hand
Posts: 63
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

this is kiran, please explain me 'what is immutable class ?', & also tell me about the java IDEs.
suggest me a good IDE to learn.

thanks in advance.
 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Immutable is when something can't be changed after it is created, for example the String class, there is a basic explanation here : http://en.wikipedia.org/wiki/Immutable_object

Regarding IDEs, download Eclipse or Netbeans, they are 2 popular Java IDEs (personally I prefer Netbeans because its a bit simpler IMHO)
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseOneThreadPerQuestion

If you are at a beginner stage, I would strongly recommend against using any type of IDEs. Start off with using a simple text editor like notepad and progressively move towards an IDE .
 
Brad Dwan
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Please UseOneThreadPerQuestion

If you are at a beginner stage, I would strongly recommend against using any type of IDEs. Start off with using a simple text editor like notepad and progressively move towards an IDE .


No offence intended. Why? I would think being able to know spot syntax errors, use auto-complete and, the constant javadocs features would be extremely helpful to programming novice. I'm new to Java, but not programming and OOP, and using the IDE has allowed me to progress at a much greater rate then a plain text editor. I could understand the need to learn how to manually compile/build in command prompt and alike, but that's not overly difficult, nor needed these days. Each to their own in my opinion.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brad Dwan wrote:
Why? I would think being able to know spot syntax errors, use auto-complete and, the constant javadocs features would be extremely helpful to programming novice. I'm new to Java, but not programming and OOP, and using the IDE has allowed me to progress at a much greater rate then a plain text editor. I could understand the need to learn how to manually compile/build in command prompt and alike, but that's not overly difficult, nor needed these days. Each to their own in my opinion.


Its a bit more than using the command line tools. There are some very distinct setup quirks with Java. In my previous company, we sent an "experience" engineer on site, and this engineer could not get the classpath correct (production code obviously are not run by IDEs). It was quite embarrassing.

Henry
 
Moguluri Ravi Kiran
Ranch Hand
Posts: 63
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String is immutable , means the String object once created can't be changed , But i have small doubt..

we can do

String s = "aa";
s+="bb";

isn't the original object 's' changed ?

Thanks.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brad Dwan wrote:No offence intended. Why? I would think being able to know spot syntax errors, use auto-complete and, the constant javadocs features would be extremely helpful to programming novice.

Because you learn more, and learn how to learn more quickly, if an IDE isn't holding your hand. In addition, IDE's can *cause* problems that aren't directly related to the learning that's actually going on. It's easier, quicker, and more efficient to attack one set of problems at a time: the more layers are involved the more overwhelming, the more obfuscation, the more things that can go wrong.

Just like if I'm learning a new framework I wouldn't start with a complete application--I'd build it up over time, understanding each component I'm working with, each associated tool, etc. That way if something *does* go wrong I have only a small set of known things to look at, rather than every single item in my tool chain and development process.
I could understand the need to learn how to manually compile/build in command prompt and alike, but that's not overly difficult, nor needed these days.

In order to understand what happens when things go wrong with tools like Ant or Maven a strong grounding in the fundamentals is *mandatory*. If you can't figure out a classpath issue on the command line how are you going to figure it out when there's multiple additional layers of obfuscation?
 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moguluri Ravi Kiran wrote:String is immutable , means the String object once created can't be changed , But i have small doubt..

we can do

String s = "aa";
s+="bb";

isn't the original object 's' changed ?

Thanks.


I think that the "internal workings" of the string append, will create a new string, so s+="bb"; would be :



Don't quote me to that, but that makes sense
 
Moguluri Ravi Kiran
Ranch Hand
Posts: 63
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your valuble views.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moguluri Ravi Kiran wrote:String is immutable , means the String object once created can't be changed , But i have small doubt..

we can do

String s = "aa";
s+="bb";

isn't the original object 's' changed ?

Thanks.


No, it is not. Without getting into the nitty-gritty details, what happens is a NEW string is created, and the reference variable s is reassigned to point to it. I think you can test this by doing something like



 
Thomas Kennedy
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String s = "aa";
s+="bb";

isn't the original object 's' changed ?


No it is not. To restate Fred's response a little, the object to which the reference variable s pointed still exists but you no longer have a reference to it. The reference variable s now points to a completely separate object whose content is "aabb".

In other words, s is not really an object at all, it's a reference variable that leads to an object. Point that reference variable somewhere else, or set it to null, or let it pass out of scope, and the object is lost unless you have another reference for it. (The object still exists and will eventually be destroyed by the garbage collector.)

If you need to do a lot of String concatenation you should use StringBuilder to avoid leaving a lot of abandoned objects in memory.

 
Lavanya Halliwell
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just did this and got:

string t is aa
string s is aabb
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you expect to happen?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[quote=Lavanya Halliwell]I just did this and got:

string t is aa
string s is aabb[/quote]
exactly. That shows that your original string of "aa" didn't change. It's still there, untouched.

A new, second string of "aabb" was created, and s now points to that.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!