Title | Syntax Errors Vs Semantic Errors |
---|---|
Course | Programming 1 |
Institution | University of the People |
Pages | 2 |
File Size | 88.7 KB |
File Type | |
Total Downloads | 22 |
Total Views | 194 |
Discussion Assignment For Programming 1 CS 1102 Unit 1....
SYNTAX ERRORS & SEMANTIC ERRORS, WHAT’S THE DIFFERENCE? SYNTAX & SYNTAX ERROR Syntax in programming refers to the rules that define how combinations of words and characters make up a working program. Syntax can be described the structure or form of the programming language and this what facilitates communication between the programmer/user and the computer. When there are syntactically unfitting such as misspelling of keywords, misdeclaration of variables, or even omitting punctuations. SYNTAX ERROR EXAMPLE: public class DiscussionAssignment { public static void main(String[] args) { System.out.println("Hello World") /* * In Java, each code statement must end with a semicolon. */ } }
SYNTAX ERROR CORRECTED: public class DiscussionAssignment { public static void main(String[] args) { System.out.println("Hello World"); /* * In Java, each code statement must end with a semicolon. */ } }
SEMANTICS & SEMANTIC ERROR Semantics in programming tends to deal with the logic and meaning of syntactically valid programs. It reads the program and validates it and executes it as it is. A program with a semantic error is one that can be compiled and run but produces or returns an incorrect or unexpected result. Some semantic errors cannot be determined at compile-time and can only be assessed at runtime, others produce no result or results that are not useful. SEMANTIC ERROR EXAMPLE: public class DiscussionAssignment { public static void main(String[] args)
{ int message = "Hello World!"; System.out.println(message * 5); /* * In Java, String and int are incompatible data types */ } }
SEMANTIC ERROR CORRECTED: public class DiscussionAssignment { public static void main(String[] args) { int message = 6; System.out.println(message * 5); /* * In Java, int mathematical operations are allowed. */ } }...