Mario Digitron wrote:
Mario Skrlec wrote:I'm a big newbie to Java and this might be the most simplest code of all codes but I still need help with it.
This is basic code so, please don't tell me exactly whats wrong, give me a hint so i can figure out myself. Thank you!
SCJP 5.0 SCWCD 5.0
avi sinha wrote:The '==' operator here can return true too in case you are matching two literally defined String variable references.
Jeff Verdegan wrote:
While that's true, it's not really relevant to the question...
and there's probably no situation in which it's appropriate to test for string1 == string2..
, unless you're the author of the String class and are writing String's equals() method.
SCJP 5.0 SCWCD 5.0
avi sinha wrote:
Jeff Verdegan wrote:
While that's true, it's not really relevant to the question...
Are you sure , it is not relevant? so how are you going to describe the immutability and the need of StringBuilder??
, unless you're the author of the String class and are writing String's equals() method.
I think 'final' is still there... I won't get a chance.
SCJP 5.0 SCWCD 5.0
avi sinha wrote:Well, I just wanted to add a 'can be true' scenario to make it more clear.
![]()
Jeff Verdegan wrote:
avi sinha wrote:Well, I just wanted to add a 'can be true' scenario to make it more clear.
![]()
Fair enough.
I probably would have couched it in a more cautionary sense though, along the lines of "While you may sometimes see == giving true for Strings, that's a side-effect of the constant pool. It sometimes misleads people into thinking you can compare Strings with ==, but just like with any other class, you need to use equals() for comparing Strings' contents."
. I wanted the guy to do some research on it.analyze these lines:
SCJP 5.0 SCWCD 5.0
There was a very useful JavaRanch journal article which explains that problem.Mario Skrlec wrote: . . . . . .
Rajat Jindal wrote:If you are coming from C background, please try to learn first OOPS concepts and then try to implement those in your programs.
Once you are done with this try to learn what features Java provides and what exactly an API is, so that instead of implementing your logic you reuse the Java API.
I would refer some of the books to you:-
1. Core Java volume 1 ( 8th Edition ) by Cay Horstmann.
2. Thinking in java 3rd edition or 4th edition by Bruce eckel.
3. A Programmer's Guide to Java SCJP Certification: A Comprehensive Primer, third edition by Khalid Mughal
4. Just Java 2, sixth edition by Peter van Der Linden.
For a complete beginner I would recommend
1. Core Java volume 1 ( 8th Edition ) by Cay Horstmann.
Happy Learning
This is my favorite show. And this is my favorite tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|