it makes it a lot easier to read your post if you surround your code by {code} brackets. But anyway in the first snippet you are declaring 2 int variables weight and thePrice. You are also initializing the weight with a value of 10. thePrice is not initialized at this point. The condition if(true) is alway true, so the next statement right after it will always execute and initialize thePrice with a value of 1000. By changing the condition in the second snippet the statement of never executes and when you get to the line that prints the result thePrice variable is never initialized and therefore will result in an error.
Below are some small snippets and behavior of compiler:
Above code causes compiler error because value of 'a' can be changed
Above cod compiles fine because if condition cannot be false
Above cod compiles fine because value of a cannot be changed (since a is final)
Above cod compiles fine because thePrice variable will be initialized to at least some value.
So compiler expects a constant (because it should not get changed by any other codes) to make sure conditions succeeds always.