local variable in Java

A local variable is a variable defined within a method. Local variables must be initialized before use. They do not have a default value and contain garbage data until initialized. The compiler will not let you read an uninitialized value. If you init a local variable in a block, the compiler knows that initialization might not happen and produces compile-time error. When using a switch or a if-else to init a local variable, should cover all allowable possibilities, otherwise there is a compile-time error.

```
public class Main {
    public static void main(String[] main) {
        String s;
        System.out.print(s); // Error: variable s might not have been initialized
    }
}
```