aabir sanyal

Greenhorn
+ Follow
since Jun 22, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by aabir sanyal

congratulations friend, java rocks
14 years ago


How many String objects are created?

Source: Self

Alfred Swensen wrote:Hello

I've just tried the free mock exam on http://www.sun.com/training/certification/assessment/055.jsp
As I found it quite cumbersome to figure out which ones are wrong I post my answers below
(I doubt that posting answers without the questions violate any copyright whatsoever),

In page 2 SUN claimes one error. Do you find it?

In page 5 I only get 100% if I answer question 28 with b although it should be
d as the example code does not even compile due to a missing ")" and illegal "7.something();"?!

................



Are all these answers correct?
Anybody else taken this and the actual test please respond.

Bob Wheeler wrote:

aabir sanyal wrote:I am unable to get this, then what is the effect of i=i++;

Really confusing



check this out



Thanks Bob
I am unable to get this, then what is the effect of i=i++;

Really confusing
How is the FREE SUN PROFICIENCY TEST for Java 5?? Are the questions of the level of the actual SCJP 5 exam?


Update : Edited. Thanks for pointing

Cameron Wallace McKenzie wrote:A non-static method is an instance method. So, in order to invoke an instance method, you need an instance!

That's really the problem. Your error message probably said something about invoking an instance method in a static way or something like that.

Static methods bug me. They always stick to my clothes when I pull them out of the dryer.

-Cameron McKenzie



I hereby declare you my GURU

Ninad Kulkarni wrote:Hi Aakash,

Up cast means casting from sub class to super class
Down cast means casting from super class to sub class

Up casting happen automatically or you can do it manually.
Down casting happen only manually. You have to do it.




See comment at end of each line

Correct me if I am wrong




This will throw runtime ClassCastExceptions right??
//This works but
public class Test {
public static void main(String arguments[]) {
Test t = new Test();
t.amethod(arguments);
}
public void amethod(String[] arguments) {
System.out.println(arguments);
System.out.println(arguments[1]);
}
}



//This gives compile time error
public class Test {
public static void main(String arguments[]) {
amethod(arguments);
}
public void amethod(String[] arguments) {
System.out.println(arguments);
System.out.println(arguments[1]);
}
}

Somebody please explain.

Jesper Young wrote:Simple:

Keys in a map must be unique, that's why there can be only one entry in a map with the key null. Values do not need to be unique, so there can be multiple entries which have a non-null key and a null value.



it works yay

Ankit Garg wrote:If you've read K&B properly, then it is given that there is a pool of integer Wrapper objects in the range -128 to 127...



Please tell me the page number. I have the 1.5 book

Bob Wheeler wrote:

aabir sanyal wrote:Pondered on the question, and found that there are two objects created here (c1 and c2), whenever we call new. c3 doesn't create a new object.
Now according to Bob, Short is also creating an object. My question is how?? Because there is no constructor instantiating the Short object. Please explain a bit more.


Doesn't matter if it is in the constructor or not. It is declared and instantiated as an instance variable. But the point where I was wrong, it didn't create a new object, it created a new String Pool member. If the short value would be e.g. 200, than two objects would eligible for gc; this way only one.

cheers
Bob



What is the difference if Short is 5 or its 200??

Ankit Garg wrote:This question has incorrect answer in the book as far as I remember. It says that two objects will be eligible for GC but only 1 object will be eligible for GC and that is c1. The Short will be taken from the constant pool so it will not be eligible for GC...



1.) Short also has a constant pool??

2.) K&B please come to rescue

Venkata Saraswathi wrote:


I am assuming as above. Please any one can clarify?



As far as my understanding goes, no objects are created untill we use the keyworg new or use the method getInstance()...

only string literals are created and kept in the "String constant pool"..Please correct me if i am wrong