vinay jain

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

Recent posts by vinay jain

Hi Manfred
THANKS A LOT!!!. I was going crazy.
Vinay
23 years ago
Hello Everybody
Lets see if I can summarize the situation in few lines.
I have a JFrame with BorderLayout, In the SOUTH part of the FRAME I have a Panel with 4 buttons, I want to change the layout of CENTER Panel based on the button pressed in the SOUTH section. e.g. I might want to change the centerPanel from BorderLayout to GridLayout or something like that. I tried to do that but it is not working. I am posting the code below that I used. Please help me it is driving me nuts, not understanding why the code is behaving like it is.
Thanks

Results:
1. On initial screen if I press Next Button it works like it is suppose to.
2. If I press Previous button the centerPanel becomes blank. WHY??
3. If I press the next button after pressing previous button the centerPanel remains blank. WHY???
4. If I press prev, next, next then the second next makes the centerPanel like it is suppose to.
Help PLEASE!!!
Vinay
23 years ago
Hello Everybody
I recently cleared the Programmer Certification and I am thinking of giving the Web Component Developer Certification Exam. Please help me by telling what do I need to study for it and what are the recommended books/web sites/other resources please?
Thanks
Vinay


1. public class Note {
2. public static void main(String args[]) {
3. String name[] = {"Killer","Miller"};
4. String name0 = "Killer";
5. String name1 = "Miller";
6. swap(name0,name1);
7. System.out.println(name0 + "," + name1);
8. swap(name);
9. System.out.println(name[0] + "," + name[1]);
10. }
11. public static void swap(String name[]) {
12. String temp;
13. temp=name[0];
14. name[0]=name[1];
15. name[1]=temp;
16. }
17. public static void swap(String name0,String name1) {
18. String temp;
19. temp=name0;
20. name0=name1;
21. name1=temp;
22. }
23. } // end of Class Note


Lets see if I can explain:
Line 4 : name0 is a ref to object "Killer" in the memory
Line 5 : name1 is a ref to object "Miller" in the memory
On line 6 function swap(name0, name1) is called and inside function swap(name0, name1) we pass copies of name0 and name1
so now the object and ref looks like
Main.name0 --- "Killer"
/
swap.name0 ---
Main.name1 --- "Miller"
/
swap.name1 ---
Inside swap we changed the values of swap.name0 and swap.name1 and do not change the values of main.name0 and main.name1 so now at the end of the function swap the ref looks like
Main.name0 --- "Killer"
/
swap.name1 ---
Main.name1 --- "Miller"
/
swap.name0 ---
Notice that the main.name0 and main.name1 are not changed so on line 8 it prints "Killer", "Miller"
Now in case of the other swap function the reference inside the function looks like
main.name ----- {"Killer", "Miller"}
/
swap.name ----/
Notice that both references point to the same object so when you make the swap of swap.name[0] and swap.name[1] the array changes to {"Miller", "Killer"}
and hence the output on the line 9 "Killer", "Miller"
Vinay
Thanks for the explanation, that explains the first code very clearly but what about the second code, in that the value 123456789 is much less then Float.MAX_VALUE, why would that produce the difference. Also How would I find the max Integer value which can be converted to float without loosing some value in conversion?
Thanks
Vinay
Hi Mario
Have you ever find out about the Logo business? I have recently passed the exam and I would like to put the logo on my resume too. Any tips?
Thanks
Vinay
Hello Everybody
I just came back from giving the exam and I passed with 86%, I was hoping to get more but I guess I'll learn to live with it. I want to thank everyone at JavaRanch for helping me out whereever there were some doubts in my mind. Though I have not been with JavaRanch for long just about 2 weeks, I found the discussions here to be very useful. The Exam was quite tough, I was expecting some easy questions but almost all the questions required lot of thinking.
About the actual exams there were about 8-10 Questions on I/O and 5-6 on Threads, There were only about 2 questions from Collecitons. There were about 7-8 Questions about Inner Classes. There was one Q on GridbagLayout and 3-4 Questions total on AWT. There were about 3 questions on Events. Rest of the Questions were mainly sticking to Java Language Basics, there were about 7-8 Questions which were 20-25 lines of code most of the questions were 7-8 lines of code. Most of them were Single Choices. I found about 3 questions to be very ambiguous. Three were 2 questions on OO concept. There were 3 questions on bit operators and one on Operator Precedence. What else.... Well I can't think of other Questions at this time.
About my preparation I studied mainly from R/H/E and in the end Did a quick walkthrough from Khalid Azim Mughal & Rolf Rasmussen. I studied for about 2 weeks exclusively. I have 8 years of C++ background so OO concepts were easy to understand but I had some problems with the syntax and some basic concepts like booleans and integers are different, char can't be changed to short and vice versa, byte gets extended to int before any operation etc.
Thanks everyone.
Vinay Jain
23 years ago
Because C's base class i.e. B does not throw any exceptions so you can't throw any exception from class C.
Hello Everybody I have these 2 code segments which produce different results. Can anyone explain why?

On the other hand in this example

I am confused as why in first case the two integers are equal and not in the second case.
Another Suggestion which might be easier than the last one is use readUnsignedByte() to read your byte from the I/O port and then you can do all your shifting opoerations on them and convert them back to byte without a problem.
Hello Everybody
I am taking an exam tomarrow and want to ask one question, In the questions with multiple answers does the question tells you the number of correct choices or just says check all the correct answers as I have some confusion about that. Base on the mock exams on the net, some give you number of correct answers and some don't. If anybody can tell me I'll be very grateful.
Thanks
Vinay
23 years ago
<pre>
class Mammal{
void eat(Mammal m){
System.out.println("Mammal eats food");
}
}
class Cattle extends Mammal{
void eat(Cattle c){
System.out.println("Cattle eats hay");
}
}
class Horse extends Cattle{
void eat(Horse h){
System.out.println("Horse eats hay");
}
}
public class Test{
public static void main(String[] args){
Mammal h = new Horse();
Cattle c = new Horse();
c.eat(h);
}
}
</pre>
In the above example the method eat is not being overridden so the compiler matches the correct method i.e. Mammel::eat as h is of type Mammel, but if you change the code to
<pre>
class Mammal{
void eat(Mammal m){
System.out.println("Mammal eats food");
}
}
class Cattle extends Mammal{
void eat(Mammal c){
System.out.println("Cattle eats hay");
}
}
class Horse extends Cattle{
void eat(Mammal h){
System.out.println("Horse eats hay");
}
}
public class Test{
public static void main(String[] args){
Mammal h = new Horse();
Cattle c = new Horse();
c.eat(h);
}
}
</pre>
then the method Horse::eat will be called.
Vinay
Ok Here is an idea, try this
In order to achieve b >> n // where n is number of bits, b is the byte
try
(~(~b | 0xFFFFFF00)) >> n // n is number of bits
Let me try to explain what I am doing here with your example, it will work with any byte
first
b is promoted to integer so 0x91 -> 0xffffff91
~b is 0x0000006E
0x0000006E | 0xFFFFFF00 is 0xFFFFFF6E
~0xFFFFFF6E = 0x00000091
now we do the shift say shift by 4 we get
0x00000091 >> 4 = 0x00000009 which when cast to byte results in 0x09 and which is the correct result. Hope you are able to work with that, I am sure all other intelligent people here will be able to come up with a much elegent solution.

Hello there
Does Anybody knows how I can output a number in Hex Notation rather then the default decimal notation.
Thanks
<pre>
class Test {
public static void main(String a[]) {
char c = 'A' ;
// char d = '\u000D';
}
}
</pre>