|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

05-09-2008, 07:38 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,294
|
|
Yep, normally called as unclosed character literal. 
So what is the different of,
System.out.println((String)"Java");
and,
System.out.println("Java");
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|

05-09-2008, 07:43 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
|
|
Originally Posted by Eranga
Yep, normally called as unclosed character literal. 
So what is the different of,
System.out.println((String)"Java");
and,
System.out.println("Java");
I think there is no such an difference
Eranga ......What about last ans
__________________
sanjeev,संजीव
|
|

05-09-2008, 07:57 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,294
|
|
Originally Posted by sanjeevtarar
I think there is no such an difference
There is no difference. Just casting confused. I see lots of time newbies confused on this. actually println() do all those things for you.
Originally Posted by sanjeevtarar
Eranga ......What about last ans
What you mean Sanjeev. I answered to it on post #101.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|

05-09-2008, 08:01 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
|
|
Originally Posted by Eranga
What you mean Sanjeev. I answered to it on post #101.
OK DEAR.............
moreeeeeeeeeeee......
__________________
sanjeev,संजीव
|
|

05-09-2008, 09:59 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 129
|
|
Oh Quiz Time
I AM BACK !!!
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-09-2008, 10:02 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 129
|
|
who is going to take the honor to sum up all the puzzles and there answer along with incorrect one as well as cool moments  of this thread ...
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-09-2008, 11:09 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,294
|
|
|
I don't think it's much better. We do this just to catchup something. Some answers are not given honestly, try to pointed something. Isn't it?
So it's better to keep going like this.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|

05-09-2008, 03:08 PM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 129
|
|
|
once againg STRING comaprison by ==
predict the output!! an as rule says, don't compile it just see and post the answer
package com.faaltu.Quiz;
public class StringInternTest {
public static void main(String[] args) {
String str1 = "string";
String str2 = new String("string");
String str3 = new String("string").intern();
if ( str1 == str2){
System.out.println("\nSAME");
}else{
System.out.println("\nNEAH");
}
if ( str1 == str3){
System.out.println("\nSAME");
}else{
System.out.println("\nNEAH");
}
if ( str2 == str3){
System.out.println("\nSAME");
}else{
System.out.println("\nNEAH");
}
}
}
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-09-2008, 03:14 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 221
|
|
|
Neah
Yeah
Yeah
__________________
Definition of Impossible = making a good game in Java.
|
|

05-09-2008, 03:15 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 221
|
|
|
How is mine two long it has everything you guys have talked about with objects , and then some so instead of posting 5 little ones I did one big one.
__________________
Definition of Impossible = making a good game in Java.
|
|

05-09-2008, 03:21 PM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 129
|
|
NEAH NEAH NEAH
You are wrong,
try again,
How is mine two long it has everything you guys have talked about with objects , and then some so instead of posting 5 little ones I did one big one.
My friend as said already, keep only the catchy part! that puzzle looks lika an essay 
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
Last edited by rjuyal : 05-12-2008 at 06:52 PM.
Reason: PHP code should not be used ;) for Simple quote
|
|

05-09-2008, 03:46 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
|
|
|
Is it correct?
NEAH
SAME
NEAH
__________________
sanjeev,संजीव
|
|

05-09-2008, 03:58 PM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 129
|
|
|
correct
Thts Right Sanjeev,
What's the answer of this:-
package com.faaltu.Quiz;
one more
public class StringInternTest {
public static void main(String[] args) {
String str1 = "string";
String str2 = new String("string").intern();
String str3 = new String("string").intern();
if ( str1 == str2){
System.out.println("\nSAME");
}else{
System.out.println("\nNEAH");
}
if ( str1 == str3){
System.out.println("\nSAME");
}else{
System.out.println("\nNEAH");
}
if ( str2 == str3){
System.out.println("\nSAME");
}else{
System.out.println("\nNEAH");
}
}
}
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-09-2008, 04:00 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
|
|
Originally Posted by rjuyal
Thts Right Sanjeev,
What's the answer of this:-
package com.faaltu.Quiz;
one more
public class StringInternTest {
public static void main(String[] args) {
String str1 = "string";
String str2 = new String("string").intern();
String str3 = new String("string").intern();
if ( str1 == str2){
System.out.println("\nSAME");
}else{
System.out.println("\nNEAH");
}
if ( str1 == str3){
System.out.println("\nSAME");
}else{
System.out.println("\nNEAH");
}
if ( str2 == str3){
System.out.println("\nSAME");
}else{
System.out.println("\nNEAH");
}
}
}
SAME
SAME
SAME
because you are using intern()........which causes new String object to point existing one if any exist.
__________________
sanjeev,संजीव
|
|

05-09-2008, 04:50 PM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 129
|
|
es el correcto!
next puzzle please
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-12-2008, 04:32 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,294
|
|
Hi, guys. I'm back here. 
I would like to make a request from all of you guys. Please don't use PHP tags when posting codes or quotes in forums. It's make the browser keep too wide on the scree. 
Thanks
Eranga
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|

05-12-2008, 06:51 PM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 129
|
|
|
Another Quiz: Constructor Vs Parsing
package com.faaltu.temp;
public class IntegerTest {
public static void main(String[] args) {
System.out.println("constructor: " + new Integer("hello"));
System.out.println("parsing: " + Integer.parseInt("hello"));
}
}
what will be the output?
and as the rule say "Don't compile it, just read and try to answer"!!
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-13-2008, 04:55 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,294
|
|
Ah, I caught you 
You comes with NumberFormatException. Required a integer value, but found a String object there in the second println().
Actually you need a String there. But it should be containing an int representation.
Is that my explanation is ok?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|

05-13-2008, 08:05 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 22
|
|
|
LOL, still waiting eh?
I think it would print "no" because == compares objects and the two strings are actually different objects with identical values under the hood.
|
|

05-13-2008, 08:14 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,294
|
|
|
On which question are you talking about?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
| | |