Chain of events
I bumped into that question immediately after it was asked. It took me about 30 seconds to Google for an appropriate link, and I posted it as a comment together with a short answer to the question. While I was typing my comment another comment arrived stating same thing, but without the link, so I posted my comment anyway.
While I was deciding what close vote reason I should use, an answer arrived. It was a bad answer: I wanted to downvote and post a comment but I didn't feel like getting involved with a FGITW 200K user. So I moved on, forgetting to cast my close vote. Anyway, I thought this kind of question would get moderated soon because it is either a trivial question or an "Ask your teacher" kind of question.
Question - first version
My teacher asked a question that I don't quite understand, he asked:
what is the meaning of the following symbol in java '{'?
I'm confused as to what EXACTLY is the correct way to answer this
question.. As it could be the start of a method, or if statement, for
loop..etc.. I looked online and was unable to come up with the answer
I was looking for.
Thanks,
The answer to that is rather trivial: "it is the beginning of a block", then "ask your teacher, read a Java book".
But when it comes to symbols sometimes it is hard to search and find an appropriate answer if you don't already know the answer. I felt that the OP could use a hint so I posted the following comment:
It is start of a block
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/expressions.html
However, the link does not cover array initialization because that is not a statement block but an expression block. Mea culpa... But that is why I commented instead of posting an answer, because I thought there was no need to answer.
Also from a programming practice POV, a detailed answer to the question does not matter. There is no different meaning or possibility to misuse or misunderstand braces. If you manage to put one in the wrong place, have too few or too many of them, such a coding question could be closed as a typo.
Answer - first version
This seems like a not-so-great question - it can mean all sorts of
different things by context.
In the context of a statement, the { symbol is used to denote the
start of a block statement. This accounts for all the uses of { with
if statements, while loops, for loops, do ... while loops, switch
statements, etc., which technically only apply to a single statement
but are often used with block statements.
In the context of a method or class, the { symbol is used to denote
the beginning of the body of a class or a method. It can also be used
inside a class to declare an initializer or static initializer block.
This is entirely separate from the syntax used in block statements.
Actually, there is nothing wrong with the question itself, but it was IMO asked in the wrong place. Also, if one thinks it is such a bad question, why answer it with an equally not-so-great answer?
IMO the answer is wrong. Braces do not carry any context themselves; it is the code around them that gives the context. And actually according to the Java language specification braces are separators.
From my POV, the question should either be deleted or be left open so other answers can be added.
Since the question is now opened, and it has not-so-great answer, I reluctantly decided to post my own. If the whole thing gets deleted that is fine with me, but I would rather not leave the question lingering on the site with half an answer.
Update:
In the meantime it turned out that I don't have exact proof backing up my stance. While I haven't changed my position much, another more coherent answer by Mark Amery appeared and since differences between my POV and that answer lie more in opinion based area I decided to remove my answer.