Originally posted by Usha Vydyanathan:
Hi,
I thought if a statement is unreachable Java always gives error.
Following code compiles fine eventhough "System.out.println("After stop method");" is not reachable because thread will stop before that.
public class Q1 extends Thread
{
public void run()
{
System.out.println("Before start method");
this.stop();
System.out.println("After stop method");
}
public static void main(String[] args)
{
Q1 a = new Q1();
a.start();
}
}
Can any one explain? Thanks in advance.
regards,
Usha
Originally posted by Tanveer Mehmood:
Hi all,
Is there any difference b/w the following three options, in a situation where you've to select 2 correct out of 3.
1. 16 >> 2;
2. 16 >>> 2;
3. 16/2^2;
Well one difference could be that first two are acceptable to compiler while third one not. But there is hardly any other difference I think....
Tanveer
Originally posted by sachin kumar:
hi every one !
i am sachin . i am little bit confused about the throw and throws concept and really not finding its solution if any one of you could help me out it will be a great help of mine
Originally posted by sridhar mon:
Hi all,
I see all the stuff that flow in at this board, but afterall what amI going to get after I get certified, Iam getting some confidence on my skills, but wherever I go they ask for experiance, but where do i pluck the experiance from , I do need to start from somewhere, but where...
Iam dippressed and adding to that the current situation of industry, at this junction how is the scjp going to help me ???
somebody please answer to my first writing here.
Thanking you.
[Also hey how do you get all those little images in all the posts]
Originally posted by bill bozeman:
For the first one, try to remember this:
if you compare to NaN values with == it will return false, if you compare them with equals it will return true.
if you compare -0.0 to 0.0 with == it will return true, if you compare them with equals it will return false.
The way I have remembered this, is 0.0 is a number and if you were to type in the numbers with == then it would work and return true. NaN is not a number, so I treat it like an object, so == will return false. Then I just remember that the opposite is true for the other scenerios involving equals() method. Tricky, but one of those things you just have to memorize.
Bill
Originally posted by Shah Chunky:
Hi All...
Can someone answer the following 2 Cases :-
Case 1:-
Object o = new Object();
Object x = o;
o = null;
Will the Object o eligible for garbage Collection ?
Case 2:-
Object o = new Object();
Object x = o;
x = null;
"Will the Object x eligible for garbage Collection ?"
Thanks */
Originally posted by Tanveer Mehmood:
Which checkboxes will initially be selected when the following program is run?
import java.awt.*;
public class TestClass extends Frame
{
TestClass( )
{
setLayout(new FlowLayout());
CheckboxGroup[] cbgs = new CheckboxGroup[] { new CheckboxGroup(), new CheckboxGroup()};
for (int i=0; i<5; i++) add( new Checkbox("Checkbox"+i, true, cbgs[i%2] ) ); //1
setSize(300, 300);
setVisible(true);
}
public static void main(String[ ] args)
{
new TestClass();
}
}
It says that checkboxes 3 and 4.
But I think that at line marked 1 when it will calculate cbgs[i%2] in its fourth iteration, program should throw an ArrayIndexOutOfBoundsException as result will be 2.
Correct me if wrong.
Tanveer
Originally posted by William Brogden:
"I would expect a runtime exception here since the value range for a byte type can only be -128 thru 127."
Java does no checks for runtime math overflows such as the one you suggest. Right off-hand, the only Exception I can think of that you can get with primitive math is ArithmeticException due to integer divide by zero.
Bill
Originally posted by Tanveer Mehmood:
Consider the following lines of code...
1. public void method( )
{
2. String a,b;
3. a=new String("hello world");
4. b=new String("good bye");
5. System.out.println(a+b+" ! ");
6. a=null;
7. a=b;
8. System.out.println(a);
}
In the absence of compiler optimization, after which earliest line the object a is definitely eligible to be garbage collected?
(Do not add spaces or dots. Just type in the number.)
Now this one says Line number 6, why not 8.
Originally posted by Tanveer Mehmood:
Question ID :952739440490
Which of the following statements can be inserted sucessfully at // 1?
public class InitTest
{
static int si = 10;
int i;
final boolean bool;
// 1
}
Now 2 of the 5 options given are.
1. {i = 1000;}
2. { bool = (s1>5); i = 1000;}
Why not both??? why only 2???
Tanveer
Originally posted by vijay malhotra:
How I calculated the value of i to be 1
is that
i = i++-i;
with in this expreession (i++-i) the value
of i will remain 0 because here the post fix
operator ++ is used and according to post fix
operator's behaviour the value of i will become 1
only after the expression i++-i is completed.
so the values would be
i = 0++-0;
only after this expression is completed the
value of i will be incremented by 1.
I also performed similar calculation in C++
and the answer was 1.
Do the precedence rules of Java differ from that
of C++ or C ?Why there is difference between the
behaviour of the same proogram when run on C++ and Java.
According to my knowledge when the post fix operator
is used the old value is used with in the expression
and only after the completion of expression the value
is incremented.
Please explain ?