Anand Kane

Greenhorn
+ Follow
since Mar 15, 2005
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 Anand Kane

Thank you all for the responses. And my apologies that the title seems to have created some confusion. I did not mean String("") constructor specifically. I meant any String constructor against literal.

Originally my intention was to initiate the discussion on this and it has been met. When I searched about this on net and could not find anything, thought there should be something. However, the discussion above leads me to belive that the code

String s = new String("abcd");

creates string instance in pool anyway. But my understanding is that it creates String on heap that is eligible for garbage collection. So, does it mean that the code creates two instances? Or is my understanding incorrect? Please comment.

Thanks
Anand
13 years ago
It is about one topic. Its about sorting in java. But I have found a thread that discusses diff between the two interfaces in detail.

However I am attaching the doc here, so that one of you could create an FAQ if you find the document worth it. I tried doing it myself, but it looks like creating an FAQ needs appropriate authorization.

Sorry, word doc attacment is not allowed.

Thank you all.

Regards
Anand
13 years ago
It's a 4 page word document.
13 years ago
1. When you need to create string as a ThreadLocal.
2. When a string is doesnt have to be living throughout the life of JVM. If you have a code that creates too many strings (in a loop for eg) and this is code is run highly infrequently in application life time, it is perhaps preferable to create strings on heap and let them be garbage collector in next GC run.

I do not have any suitable example for the second point. Members are requested to share their thoughts on second point.

Thanks
Anand
13 years ago
My apology for being very brief. I realised that only after I had posted the query.

I have small write-up explaining the usage of Comparator and Comparable interfaces. I wrote this up since many of my acquaintances do not seem to clearly understand sorting in java collections. I wanted to post the same on the site, but was unable to find where I could do so.

And I need help in this regard.

Thanks
Anand
13 years ago
Hi

I wonder if there is any way I can post small write-ups on the site? Could someone please help me in this regard?

Thanks
Anand
13 years ago
Given below is the code that threw me into confusion; line # 30 in particular. Since both the generic parameters being passed to method 'add' are of type Shape, I assumed that for this call to method 'add', the generic type would be inferred to 'Shape'. But since it doesn't generate a class cast exception at line# 30, it is obvious that generic type is inferred as 'Object' and not Shape.

Could someone please explain the way generic types are inferred when a generic method is called?

Thanks


13 years ago
Thank you all for posting responses with clear evidence. I posted this particular question because I wasn't sure of it. There were few more to make me realize that there was no point arguing with that interviewer. And the company is one the biggest brandnames across the globe.
13 years ago
Hi All

Here is a question I was asked in one of the interviews. Which of the following two performs better,

var!=null or !(var==null)?

The interviewer told me that the latter performs better. I haven't heard or read any such thing before. So I will appreciate if someone can confirm the interviewer's opinion.

Thanks
Anand
13 years ago
Hi All

I wrote this simple composite iterator code. Hope this serves some purpose for someone.

Regards
- Anand