title: Java Pass By Value and Pass By Reference
body: <p>i have done the following sample with to check my knowledge </p>
  
  <pre><code>import java.util.Map;
  
  public class HashMap {
      public static Map&lt;String, String&gt; useDifferentMap(Map&lt;String, String&gt; valueMap) {
          valueMap.put("lastName", "yyyy");
          return valueMap;
      }
  
      public static void main(String[] args) {
          Map&lt;String, String&gt; inputMap = new java.util.HashMap&lt;String, String&gt;();
          inputMap.put("firstName", "xxxx");
          inputMap.put("initial", "S");
          System.out.println("inputMap : 1 " + inputMap);
          System.out.println("changeMe : " + useDifferentMap(inputMap));
          System.out.println("inputMap : 2 " + inputMap);
      }
  }
  </code></pre>
  
  <p>the output is : </p>
  
  <pre><code>original Map : 1 {initial=S, firstName=xxxx}
  useDifferentMap : {lastName=yyyy, initial=S, firstName=xxxx}
  original Map : 2 {lastName=yyyy, initial=S, firstName=xxxx}
  </code></pre>
  
  <p>this method <code>useDifferentMap</code> gets the map and changes the value and returns back the same.
  the modified map will contain the modified value and the scope of it is local for the <code>useDifferentMap</code> method.</p>
  
  <p>my question is if java is pass by value is the modified value should not be affected in the original map.</p>
  
  <p>so is java pass by value or pass by reference ???</p>
  
  <p>thanks</p>