Syntax - Set of rules that defines the combinations of symbols that are considered to be correctly structured programs in that language.
Something that is syntactically correct means that the rules of the language in which it is written are followed.
For instance, saying “The chicken ate the horse” is syntactically correct, as it does not lack anything to form a complete sentence in English.
In terms of java, int sum = 0; is syntactically correct, as it follows the rule of java coding.
Should you compile it, you would encounter no errors.
However, syntactically correct should never be confused with something that is semantically correct (or logically correct).
This leads us to our next topic – semantics.
Semantics - Refers to the meaning of languages, as opposed to their form (syntax).
Semantics is about interpretation of an expression. Additionally, the term is applied to certain types of data structures specifically
designed and used for representing information content. An English example of correct syntax application,
but incorrect semantic application would be "The bat slipped out of his hands". Determining whether the bat mentioned refers
to something like a baseball bat or the animal itself depends on the context, and cannot be determined solely by the sentence itself.
A semantically and syntactically correct sentence in English would be “I ate my food.”