• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query in Java

 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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......

 
Henry Wong
author
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Henry
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An example of what, how to use a List and a Queue?!
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic