1/9
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
WHAT IS SYNTAX?
In programming languages, syntax defines the rules that determine the structure and arrangement of keywords, symbols, and other elements. Syntax is concerned with the grammar and structure of the programming language and is unrelated to the meaning of the statements.
A line of code is syntactically valid and correct if it adheres to all the syntax rules. Syntax does not pertain to the meaning of the statement. Syntax errors are identified after the program is executed.
Examples of syntax errors include missing semicolons in C++ and undeclared variables in Java, which are typically easy to detect.
WHAT IS SEMANTICS?
Semantics refers to the meaning of the associated line of code and how they are executed in a programming language. Hence, semantics helps interpret what function the line of code/program is performing.
Semantic errors are encountered and handled during runtime of the program execution. If there is any semantic error and even when the statement has corrected syntax, it wouldn't perform the function that was intended for it to do. Thus, such errors are difficult to catch.
DIFFERENCES OF SYNTAX AND SEMANTICS?
Syntax defines the rules and regulations that help write any statement in a programming language,
while semantics refers to the meaning of the associated line of code in the programming language.
THE FOLLOWING TABLE HIGHLIGHTS ALL THE
SIGNIFICANT DIFFERENCES BETWEEN SYNTAX
AND SEMANTICS −
SYNTAX
Syntax is one that defines the rules and
regulations that helps to write any
statement in a programming language.
Syntax does not have any relationship
with the meaning of the statement.
Syntax errors are encountered after the
program has been executed
Syntax errors are easy to catch.
SEMANTICS
Semantics is one that refers to the
meaning or logical effect of code in a
programming language.
Semantics tells about the meaning.
They are encountered at runtime.
Semantics errors are difficult to catch.
Comments
Single-line comment: // This is a single-line comment.
Multi-line comment: /* … */ This is multi-line comment.
Data types
Primitive Data Types: (ex. Integers, Floating point, Character, Booleans)
Non-Primitive Data Types: (ex. String, Array, Classes & Object, Interfaces)
Variables
Declaring and Initializing:
Operators
Arithmetic Operators:
Comparison Operators:
Logical Operators:
Control Structures
If-Else:
Switch-case:
For Loop, while Loop, Do-while Loop:
Classes and Object
Defining a Class:
Creating Objects: