title: Java API and checked/unchecked exceptions confusion
body: <p>The question about checked and unchecked exceptions was raised here and on other websites million times, but I'm still confused with so different answers.</p>
  
  <p>In many answers and articles we can read general statements like:</p>
  
  <blockquote>
    <p>Unchecked runtime exceptions represent conditions that, generally
    speaking, reflect errors in your program's logic and cannot be
    reasonably recovered from at run time.</p>
  </blockquote>
  
  <p>and for checked exceptions</p>
  
  <blockquote>
    <p>represent invalid conditions in areas outside the immediate control of
    the program (invalid user input, database problems, network outages,
    absent files)</p>
  </blockquote>
  
  <p>both quotes are from <a href="http://www.javapractices.com/topic/TopicAction.do?Id=129" rel="nofollow noreferrer">http://www.javapractices.com/topic/TopicAction.do?Id=129</a> and are cited many times.</p>
  
  <p>We can read similar statements on oracle website:</p>
  
  <blockquote>
    <p>Runtime exceptions represent problems that are the result of a
    programming problem, and as such, the API client code cannot
    reasonably be expected to recover from them or to handle them in any
    way
    <a href="http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html" rel="nofollow noreferrer">http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html</a></p>
  </blockquote>
  
  <p>Lets take simple example with reading Number with Scanner:</p>
  
  <pre><code>Scanner sc = new Scanner(System.in);
  int userInput = sc.nextInt();
  System.out.println(userInput);
  </code></pre>
  
  <p>nextInt() throws InputMismatchException when I type i.e. "asdf" instead of int. InputMismatchException is RuntimeException but according to statements above this is the first example of checked exceptions "invalid user input".</p>
  
  <p>When I look at checked exceptions I am even more confused. For example NPE vs FileNotFoundException - both can be prevented by simple if-else, so why first one is unchecked and second is checked?</p>
  
  <p>Oracle website has bottom line guideline:</p>
  
  <blockquote>
    <p>If a client can reasonably be expected to recover from an exception,
    make it a checked exception. If a client cannot do anything to recover
    from the exception, make it an unchecked exception.</p>
  </blockquote>
  
  <p>So according to that I can recover from FileNotFoundException or IOException but I can't from NPE or ArrayIndexOutOfBoundsException? This makes no sense.</p>
  
  <p>Maybe someone has better explanation to this with some better example?</p>