title: Store images with unique filenames using hashing
body: <p>I'm looking for a solution for storing unique file names for a web application using Java Servlet.</p>
  
  <p>What I need is to render profile images in a webpage, since I decided to store only file names in the database I have only to be sure they're unique in the image folder: to achieve that I was thinking to name images and save them with a string name composed by the couple:</p>
  
  <pre><code>&lt;user_id&gt;_&lt;hash&gt;.&lt;file-type&gt; 
  </code></pre>
  
  <p>In this manner I think I would be pretty sure there will be no collisions, since user_ids are already unique.</p>
  
  <p>1) Is this solution sound? </p>
  
  <p>2) What algorithm should I pick for this purpose? </p>
  
  <p>I'd like to use it properly so code snippets would be very appreciated.</p>
  
  <p>Thanks</p>