The switch build the "if" cases structure based on compilation time (for example you cannot change a or b on runtime). In your second code you have a compilation error because the b variable is not initialized at the compilation time. The compiler cannot know that you will initialize it later.
The case constant must be compile time constant, because the case argument has to be resolved at compile time. The variable that has to be used in the case must be assigned a literal at the time it is declared.
final int b; a=10; //b is not compile time constant because it is assigned the value at run time.