« first day (3424 days earlier)      last day (1741 days later) » 

00:00
Those who do not understand Unix are condemned to reinvent it, poorly. - Henry Spencer, University of Toronto Unix hack (source)
 
1 hour later…
01:04
farts
 
6 hours later…
07:04
dreams of electric sheep
 
1 hour later…
08:34
hi guyes.. have some question... what is the difference between 1) String a = new String("a") 2) String a = new String("a").intern() ?
i guess, in this case, 1),2) create 2 objects. so there is no difference unless i add additional line for 2) that String c=new String("a").intern();
is my understanding correct?
08:57
@Energy doing `new String("blah")` is taboo since the JVM provides interned strings with literals. That's why you'd find almost all code using literals instead of invoking the String constructor. You only need to invoke `new String(someString)` if you need an explicit copy of `someString`.

Consider this:

```lang:java
String a = "someString"; // new object and interned on the JVM heap
String c = "someString"; // interned to the same object as 'a' above. No new object.
String myCopy = new String(a); // creates an explicit copy of 'a' on the JVM heap
Hmmm, I can't markdown
understand ur point. but i am asking u this cuz got this question on interview. and drive me crazy
So, if you do:

String someString = new String(a).intern()

It is the same thing as doing:

String someString = "someString";

No new String object is created on the heap
ok how about this. String aa1=new String("test1"); //=> 2 obj are created?
@S.R.I String aa1=new String("test1").intern(); // 1 obj created? or how many obj will created?
if intern() is just same as String someString = "someString"; => means 1 obj will created? in string pool?
With:

String aa1 = new String("test1"); // new object is created
String aa1 = new String("test1").intern(); // new object is created only if it does not already exist on the heap
@Energy correct
ok. thanks for confirming . how about String aa1=new String("test1"); //=> 2 obj are created? (1 in string pool/ the other in heap ) . am i correct?
@S.R.I last question... String aa1=new String("test1"); // 2 obj?
String aa3 = new String("test1").intern(); // only reference is created as test1 alredy exist in string pool
09:09
@Energy The JVM specification on this topic here: docs.oracle.com/javase/specs/jvms/se7/html/jvms-5.html#jvms-5.1
The exact quote:

> A string literal is a reference to an instance of class String, and is derived from a CONSTANT_String_info structure (§4.4.3) in the binary representation of a class or interface. The CONSTANT_String_info structure gives the sequence of Unicode code points constituting the string literal.

> The Java programming language requires that identical string literals (that is, literals that contain the same sequence of code points) must refer to the same instance of class String (JLS §3.10.5). In addition, if the method String.intern is called on any string, the result is a ref
@Energy This String interning is also what enables you to directly do the '==' comparison. You can see that for yourself here
`public class StringsTest {
public static void main(String[] args) {
String s = "someString";
String s1 = new String(s);
System.out.println(s == s1); // false
String s2 = new String(s).intern();
System.out.println(s == s2); // true

String s3 = new String("someString");
String s4 = new String("someString").intern();
System.out.println(s == s3); // false
System.out.println(s == s4); // true
}
}`
@S.R.I Thanks! got it.
09:25
Heh. I came here to ask a question and found an answer myself, while I found myself answering something else! Who knew programmers multitask all day?!?!?

And @Energy, you're welcome and I'm glad it helped.
@S.R.I lol congrats thanks><!
@Energy :-) good luck in your interviews!
 
6 hours later…
15:32
farts
 
3 hours later…
18:05
@Michael wat?
Always @Gabriel14! Ideally you ask your question directly instead of asking to ask. Especially for lurkers it's more likely you will get someone to answer a question about programming instead of a question about asking about programming :)
@S.R.I just for future reference, you can format a full message as code by pressing Ctrl+K prior to sending. Code-fence markup doesn't work in chat unfortunately.
 
1 hour later…
19:24
@geisterfurz007 You heard me.
20:07
Is it possible to pass an instance of a class from a servlet to a jsp? I have a shopping cart instance I would love to put on a jsp page to show the cart.
@user6274491 Welcome to the Java Chat, the room for Java enthusiasts! I'm Oak, one of the room's bots. If you want to ask a question, just ask it and someone will respond if they feel like it. But remember that this room is not a help desk or tutoring service! If you want to just hang out, then welcome aboard! Oh, and the room's full list of rules are posted here.
 
2 hours later…
22:15
@geisterfurz007 Ah, thanks!

« first day (3424 days earlier)      last day (1741 days later) »