In this article, I will explain how Java is a strict and syntax oriented programming language.
Java Compiler Errors will be displayed when we make syntax mistakes in the Java code.
In this article, I will give 3 examples in a practical way, where we make syntax mistakes intentionally and get compiler errors.
Let’s get started.
Java for Testers – Compiler Errors
Follow the below steps for the practical demonstration of compiler errors due to the intentionally made syntax errors in the Java code
1) As we already know from the previous article that, all the Statements in Java should end with a semicolon symbol ;
In the below screen, there is no compiler error in the program as there is semicolon symbol provide at the end of the Java print statement.
Now, let’s remove the semicolon symbol ; from the end of the above shown Java print statement and observe that the compiler error will be displayed as shown below:
Again provide the ; at the end of the print statement to resolve the error.
2) Moving to the next example.
Java is case sensitive (i.e. syntaxes which are in capital letters should be provided in the capital letters only and the syntaxes which are in small letters should be provided in small letters only)
In the print statement, the first letter in the System keyword is in the capital as shown below:
Now, let’s make it small and observe that the compiler error will be displayed as shown below:
Again change it back to the capital letter to resolve the compiler error.
3) Moving to the last and final example.
According to the Java Syntax, if there is a starting brace then we should end it with an ending brace.
In the below example, class block has a starting and ending curly braces as shown below:
Now, let’s remove one of the brace as shown below:
Provide the ending brace back to resolve the error.
Hence Java is a strict language and on missing any syntax will result in compiler errors as explained above.
Here concludes this article.
In the next article, I will explain about the different types of print statements in Java.
- > To learn more about Java, continue to the next post (Click on Next Post link below)
- > Check complete Java Tutorial Contents here (Click here)
Please leave your questions/comments/feedback below:
Happy Learning 🙂
Arun Motoori (www.QAFox.com)
On a mission to help the Testing Community in all possible ways.