title: java URL object - new java.net.URL()
body: <p>I'm a very new to java, just trying to run some simple programs.
  I have this code:</p>
  
  <pre><code>import java.net.*;
  import java.io.*;
  
  class example1 {
  
      public static void main(String args[]){
  
      try{
          URL hp = new URL("http://www.java2s.com");
          System.out.println("it all worked?");
      }catch (MalformedURLException e){
          System.err.println("New URL failed");
          System.err.println("exception thrown: " + e.getMessage());
      }
  
      System.out.println(hp.getProtocol());
  
      }
  }
  </code></pre>
  
  <p>The java compiler "cannot find symbol: hp" which would lead me to believe that the url object, hp is not being created by the line:</p>
  
  <pre><code>URL hp = new URL("http://www.java2s.com");
  </code></pre>
  
  <p>But shouldn't the catch statement be reporting an error?</p>
  
  <p>I tried compiling without the try-catch blocks but I was getting an error saying "unreported exception MalformedURLException; must be caught or declared to be thrown"</p>
  
  <p>If i remove the last line that refers to hp, the program compiles and runs but just displays "it all worked?".</p>
  
  <p>I'm sure there is a simple explanation here but I don't have much knowledge of java.
  Thanks</p>