Sharda Vajjhala

Ranch Hand
+ Follow
since Nov 14, 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
2
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 Sharda Vajjhala

So, how does this actually work? I just passed my SCJP2 and want to develop some experience in Java and related technologies.
Sharda
21 years ago
Hi
What's this "open source project" that you are referring to? I too would like to join that, since I am in a similar situation.
Thanks
Sharda Vajjhala
21 years ago
Hello,
I recently passed the SCJP. Now I want to learn Swing. I have JDK 1.2.2. What do I need to download to get started on Swing? Also, is there a Swing tutorial online anywhere?
Thanks
Sharda Vajjhala
21 years ago
I passed the SCJP 1.2 with a 79%. I couldn't have done it without the help of JavaRanch members.
Thanks to all of you.
Sharda
21 years ago

The above prints true,true,true
What exactly is the method m doing? And why is isNaN() taking an argument? Can someone please explain?
Thanks
Sharda
Vin,
Thanks for your explanations. In the 1st link, Case 4:


If you have methods as follows,
void someMethod( Base obj ); // 1
void someMethod( Level1_A obj ); // 2
void someMethod( Level1_B obj ); // 3
void someMethod( Level2_A obj ); // 4
and you invoke someMethod() with argument null, then you STILL have ambiguity because now the confusion is between invoking the Level1 method or the Level2 method i.e., between 3 & 4.


Since anything passed to Level2_A can be passed to Level1_A, Level2_A is more specific than Level1_A. The Level1_A and Level1_B are at the siblings and hence are considered "equal". Since Level2_A is more specific than Level1_A, Level2_A should be more specific than Level1_A too.
Where is the ambiguity in this case?
All the other cases are very clear to me.
Thanks
Sharda
The following are 2 questions that are somewhat similar, yet yield different results.
Question 1:
class A {}
class B {
static void m(Object x) {System.out.print("Object");}
static void m(String x) {System.out.print("String");}
public static void main(String[] args) {
m(null);
}
}

What is the result of attempting to compile and run the above program?
a. Prints: Object
b. Prints: String
c. Compiler error.
d. Runtime error.
e. None of the Above
Answer: b.
Explanation:
Section 15.12.2.2 of the Java Language Specification states the following. If more than one method declaration is both accessible and applicable to a method invocation, it is necessary to choose one to provide the descriptor for the run-time method dispatch. The Java programming language uses the rule that the most specific method is chosen. The informal intuition is that one method declaration is more specific than another if any invocation handled by the first method could be passed on to the other one without a compile-time type error. End of quote. In this case, the String type is more specific than the Object type.
Question 2:
class A {}
class B {
static void m(Object x) {System.out.print("Object");}
static void m(String x) {System.out.print("String");}
static void m(A x) {System.out.print("A");}
public static void main(String[] args) {
m(null);
}
}

What is the result of attempting to compile and run the above program?
a. Prints: Object
b. Prints: String
c. Compiler error.
d. Runtime error.
e. None of the Above
Answer: c
In question 2, why doesn't it pick A? A being a user-defined class should be considered more specific than String or Object, right?
Can someone explain to me how the compiler decides what is more specific than the other?
Thanks
Sharda
This is from Marcus Green's Mock Exam.
Which of the following are legal statements?
1) float f=1/3;
2) int i=1/3;
3) float f=1.01;
4) double d=999d;
Answers: 1,2,4
How are 1 and 2 legal? I thought a numerical literal containing a decimal component was interpreted as a double. Going by that logic, 1 and 2 should be double values which should be illegal statements.
Can someone clarify?
Thanks
Sharda
Thanks for the responses (along with examples too).
Sharda
Stefan,
So, basically, to initialize variables you have to do one of the following:
1) provide a path in the program to assign a value to the variable. If you are using an "if" stmt to assign value, then make sure you have an "else" construct too.
2) explicitly assign a value to the variable
It seems strange that a compiler can understand the if-else logic but does not understand multiple if although it implies the same logic.
These kinds of questions are really frustrating me.
Thanks
Sharda
This is from JavaPrepare Lang Fundamentals Exam:


Answer: D.
According to Bill Brogden's Exam Cram book "The compiler will report an error if there is any path in your code that does not initialize a variable before it is used."
In the above question, y is always being set to a value - so why doesn't it compile? I thought the answer would be C.
Thanks
Sharda
Thanks, that was a great help. It certainly cleared things up.
Sharda
I think you should start with taking tests. Start with the topic exams of Dan. They are really good. Also, don't make the mistake of trying to cover the material completely, before embarking upon exams.
I left the exams for the last and I regretted it, because I found out that I still don't know a lot of things. The topic exams, especially, are a learning tool. Also, try out all the examples. Comment out or change code in different sections and see the difference in o/p.
-Sharda
Given the following code what will be the output?

The correct answer is 10020.Can someone explain the result?
Thanks
Sharda