Ravinder Singh

Ranch Hand
+ Follow
since Mar 06, 2006
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 Ravinder Singh

Thanks Barry (and Ganesh) for your clarifications...
Here is another one...this time using equals() method.



Object class equals() method is used to test object equality ie. to see if two instances of the same type are "meaningfully equal".

Q. The above doesn't compile saying:

Why int pi in the code above not boxed (wrapped) to an Integer object while invoking equals()? The code compiles and runs when the same expression is changed to i.equals(pi), in which case the argument pi IS wrapped.

Regards
Ravinder
Dear ranchers,

The following code compiles and prints true.



In the above code, == is used to compare the bit pattern/values of an Integer object with an int primitive. It looked like from the result that Integer object is unboxed and then both the primitives values' are checked for equality thereby resulting in value true.

Q. Why is an Integer object being unboxed as opposed to primitive being boxed instead (in which case the result would have been false)?

Regards
Ravinder Singh
Thanks a lot Peter for your explanation. I've understood the concept now.

---------------
Ravinder Singh
oops.. sorry for typos.
here is the correct code sample:

Hi Marc,

I couldn't understand your explanation. Would you pls. support your reasoning with the corresponding code sample?

As I understand a=b is not a valid identifier and hence cannot be used as a class name. The following code won't compile:



I would appreciate more clarifications on this topic.

---------------
Ravinder Singh
Hi Ranchers,

Here is my question - Source: SCJP 5 Guide by K&B: Q5. Page 391 / 402

Given:



Which, inserted at line 4, produces the output 12?
A. int y = x;
B. int y = 10;
C. int y = 11;
D. int y = 12;
E. int y = 13;
F. None of the above will allow compilation to succeed.

Answer:
> C is correct. x reaches the value of 11, at which point the while test fails. x is then incremented (after the comparison test!), and the println() method runs.
> A, B, D, E, and F are incorrect based on the above.

My Question:
Since postfix operators (as well as prefix unary operators) have higher precedence than relational operators; why isn't x++ evaluated before < operator in the do{} while() expression in the question above? Going by that the correct answer should be option D.

---------
Ravinder
Congrats Nishant...it's a GREAT score!


----------
Ravinder
14 years ago
Cool concept..
Thanks Henry!

-------------
Ravinder
Hi,

Pls. help me understand the following..I've customized the code a bit:



Line 6:
two dimension int array a assigned to an Object d2 --> code compiles

Line 7:
two dimension int array a assigned to a single dimension Object array d3 --> code compiles

Line 8:
two dimension int array a assigned to double dimension Object array d4 --> compiler error!

Q. Why does the code compiles with respect to line 6 and line 7 and NOT for line 8? What are the differences?

--------------
Ravinder
Thanks Joshua..
The warnings disappear if I change the statement for TreeSet instantiation to: TreeSet<String> map = new TreeSet<String>();

-----------
Ravinder
Dear ranchers,

I have a query in the following question that I have customized a bit for testing purpose:

Given:-


Which statements could be inserted at // INSERT DECLARATION HERE to allow this code to compile and run? (Choose all that apply.)

A. List<List<Integer>> table = new List<List<Integer>>();
B. List<List<Integer>> table = new ArrayList<List<Integer>>();
C. List<List<Integer>> table = new ArrayList<ArrayList<Integer>>();
D. List<List, Integer> table = new List<List, Integer>();
E. List<List, Integer> table = new ArrayList<List, Integer>();
F. List<List, Integer> table = new ArrayList<ArrayList, Integer>();
G. None of the above.

Correct Answer is B.

What if I modify option C a bit to make it look like the following ..and try to recompile and run. But it doesn't compile, why? What is wrong with the type declaration here?

List<ArrayList<Integer>> table = new ArrayList<ArrayList<Integer>>();

-------------
Ravinder
Hi,



Q. Why does the code above compiles with the following warning??

Note: TestMaps.java uses unchecked or unsafe operatio
Note: Recompile with -Xlint:unchecked for details.



--------------
Ravinder
Well Done Shawn! Congratulations!!


----------
Ravinder
14 years ago
Check this section: "Questions about Exam Preparation (Books, Notes, Mock Exams, etc.)" on http://faq.javaranch.com/view?ScjpFaq

---------
Ravinder
14 years ago