title: Why is this Java code in curly braces ({}) outside of a method?
body: <p>I am getting ready for a java certification exam and I have seen code LIKE this in one of the practice tests:  </p>
  
  <pre><code>class Foo {  
      int x = 1;  
      public static void main(String [] args) {  
          int x = 2;  
          Foo f = new Foo();  
          f.whatever();  
      }  
      { x += x; }  // &lt;-- what's up with this?
      void whatever() {  
          ++x;  
          System.out.println(x);  
      }  
  }
  </code></pre>
  
  <p>My question is ... Is it valid to write code in curly braces outside a method? What are the effects of these (if any)?</p>