Common Mistakes and Errors in Java
When we write a Java program we may make small mistakes. Even a small mistake can cause an error in our program. Sometimes the program will not compile and sometimes it will not run properly.
my Home class program I may make the following mistakes.
Missing Semicolon (;)
If I forget to put a semicolon at the end of System.out.println("Hello World"); Java will show a compilation error.
Missing Dot (.)
If I forget the dot in System.out.println() Java will not understand the statement correctly and may show a compilation error.
** Missing Curly Brackets { }**
If I forget the opening or closing curly bracket Java may show an error because the code block is incomplete.
**
Missing Parentheses ( )**
If I forget the parentheses in the main method or print statement Java may show a compilation error.
**
Missing public**
If I remove public from the main method the program may compile but Java may not be able to access the main method to start the program.
** Missing static**
If I remove static from the main method the program may compile but Java may not recognize it as the correct entry
Missing void
If I remove void from the main method without replacing it with a valid return type the program will show a compilation
Missing main
If I write the main method name incorrectly Java may not find the main method and may show a main-method error when I run the program.
Incorrect String Spelling
If I write string instead of String Java will show an error because Java is case-sensitive.
Incorrect System Spelling
If I write system instead of System Java will show a compilation error because uppercase and lowercase letters are different in Java.
Incorrect println Spelling
If I write Println instead of println Java may show a compilation error because the method
Missing Double Quotes (" ")single Quotes (' ')
If I forget the double quotes around Hello World Java may show a compilation error because the text is not written corr
Incorrect Class Name
If I write the class name incorrectly I may get a compilation error or a class not found error when I run the program. If the class is declared public the filename must mat
** Missing Class **
If I forget to write class before the class name Java will show a
Extra Semicolon
If I put an extra semicolon in the wrong place the program may compile but behave differently from what I expected. The result depends
Incorrect Capital Letters
Java is case-sensitive Home, home, and HOME are different names. Using the wrong capitalization
Missing Closing Bracket at the EndBracket at the End**
If I forget the final closing curly bracket Java may show an error because the class or method
** Writing Code Outside the Class Outside the Class**
If I write a statement such as System.out.println() directly outside a method Java may show
Writing the Print Statement Incorrectly
If I write System.out.println without the correct parentheses or semicolon Java may show
Incorrect File Name
If the public class is named Home the source file should be named Home.java. Java may show a filename related compilation error.
Main Method Mistake
If I change String[] args incorrectly or write the main method with an invalid declaration Java may not recognize the main method as the program entry point.
Missing the Main Method
If I write the class and print statement but forget the main method Java will not find the correct starting point when I try to run the program.
Top comments (0)