Kayalvizhi Umashankar

Greenhorn
+ Follow
since Aug 04, 2005
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 Kayalvizhi Umashankar

Hi all,

I passed SCJP 1.4 exam with a score of 95%. This site helped me a lot in my preparation. Thanks a lot to all those out there.

I felt that the exam was easy (tricky ofcourse). Dan's and Marcus Green's mock exams are very helpful.

Marcus mock exam is close to the real exam whereas Dan's is bit hard but makes you understand the concepts well.

Regards
Kayal
18 years ago
class TestClass6 extends Thread
{
public static void main(String[] args)
{
TestClass6 j1 = new TestClass6();
j1.setName("one");
j1.start();

System.out.println(j1.getName()+" : "+j1.isAlive());

try
{
j1.join();
}catch(InterruptedException e) {}

System.out.println(j1.getName()+" : "+j1.isAlive()); //Showing false -- ie j1 thread has finished executing run()....ie j1 is dead

j1.start(); // trying to restart j1

System.out.println(j1.getName()+" : "+j1.isAlive()); //showing true -- ie j1 is alive (how??)

}

public void run()
{
for(int i = 0; i < 5; i++)
System.out.println(Thread.currentThread().getName()+" Running");
}
}

The above code executes fine even though the thread is started after its dead. How come?

Also when i remove the try block then it throws IllegalThreadStateException.

Please explain.

(I searched if this was asked before without success. So had to post again)

Thanks in advance
Kayal
In real exam after answering all questions, what if i want to review my answers for all.
Do i have to check the "Mark/Review" button in order to go back to those questions orelse is it ok to use the back button in the applet window.

Please reply

Thanks in advance
Kayal
Easy way to compute that would be by applying the formula (n)(n+1)/2.

Kayal
The output is like that because the methods m2() and m3() are invoked on the instance a1 whose name is "A0".

Kayal
Please explain the following

1. When i give

Integer i = new Integer(10);
Integer i1 = new Integer(10);
System.out.println(i.toString() == i1.toString());

Output is true

2. When i give

Integer i = new Integer(11);
Integer i1 = new Integer(11);
System.out.println(i.toString() == i1.toString());

Output is false

How come?


Kayal
Its neither overriding or overloading. Its a new method by itself in the sub-class

Kayal
Believe me I had no idea that what i possess is illegal. All the while i thought its some documentation that was downloaded from internet (for free ofcourse).

But when i saw some posts with questions mentioned as from K&B book, it looked similar to what I had in my documents. And thats why i posted to get to know.

I didn't mean to hurt anyone and i am sorry if i have offended anyone unknowingly

Kayal
I posted a question about K&B Book and its not listed.

Any idea why?

Kayal
Exception is raised due to "String s4= args[4];".

In the input given there are 4 elements. As the array index starts from 0, the last element is args[3].

Kayal
class A9o extends Thread
{
String[] sa;
public A9o(String[] sa) {this.sa = sa;}
public void run()
{
synchronized (sa)
{
System.out.print(sa[0] + sa[1] + sa[2]);
}
}
}

class TestCalss5
{
private static String[] sa = new String[]{"X","Y","Z"};
public static void main (String[] args)
{
synchronized (sa)
{
A9o t1 = new A9o(sa); t1.start();
try{t1.join(900);} catch(InterruptedException e){}
sa[0] = "A"; sa[1] = "B"; sa[2] = "C";
}
}
}

In the above code, when the either of the synchronized statements are removed then the output is "XYZ" orelse "ABC".

Please explain.

Thanks in advance

Kayal
If you are refering to the comment portion, yes i understand that.

But i meant why
String d = "\u000d"
this line results in a compile time error

Kayal
class A {
public static void main (String[] args) {
String a = "\n"; // 1
String b = "\r"; // 2
String c = "\n"; // 3 \u000a = new line
String d = "\u000d"; // 4 \u000d = return
}}

Can anyone please explain why line 4 will result in a compile time error?

Thanks in advance

Kayal
Thanks Santana for the awesome reply.


Kayal