Nishu Batra

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

Recent posts by Nishu Batra

Thanks for the reply what if you get (byte)25546. Then what do we do?
class E {
static byte a = (byte)127;
static byte b = (byte)128;
static byte c = (byte)255;
static byte d = (byte)256;
public static void main(String args[]) {
System.out.print(a + " " + b + " " + c + " " + d);
}
}
Output is
127, -128, -1 and 0
I understand 127 because its a byte's limit.
I understand (byte) 256 that would be 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0.
This would give you zero when you convert it to byte.
But 128 would be 1 0 0 0 0 0 0 0. Now 2's complemet of this would be
of this would give again 1 0 0 0 0 0 0 0 which again is -128. (Is this correct?).
Now 255 in eight bits would be 1 1 1 1 1 1 1 1. 2's complement of this would give me 1 0 0 0 0 0 0 1 and this is -1. Am I correct. Please let me know.
Thanks,
Congratulations Gaurav. Job Well done. Thanks for all your tips. I am newbie trying to learn here. Am preparing hopefully would be appearing for the exam in a month or so hopefully sooner. Looking at all the posts makes me feel better. But fingers crossed. Will keep everyone informed and contributing.
Do you have any other suggestions for someone just starting to prepare for the exam.
Please let us know.
--Thanks
21 years ago
I recently started preparing for this exam. I had only read Passes of SCJP's. This is the first person I am hearing who hasn't cleared it. Honestly it inspires me. I was at an information session a few days ago where they talked about failure of Erik Peterson (who the hell is he??). He was a Harvard Business School Graduate an A1 student. He started working as a manager in a cellular communication company. He failed miserably as a Manager and eventually was fired from his job. This is one of the first cases they teach at Harvard and at other business schools.
Bottom line of this case is you can do what ever you want to, but you can still fail, because you can't be overconfident and that is what I was becoming after reading all these success stories here as in its going to be easy.
And the reason they teach this course at Harvard is because you shouldn't be overconfident after graduating from Harvard there is always something you need to learn.
I want thank you for putting in this post, makes me and I hope lot of others work more harder.

I am pretty sure that you are going to do great in your next try, and for sure you are going to succeed.
21 years ago
Quick Question --
Where do you find Dan's exams?

Is it this?
Dan's Exam
Please let me know.
Thanks,
[ September 12, 2003: Message edited by: Nishu ]
Static methods --
Lets say for example we have the following class
class A(
int i ;
static int j ;
static {
j = 0;
}
void f1(){/*body of the method*/}
static void f2{/*body of static method*/}
}
Let take in two scenarios.
1. When no object of class A type is created (i.e. we don't have A a = new A()) and we have a call for A.f2().
In this scenario there is no i and there is no f1() which is created or called.
But since j is static and f2() is static method they would still exist. So that implies j is the only variable and f2() is the only method which can be used. At this moment static initializing block is also called (you can initialize in the declaration too).
2. When an object is created and initialized A a = new A().
In this case i and j would be available for a and function f1() and f2() would be available for a.
Another interesting situation here is which variables you can call in functions f1() and f2().
f1() can see both i and j since i is a normal variable and f1() method cannot be called without A be instantiated.
f2() can only call j because i might not be active yet since there might not be an object of A.
I hope this makes it a little clearer.
Uma is right about the answer.
Two things
default value of b is false.
(b = false ) would assign the value false to b and do a comparison if b is true or not. But since b was false it went to the next comparison.
now when (!b) is dealt with this condition is true and hence we get the output to be 'D'.
--nb--
Please refer to your other posting for the reply to the first question, which is correct.
Answer to Q1

For the second question, byte can take values from -128 to +127, how ever charcter conversion of negative numbers is not possible. So when you convert a negative number to a char you would get an undefined value. This should answer your question.
If you have any questions let us know.
Thanks,
--nb--