C Halbe

Greenhorn
+ Follow
since Jul 18, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
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 C Halbe

Makes sense Campbell Ritchie. Thanks for your response.

Can you please paste the link here for the tutorial that you are talking about?
12 years ago
Yes, I am familiar with other collections. I guess I can use comparable to sort by first name and then run a comparator to sort by the last name on the set to sort by the last name.

I was thinking more in terms of a TreeMap with last name as the key, and use chaining with the values

Eg. (Key)Halbe /(Values)--> Campbell Halbe --> Charles Halbe --> Christopher Halbe

But set would be a better option as it handles duplicates on its own. Using TreeMap, I will have to write that code myself.

Please let me know what you think.

Appreciate it!
12 years ago
I have a file containing a list of first name, last name. I want to read the file, sort by last name. The results should still print as first name, last name but will be sorted by last name.


I am thinking of using a TreeMap for this.

Please share your insight on this.
12 years ago

Michael Dixon wrote:I have been doing the courses, for 2 weeks now. They are very good. I have no regrets. www.jpassion.com is an alternative that is worth considering.



Which one do you think is better between Jpassion.com and learnnowjava.com? Your review will help. I am thinking of registering for one of these two within a few days.
12 years ago
What type of collection/data structure would you use?
12 years ago
How would you compact a set of number ranges in pairs such that

eg. Given:[1,10], [2,5], [25, 40]
output : [1,10] covers [2,5] hence output would be [1,10] and [25,40]
12 years ago

Jeff Verdegan wrote:
Your other choice is to tell them to take a hike.



LOL....I was just asking this because this is asked in interviews. If asked, I will have to show the implementation in other language, not Java.
12 years ago
Hi Brian,

Thanks for replying.

Yes, that's what I meant by "in-place". So I guess, if someone asks me how to reverse a string "in-place" I will have no choice but to implement it in C/C++, because in Java, while returning the reverse String we will create a new String.
12 years ago
Can this be done in Java?
12 years ago
I know that once a thread gets an ID it will not change until the thread is dead. But why does the ID change when we run the below code with start() and it does not change when we call the run() directly?



Please help me understand.

What happens if the package xcom are removed from the A.java and B.java? The fully qualified name of them are now A and B.



If the package xcom; is removed from both the classes then, you haven't mentioned what is the new location of those two classes. They must belong to some default directory.
And you have 100% marks!! false is the answer...oh helen, there is no greater java scholar on this planet than you!!

Anyways, i just wanted Mr. ayush raj to have a clear understanding of where the two "abc" objects will be created. And I think I have proved the point!

ayush raj wrote:@C Halbe : And what about equals method? How does it manipulate the strings equality? For the case 1 : does any object exist on the heap ?



equals() does not manipulate the strings. It will only compare the contents of the the two string objects and tell you if they are meaningfully equal.

str1.equals(str2) will be true because in literal sense it doing something like "abc".equals("abc");

ayush raj wrote:Totally confused relating to String constant pool and the heap .



String constant pool is a part of the heap, but separately allocated only for String because of the way strings behave in Java. So when you say "in the constant pool" , it is on the heap but inside the string constant pool.

Whenever we create a string, eg.
String s = "abc";
JVM will check the constant pool if "abc" is already there in the pool, if not, it will create "abc", but if it already exists then the existing "abc" object will be allocated to s reference variable.

In case of
String s2 = new String("xyz");
JVM will create a String object in the heap (outside of the pool) because of the 'new' keyword. It will also put "xyz" in the constant pool in the manner I stated above. That is how the JVM works.

To clear your confusing try running this simple code below and checkout the results!



ayush raj wrote:How many objects are created if i write the following codes in java 1.6 :

String str1="abc";// case 1

String str2=new String("abc");//case 2

Does str1 will also be stored in the some string literal pool or only str2 would be stored in the pool ?



If the 2 cases are taken separately, then

case 1: only one object will be created in the string constant pool and str1 will refer to it

case 2: two objects will be created as we use the 'new' keyword, one on the heap(non-pool memory) and str2 will refer to it and other object in string constant pool - assuming that "abc" is not already present in the pool

ayush raj wrote:But then how could i know if two objects have been created or only one object is created ?



== will tell you if the two references refer to the same object on the heap. In above case (str1==str2), the result will be false.


Correct me if I am wrong.