Java has contradictory scoping : For this code sample the Java compiler is not happy:

    public class Test1 {
      public static void main(String args[]) {
        int x = 99;
        {
          int x = 10;
          System.out.println(x);
        }
        System.out.println(x);
      }
    }

The compiler says "error: variable x is already defined in method main(String[])".

However, the Java compiler is completely satisfied with this:

    public class Test1 {
      public static void main(String args[]) {
        {
          int x = 10;
          System.out.println(x);
        }
        int x = 99;
        System.out.println(x);
      }
    }

And that, gentleladies and gentlemen, is a little piece of insanity in Java. When I look up Java scoping rules, I'm almost always seeing writers describe that variables are scoped within the block level they're in, except for instances of object level variables which retain their values for the instance lifetime - and none of them explain the rules in a way that explains the way the Java compiler deals with the code samples here. But as we can see from these two obvious examples, the scoping rules don't really work they way everyone is describing them.

Will someone explain this correctly, please, so that I am understanding it properly.