Advantages of Java memory over memcache:

  1. Java memory is faster (no network).
  2. Java memory won’t require serialization, you have Java objects available to you.

Advantages of memcache over Java memory:

  1. It can be accessed by more than one application server, so your cache will be shared among all your app servers.
  2. It can be accessed by a variety of different servers, so long as they all agree on the key scheme and the serialization.
  3. It will discard expired cache values, so you get time-based invalidation.

 

 

There are several differences between HashMap and Hashtable in Java:

  1. Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.
  2. Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.
  3. One of HashMap’s subclasses is LinkedHashMap, so in the event that you’d want predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for a LinkedHashMap. This wouldn’t be as easy if you were using Hashtable.Since synchronization is not an issue for you, I’d recommend HashMap.

 

8  
This statement “unsynchronized Objects typically perform better than synchronized ones” isn’t always true anymore with modern compilers. The key point is that the HashMap must be externally synchronized rather than relying on the internal synchronized methods. – Bob Cross Dec 5 ’08 at 20:58
1  
+1 Because you also recommend the best one in this case. – OneWorld Dec 17 ’10 at 14:29
5  
@Bob your statement about modern compiler is completely nonsense. Modern compilers can optimize synchronisation to the point where they are as effective as non-synchronized code, but they will never out-perform it. Or can you give me an example where this is not the case? – LittleFunnyMan Jan 29 ’11 at 9:48
22  
Sometimes I wish I could downvote comments… @LittleFunnyMan: did Bob say that synchronised objects can perform better than unsynchronised ones? No. All he said was that unsynchronised objects aren’t always better than synchronised ones – precisely what you said, if I’m not mistaken… – Mac May 24 ’11 at 4:26
1  
Nice answer. One