Missing “Braces”
Leaving curly braces {} within the line of codes such as ( { and } ) can lead to a disastrous result. It often happens when a developer forgets to put an open brace and executes the code and developers at the rookie level make these mistakes so often during their initial period. However, IDEs and compilers can identify these small mistakes, but one must ensure to keep a close eye while opening any braces and close it immediately when moving on to the next section of code.
Now, look at the example below for a better understanding:
Java
public void getFood(String type) { if (type.equals( "Juice" )) { System.out.print( "Choose Juice" ); } else if (type.equals( "Mango" )) System.out.print( "Choose Mango" ); } } |
However, the code seems fine – for some (except for the one brace that has been missed out while coding). The correction has been mentioned below:
Java
public void getFood(String type) { if (type.equals( "Juice" )) { System.out.print( "Choose Juice" ); } else if (type.equals( "Mango" )) { // missing brace added System.out.print( "Choose Mango" ); } } |
10 Most Common Mistakes That Java Developers Make
If you’re working on any new programming language, there might be certain phases where you can get stuck. This eventually leads any developer to make minor-major errors and creates a roadblock towards their learning curve. Not to forget, as much as you’ll be making mistakes, you’ll achieve excellence. Besides this, learning Java is no different task and thus it can also be excelled with time and with the right resources (tutorials, courses, books, etc) but the path towards becoming an expert is not as simple as it sounds, you need to ensure that you’re avoiding all the “Basic” mistakes that most developers do when they’re at “Beginner” level.
No matter how better a programmer you are, it is always necessary to make some mistakes, and the best part is it’s good to be informed about the blunders that you’re doing and avoid making such errors while coding. That’s why we came up with this article to highlight the 10 most common mistakes that every developer makes during their coding life and it might give you some clarity on how to avoid those mistakes. So, let’s check them out one-by-one.