• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Clarifications..help needed

 
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,
I had few clarification in Core Java .Please help me out.

1>
what is shallow copy and deep copy of objects ?Please provide me an example for the same?


2>
How is HashMap and HashTable different in terms of Synchronization.?Please explain me with a real time scenario as to when i should use a HashMap and when i should use a HashTable? Real time Examples provided will be helpful to understand the differences.


3>

 
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the answer of your first question see this link.

https://coderanch.com/t/401249/java/java/difference-between-deep-copy-shallow
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Himanshu Gupta:
For the answer of your first question see this link. . . .



For the answer to your second question see this link. Link And this one, this one, this one and this one.
 
Deepak Lal
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 2: How is HashMap and HashTable different in terms of Synchronization.?Please explain me with a real time scenario as to when i should use a HashMap and when i should use a HashTable? Real time Examples provided will be helpful to understand the differences.??



@Campbell Ricthiee :you have given me links to the API,i had enough of API information,but can you give me some real time scenario where we can implement HashMap and HashTable,Please explain me with a real time scenario as to when i should use a HashMap and when i should use a HashTable? Real time Examples provided will be helpful to understand the differences.



Please help me out with Question 3 and Question 4 as well.

Help provided will be highly appreciated.

;-)

--
Deepak Lal
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
2: Map example. Always use HashMap. Look in its API for what to do if you need to synhronise it.
3: Sorry I didn't notice that question. Reflection
4: Yes. Because it requires more work.

And you are going to have to get used to reading API documentation.
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to synchronize the HashMap?
Use the built-in method.


Regards.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Real-time examples of HashMap & HashTable.
Basically there is no major difference between HashMap & HashTable now.
In earlier versions HashTable is synchronized in-built that's why they preferred it.
But now you can make your HashMap synchronized by the built-in methods of Collections class.

Suppose you want to create a telephone directory where you need two entities:
name & no.
Have the name as the key & no as the value


Is this suffice?
Regards.
[ December 11, 2008: Message edited by: ramya narayanan ]
 
Deepak Lal
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ramya,
Thanks for your valuable inputs,i have agreed to whatever you say ,i have another set of questions now for you

Question 1> Understood from others.

Question 2> when do i need to use a HashMap and when do i need to use a Hashtable(Synchronized).I mean under what circumstances should i prefer a HashMap over a Hashtable and vice versa and Why? Can you give me a Real TIME SCENARIO under which you can strongly recommed me to use a HashMap and Hashtable.I need real time examples.i have understood the differences.<<Please read my question again carefully>>.?? i hope the question is clear now.

Question 3> Can you explain how to achieve it using Reflection API,how do i invoke a method using Reflection API.??SEE question 3 in the Original Post.

Question 4> Please give me the reason as to why Synchronization is an Overhead.?

Help provided will be immensely appreciated.
Please rancers share your valuable expertise and inputs.




--
Deepak Lal
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Question 2> when do i need to use a HashMap and when do i need to use a Hashtable(Synchronized).I mean under what circumstances should i prefer a HashMap over a Hashtable and vice versa and Why? Can you give me a Real TIME SCENARIO under which you can strongly recommed me to use a HashMap and Hashtable.I need real time examples.i have understood the differences.<<Please read my question again carefully>>.?? i hope the question is clear now.



Please see my above post.

Question 3> Can you explain how to achieve it using Reflection API,how do i invoke a method using Reflection API.??SEE question 3 in the Original Post.





4> Is Synchronization an overhead ? if so,why ??


As gurus said it is an overhead, but I don't know why?
But let us see.
Regards.
 
Deepak Lal
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ramya,

Thanks for your valuable input,If you could explain the Question 4> in concern it would be highly appreciated.



--
Deepak Lal
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why can't you google & post your opinions on that?
We Ranchers already have given you 3 answers straight forward which our guru campbell won't accept at any cost.
So expecting for your post on that?
Regards.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer to "when to use a Hashtable" is never. Never use it in new code.

Note that despite its common use to the contrary in Indian English, "real time" does not mean "practical" or "realistic". It's a technical term describing computing with hard time limits. The phrase you want is real life. You want "real life" examples. Asking for "real time" examples sounds very strange to many readers of this forum.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding synchronisation overhead associated with it
Go through this link:
Synchronisation overhead
Don't forget to post what have you got from it so that it can benefit others.
Regards.
 
Deepak Lal
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ramya and ALL
Thanks all for your valuable input,
The link which you provided simply speaks about Lock on a object.Hence being thread safe is a costly operation.So Synchronization is a costly operation.hence Only one thread acquires the lock on a piece of code hence synchronization comes in picture,which prevents multiple threads from accessing a single block of piece of code at the same time.

Please correct me IF im wrong at my statement made above.

;-)

--
Deepak Lal
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
off to the intermediate forum
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic