Thiru Mu

Greenhorn
+ Follow
since Aug 30, 2007
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 Thiru Mu

Hi,

Thanks to all.

I have just gone through HF book, practiced all the topics and worked out Mock exams in HF as well as some Mocks in Internet.
13 years ago
Hi Friends,
I am glad to inform You that I have cleared SCWCD with 92% of score.
Thanks to HF Book and Java Ranch.

Thanks
ThiruMu
13 years ago
Hi

Get Head First Book... its excellent for SCWCD preperation.
I have cleared the exam 31 dec. I read only Head First BOok..
How can I write a class, so that only one object can be created for the class?
when we say

int[][] array = new int[2][2];

how many objects are created on the heap?
[ September 10, 2007: Message edited by: Thiru Mu ]
hey
this is indeed a good question and answers with explanation.
excellent...
hi

Objects can be created using only 'new'

so no confusion the object cunt here is 2....

correct me if i am wrong..
cool..this is what i was expecting...
It was given wrong in the question i have refered..
Greg,

if("String".replace('g','G') == "String".replace('g','G'))
System.out.println("Equal");
else
System.out.println("Not Equal");

if("String".substring(2,4) == "String".substring(2,4))
System.out.println("Equal");
else
System.out.println("Not Equal");


if("String".concat("s") == "String".concat("s"))
System.out.println("Equal");
else
System.out.println("Not Equal");

if("String ".trim() == "String ".trim() )
System.out.println("Equal");
else
System.out.println("Not Equal");


I ahve tested all the above, all prints "Not Equal" so it means, the methods substring,replace, trim and concat are creating new instances behind the scenes!

Is this seem good?
Hi Praveen,
In my evaluation, I see the same .

here is the explanation,

class C
{
public static void main(String a[])
{
C c1=new C(); // OBJONE: here object OBJONE is getting created
C c2=m1(c1); // here c2 refers OBJTWO
C c3=new C(); //OBJTHREE: ct is created
c2=c3; //6 // c2 now refers OBJTHREE
anothermethod();
}
static C m1(C ob1){ // ob1 refers to OBJONE
ob1 =new C(); //now ob1 is refering a new object say OBJTWO
return ob1; // OBJTWO is returned

}
}

so at the line 6, c1 refers OBJONE , nothing refers OBJTWO because ob1 is a method local variable, and its life time is only when the method is getting executed..so OBJTWO is eligible for GC,
OBJTHREE is referenced by C2 C3.

am i right praveen? Please give your explanation.
[ September 06, 2007: Message edited by: Thiru Mu ]
StringBuffer s1 = new StringBuffer("abc");
StringBuffer s2 = s1;
StringBuffer s3 = new StringBuffer("abc");
How many objects are created ?
Can any one explain the code below, The answer is 2
class C
{
public static void main(String a[])
{
C c1=new C();
C c2=m1(c1);
C c3=new C();
c2=c3; //6
anothermethod();
}
static C m1(C ob1){
ob1 =new C();
return ob1;
}
} After line 6, how many objects are eligible for garbage collection?
[ September 06, 2007: Message edited by: Thiru Mu ]
Hi,

I dont think String objects are stored in the pool. It is stored only in heap.

Also String objects are eligible for garbage collection not the litterls..please correct me if i am wrong..
[ September 04, 2007: Message edited by: Thiru Mu ]
Yes you are right,
at a point, b's value will be 127 and when it still do ++b it will become
-128, which is less than 0, so the wilhe loop quits and prints the text.