Help coderanch get a
new server
by contributing to the fundraiser

vikram choudhary .

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

Recent posts by vikram choudhary .

non-generic collection always compiles with warning ?
is it correct?


Above code compiles without warning why?
can any one explain?
import java.io.Serializable;
class Animal{

}
class Dog extends Animal{

}
class NewClass {
public static void main(String... a) {

Dog[] dogs=new Dog[10];
Animal[] animals=new Animal[10];
animals=dogs;
animals[0]=new Animal(); // ArrayStoreException
Animal m=new Dog();
m=new Animal();// No Exception


}
}

pls explain?
hi,


i think, this code will throw java.lang.IllegalMonitorStateException: not IllegalStateException ...
see, there are two things thread of execution and thread object having 1-1 mapping.
A thread object is just like other java objects so it also has a lock and any thread can acquire it.but remember, a thread of execution never hold the lock of its thread object but it can acquire by calling synchronized block or method.
that is the reason sometimes, run() is made synchronized.

so in the above code,
the current thread (means,thread of execution) will try to acquire the lock of
current thread (here, it is thread object) which is available. so no,
IllegalStateException.
but in the synchronized block you are calling wait on obj object whose lock is not acquired by thread(thread of execution) and throws IllegalMonitorStateException.

Am i right?
regards,
Vikram
preparing for scjp1.5
byte i= (byte)129;
System.out.println(i);

output: -127 why?
can anyone explain?
[ April 25, 2007: Message edited by: Barry Gaunt ]
byte i= (byte)129;
System.out.println(i);

output: -127 why?
can anyone explain?
JVM has constant pool of string objects.that's why
"Java"=="Java" always evaluates to true.
is the same case with wrapper objects?
Integer i=3;
Integer j=3;
i==j ?