sandeep bagati

Ranch Hand
+ Follow
since Feb 22, 2001
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 sandeep bagati

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


It is a good question .Yah if u are not using threads u get definitely a compile-time Objection to the code for java doesn't allow redundant code but in case of a thread when u say stop the thread is nomore in running state and hence the code after that doesnt matter.
A little change in yr program can help u in understanding better
public class Q111 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)
{
Q111 a = new Q111();
a.start();

Thread.currentThread().stop();//(1)
System.out.println("After stop in main");(2)
}
Now after line marked (1) the code doesnt execute and doesnt
give compile-time error also.Now if u remove (1)(2) will get executed and After stop in main printed.Here it is not unreachable code rather u can say that the code after the stop is not consudered at all while in case of an unreachable statement like
while(false){
System.out.println("After stop in main");
}
thread that is executing this statement is running while it is programming error because of which a redundant code is found in the running thread and as i said java takes it as a compile-time
error.
Hope that i am right.
sandeep

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


hi tanveer
congrats tanveer!!!But i fear u have made this mistake in the test.
first two will result in 8 & 8(divide by 2) while last one 10

[This message has been edited by sandeep bagati (edited April 21, 2001).]

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


It will be better if u refer some good book .Khalid Mughal has explained it in a very proper way.
In simple words i can tell u that u throw an Exception Object using throw and throws is used with a function to indicate that a Exception may be thrown by a function.
Now say u have got 1/0 in yr code
That is equvialent to
throw new ArithmeticException();
And if u want to tell the user about a function f() in which there is possibility of 1/0 u write
f() throws ArithmeticException{}
sandeep

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]


Hi
I think Certification in java doesnt really make sure that u get a job .But one thing u really achieve is a hold over the basics of Java and that really helps a lot in understanding advanced Java and may be some other language concepts.
As for job is concerned hay u got to be more optimisstic for everybody gets chances in life and u should be in position to avail of those.
Certification brings confidence not only in U butalso the Employeer about his new Employee.So go for it
With best wishes
sandeep

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


The reply to question seems to be a good way to remember the answer.But to understand it why it really happens is to just understand what NAN is actually.It is pure mathematics(with a little difference).NAN in JAVA is introduced to take care of things like 0.0/0.0,infinity*0.0.Now suppose that NAN==NAN
then
1.0/0.0*0.0==2.0/0.0*0.0
i:e POSITIVE_INFINITY*0.0(NAN)==POSITIVE_INFINITY*0.0(NAN)
BUT that means 1.0=2.0
which is ridiculos.
Now where the difference lies
1.0/0.0*0.0==1.0/0.0*0.0
where NAN doesnt work.JAVA takes result as not equal.
There is some logic behind everything and where logic can not be applied it is then yr wish
I hope that helps
sandeep


[This message has been edited by sandeep bagati (edited April 21, 2001).]
I am not able to understand the following statement from W3C XmL doc.
The standalone document declaration must have the value "no" if
"any external markup declarations contain declaration ofd element types with element content,if white space occurs directly within any instance of those types"
Can anybody please explain?
Thanks,
sandeep
GC

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 */


Sorry Shah the statement "Will the Object x eligible for garbage Collection ?" should be "Will the Object pointed/referenced by x/o etc eligible for garbage Collection ?" and also line no of the object u are referring to should be mentioned.
Now an Object can not be used by u anymore after u are not able to handle it.Since in java only through references u can work with an object so when there is no references to an obj it is elegible for GC(free the space of thing of no utility)
In both case u are making two references of the Object in line no 1 and line 2 so even after u change the(only) object reffered by one of the references it is not going to be garbage collected unless it also loses the other reference
sandeep
I may add a thing here Super will always be called if there is a default constructor in Immediate top class and there is no explicit super(parameters) call in the derived class.If there is no default constructor in yr super class relying on an implicit call to a constructor super() that doesnt exist will result in a compile time error!!!
thanks jane.
Yah u are right and i have read that part of JLS.But using i++ operator with a byte it works as i have said above.I forgot to tell for the Integer though u get the same result i:e truncation occurs but i suppose here the addition is done at integer level only and then the trunction of the long to integer while in case of byte first the byte is converted to int then the addition and then truncation to byte occurs.
that is why byte=byte + 1 gives a compile time error and not int=int+1 whatever the corresponding int or byte value is
Do correct me if i am wrong.
sandeep
[This message has been edited by sandeep bagati (edited April 14, 2001).]
Hi
I dont have much XML experience.A little practical experience and a somewhat bookish knowledge.But I am really Confused about the things for I have been reading Professional XMlL and also XML by ExAMPLE.Are these books sufficient for clearing the IBM test or do i need to read something more.And which topics i should read and practice in detail and which ones i can just go through once
Thanks a lot
sandeep

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


Sorry tanveer u are making a mistake.AnyNumber%2 will result in either 1 or 0.I hope now u will get it for there will now just be two and in this case the last two checkboxes added which will be selected.
If u have still have got any doubt do tell
sandeep

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


I didnt get u Bill .Can u please clarify???

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.


To answer such qs is quite easy.Just look at the references of the object about which the question has been asked.Now in java U dont have Pointers so u only have got references to manipulate an objec.NOw when there is no reference pointing to an Object it is lost and hence elligble for GARBAGE COLLECTION.
I hope that is sufficient.
Yah one more thing when u say
ref x=null;
U mean to say it is not pointing to any object And if x had been initially pointing to some Object say x=new A() after the statement x=null; it doesnt point to anything and hence this reference of A is lost.
sandeep

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


Hi Tanveer
Final Blank vriables need to be initialised before the end of class or interface in which they are defined.And yah u cannot change that value.I think that is sufficient to clear yr doubt
sandeep

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 ?


as for as i remember it is compiler dependent in c/c++
i++ and ++i are compiler dependent in c/c++ and the rules too vary.