Arnab Saha

Greenhorn
+ Follow
since Nov 08, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Arnab Saha

Thanks to all the members of the forum for your invaluable feedbacks.
19 years ago
Can anyone tell what this method does?
where can I get a description of this method?
I want to know that if during Test of SCJP 1.4 if nothing is mentioned
what should we consider - Assertions enabled or Disabled.
What should be the o/p:
public class Test {
public static void main(String[] args) {
int x = 0;
assert (x > 0): �assertion failed�;
System.out.println(�finished�);
}
}
Ans: Assertion thrown,or "finished".
If nothing is mentioned should we consider Assertion is disabled.
Have a look at this code -
class BeautyThread {
public static void main(String [] args) {
ThreadB b = new ThreadB();
b.start();

synchronized(b) {
try {
System.out.println("Waiting for b to complete...");
//b.wait();
Thread.sleep(0);
} catch (InterruptedException e) {}
}
System.out.println("Total is: " + b.total);
}
}

class ThreadB extends Thread {
int total;

public void run() {
synchronized(this) {
System.out.println("Hi");
for(int i=0;i<100;i++) {
total += i;
}
notify();
}
}

}
o/p is
Waiting for b to complete...
Hi
Total is: 4950

Why does the main thread releases lock at //b.wait();
Please have a look at the code:

public class A extends Thread {
A() {
setDaemon(true);
}

public void run() {
(new B()).start();
try {
Thread.sleep(60000);
} catch (InterruptedException x) {}
System.out.println("A done");
}

class B extends Thread {
public void run() {
try {
Thread.sleep(60000);
} catch (InterruptedException x) {}
System.out.println("B done");
}
}

public static void main(String[] args) {
(new A()).start();
}
}
*************
No o/p is printed

But if in the sleep calls 60000 is replaced by 10
We get:
A done
B done.
Can u explain it?
setDaemon(true);
What does this statement do in Multithreading scenario.
Yes I have tested that if in catch block Unchecked exceptions(like ArithmeticException)are given then there is no problem.
But Exception is Super class of Unchecked Exceptions.
So,like checked exceptions it should also generate error.
Have a look at this code:
try {
//Thread.sleep(600);
} catch (InterruptedException x) {}
It gives compilation error as:
exception java.lang.InterruptedException is never thrown in body of corresponding try statement.

But,
try {
//Thread.sleep(600);
} catch (Exception x) {} // This one gives no error.
Why is this so?
Why is it so?
Float f1 = new Float(1.24); //Gives no compilation error

while,
String s1 = Float.toString(1.24);//Gives compilation error

Are there other situations for Wrapper classes where there is
like this anomally.Please let me know.