News for hackers. Stuff that matters.
Re:Out of My Depth by pjungwir on Thursday April 25, 2013 @12:05PM (#5607971)
What is the difference between a string and a String? I've written Java for 15 years, and I've never heard of a lowercase-s string before.
Re:Out of My Depth by mbrameld on Thursday April 25, 2013 @02:50PM (#5609124)
You probably know this, but I think the author is confusing a string literal with a lowercase string.

String a = "hello";

String b = "hello";

a == b will evaluate to true.

String a = new String("hello");

String b = new String("hello");

a == b will evaluate to false.

String literals in Java are put in to a string "heap" (might not be the correct word) and reused. Strings objects create a new instance for each string.

Re:Out of My Depth by eterm on Thursday April 25, 2013 @12:49PM (#5608278)
Maybe he's anonymised his experience slightly by subbing Java for C#: C# has a string and a String, although string is just an alias to System.String, so they're really the same.

It's not terribly confusing, although syntax highlighters do treat them differently which I could see could confuse the uninitiated.

Re:Out of My Depth by dexen on Thursday April 25, 2013 @12:30PM (#5608141)
It seems there isn't. There is only one `String' datatype in Java, instance of class String, and no primivite `string' type. String literals represent instances of class String, as per http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#...

Perhaps author meant JavaScript, which does have primitive `string' type, distinct from instances of class `String'?

Re:Out of My Depth by jakejake on Thursday April 25, 2013 @02:12PM (#5608874)
Maybe the answer is that String is a class and string has no special meaning in Java?

It could be that the author was shown a bit of code where an instance of a String was called string (I've seen this many times as an argument name especially in methods for converting or manipulating a String value). But since the code wasn't mentioned we have no idea,

Seems like a nasty trick question to ask of an intern who doesn't know Java!

Re:Out of My Depth by pjungwir on Thursday April 25, 2013 @06:52PM (#5610468)
I agree if it was asked with no context ("What's the difference between String and string?"), I wouldn't be sure how to answer either! (But in the OP, wasn't it the author who asked the question?)

It reminds me of an interview question I was asked once (thought not as bad as String/string): "What is the time complexity to print every node in a binary tree?"

Re:Out of My Depth by RossM on Thursday April 25, 2013 @12:20PM (#5608059)
It's been a while since I worked on some Java but I believe it has something to do with one being a type (like int) and the other being an instance of the class String. I was always taught "just use String" but I'd love to know the real difference.

Google is not proving fruitful for this question.

Re:Out of My Depth by vanderZwan on Thursday April 25, 2013 @12:13PM (#5608019)
Maybe somebody named his String variable string?
Re:Out of My Depth by pjungwir on Thursday April 25, 2013 @12:36PM (#5608187)
I think this is probably it. It's the only thing I can think of.
Re:Out of My Depth by lkrubner on Thursday April 25, 2013 @01:53PM (#5608751)
Someone should be shot.
Re:Out of My Depth by vineel on Thursday April 25, 2013 @12:28PM (#5608126)
Yeah, I don't think "string" is a thing in Java. Maybe he was comparing it to a data type from another language?
Re:Out of My Depth by wasd on Thursday April 25, 2013 @12:32PM (#5608154)
He might be referring to Integer versus int and Long versus long.
Re:Out of My Depth by johnnyg on Thursday April 25, 2013 @12:11PM (#5608004)
I scrolled to the comments section of this article looking for exactly that! Do tell!