title: Testing a Java Long value in an if statement. Does 0 != 0
body: <p>For the life of me I cannot figure out why I can’t get this method to enter the if statement.</p>
  
  <pre><code>protected void foo() {
      Date d = new Date();
      long now = d.getTime();
  
      long start;
      SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
      start = settings.getLong(FIRST_USE_DATE, 0);
      Log.w(this.getClass().getName(), Long.toString(start));     
  
      if (start == 0) {
          SharedPreferences.Editor editor = settings.edit();
          editor.putLong(FIRST_USE_DATE, now);        
      }
  </code></pre>
  
  <p>return true;
      }</p>
  
  <p>Note that the log and debug mode shows that “start = 0”</p>
  
  <p>I also tried</p>
  
  <pre><code>if (start == 0l) {
  if (start == 0L) {
  </code></pre>
  
  <p>What the heck am I missing here?  Does 0 != 0?</p>
  
  <p>I’m developing in Eclipse with Java for Android.  Thanks.</p>
  
  <p>Edits:</p>
  
  <p>@methodin - no sorry, that does not work.</p>
  
  <p>@Aioobe - I have a breakpoint under the IF statement, that never gets made.</p>
  
  <p>Edit2: Here is the actual code I'm running since you've asked.</p>
  
  <pre><code>protected boolean isDemoExpired() {
      Date d = new Date();
      long now = d.getTime();
  
      long demoStart;
      SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);   
      demoStart = settings.getLong(FIRST_USE_DATE, 0);        
  
  if (demoStart == 0) {
      SharedPreferences.Editor editor = settings.edit();
      editor.putLong(FIRST_USE_DATE, now);
      System.out.println(Long.toString(demoStart)); 
      return false;
  
  }
  return true;
      }
  </code></pre>