Java will not allow you to reference a variable unless it has been "definitely assigned". "Definitely Assigned" has a very strict definition, basically boiling down to "This variable must have been assigned no matter what path of execution has been followed".
Looking at your example, the compiler simply sees two 'if' statements. It is not concerned with evaluating the conditions in those 'if' statements; So far as it's concerned, they're unrelated.
Since, it reasons, both 'if' clauses could be false (since it hasn't evaluated and cross-referenced the clauses), then it's possible 'y' is being used before it's been assigned - hence your error.
Solution: Replace your 2 'if' statements with an 'if {...} else {...}'. This, of course, is exactly identical in function to your original code, but also lets the compiler know that every path through sets 'y'.