aspose file tools*
The moose likes Java in General and the fly likes Query in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Query in Java" Watch "Query in Java" New topic
Author

Query in Java

Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi,
I have piece of code as below,Can ranchers explain me that "Even though emp and emp1 objects are different as shown in the output,how can the map return the same object"? Please explain



//Output see below


Please explain......



When The Going Gets Tougher,The Tougher gets Going
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40


Duplicates are not allowed in a map, so when you added a duplicate key, it replaced both the key and value.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Thanks that works.

I have still Queries left.
2> Example of Queue Implementation/Linked List Implementation in Java. ?

3>If Strings are immutable then Can we override strings as below.
Assume if we have below


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseAMeaningfulSubjectLine when posting. Explaining your question or remark briefly on the subject line allows us to know what we are getting into, and if we will be able to help. Taking the time to compose a useful subject line shows that you care enough about your question to ShowSomeEffort when asking it here.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

Deepak Lal wrote:2> Example of Queue Implementation/Linked List Implementation in Java. ?

3>If Strings are immutable then Can we override strings as below.



2> this is something that can be done via a quick google or a look at the java docs.

3> string objects are immutable. string references (that are not final) can be changed.
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Henry wrote:this is something that can be done via a quick google or a look at the java docs.

Im getting confused with Queue Implementation and Linked List Implementation since both are the same.Could you please clarify ?

Henry wrote:string objects are immutable. string references (that are not final) can be changed.

Can you please give me an example for this please??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42931
    
  68
Im getting confused with Queue Implementation and Linked List Implementation since both are the same.

There is *some* similarity, since LinkedList implements Queue, but they're not the same at all. For example, other implementations of the Queue interface have none of the methods in the List interface.
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Thanks Ulf ffor the replies,


1> Could you give me a example in Java for Queue and LinkedList Implementation ? I do agree with your comments but can you help me out with an example please ?




2> Java Example needed for "string objects are immutable. string references (that are not final) can be changed."
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

An example of what, how to use a List and a Queue?!
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Please help ranchers (David,Ulf)

1> Example of Queue Implementation and Linked List Implementation in Java. ? "Example Please"

2>If Strings are immutable then Can we override strings as below. Is the below Java program Valid and if so Why ? and If not then whats the reason for the same.



Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42931
    
  68
Example of Queue Implementation and Linked List Implementation in Java. ?

What do you mean by "implementation"? The Java class libraries have several classes that implement these interfaces; see the javadocs of Queue and List for which those are. >If you're looking for the source code of those classes, then somewhere in the JDK directory is a file called src.zip that contains the source code to all classes.

If Strings are immutable then Can we override strings as below. Is the below Java program Valid?

I'm not sure where you think you're overriding anything. You're calling those methods twice each as far as I can tell, and nothing else. The fact that you can assign a new value to a String reference has nothing to do with the fact that a String object is immutable. If you're unclear about these concepts I suggest to work through a beginner's book on Java; the Sun Java Tutorial also explains those concepts in the context of Java. Also read up on the difference of "value" and "reference" in an OO language.
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507


Query 1:: Example for Queue Implementation and Linked List Implementation in Java. ?
My Comments : I meant that do you have any real time example where Queue can be used in java and some other real time example where i can think of opting for a linked list.
what are the advantages and dis-advantages of using the Queue and Linked List wrt Java ? Hope It's clear now.


Query 2: I got what your are saying,,Thanks for clarifying.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Query in Java