Hi, @ Stephen,
I will explain to you the fact why and where you get invalid literal in Java with a simple example with context: Suppose, you have taken,
x=5 and y=x++ which is correct in Java, then why is int y=++4 isn't correct!
Here it goes,
Literal: Any constant value which can be assigned to the variable is called as literal/constant.
// Here 5 is a constant/literal.
int x = 5;
That's because 5 is a value (represented by the literal 5), not a variable (which is basically a named container for a value) like x. You can change the value contained in a variable, but not the value itself. This is why you get the syntax error: Invalid literal.
++ is the pre-increment operator in Java — it takes a variable, increments the value contained within it, and returns the updated value. Which is the reason why constructs like ++(++x) are invalid in Java — the increment and decrement operators return the value instead of a (variable) reference to that value.
I hope this will help you to understand the concept.