How to fix "illegal start of expression" error in Java

The "illegal start of expression" error is a compile time error when the compiler finds an inappropriate statement in the code. The java compiler, javac, compiles your source code from top to bottom, left to right and when it sees something inappropriate at the start of an expression, it throws "illegal start of expression" error. The most common reason of this is a missing semi-colon. You might know that every statement in Java ends with a semicolon, but if you forget one, you won't get an error that there is a missing semi-colon at the end of statement because the compiler doesn't know the end. When compiler checks the next statement it sees illegal start because an earlier statement was not terminated. The bad part is that you can get tens of "illegal start of expression" error by just omitting a single semi-colon or missing braces, as shown in the following example.

Binary tree InOrder traversal in Java using Recursion

The InOrder traversal is one of the three popular ways to traverse a binary tree in Java, other two being preOrder and postOrder. During the inOrder traversal algorithm, left subtree is explored first, followed by root, and finally right subtree. You start traversal from root then goes to left node, then again goes to left node until you reach a leaf node. At that point of time, you print the value of the node or mark it visited and moved to right subtree. Continuing the same algorithm until all nodes of the binary tree are visited. The InOrder traversal is also known as left-node-right traversal or LNR traversal algorithm. Similar to the preOrder algorithm, it is also a depth-first algorithm because it explores the depth of binary tree before exploring siblings.  Since it is one of the fundamental binary tree algorithms it's quite popular in programming interviews. They are also the basis to learn more advanced binary tree algorithm, hence every programmer should learn, understand and know how to implement in-order and other traversal algorithms.

How to fix "class, interface, or enum expected" error in Java

If you have ever written Java programs using Notepad or inside DOS editor, then you know that how a single curly brace can blow your program and throw 100s of error during compilation. I was one of those lucky people who started their programming on DOS editor, the blue window editor which allow you to write Java program. I didn't know about PATH, CLASSPATH, JDK, JVM, or JRE at that point. It's our lab computer where everything is supposed to work as much our instructor wants. Since we don't have the internet at that point of time, we either wait for the instructor to come and rescue us and we surprise how he solve the error by just putting one curly brace and all errors mysteriously go away.  Today, I am going to tell you about one such error,  "class, interface, or enum expected".   This is another compile time error in Java which arises due to curly braces. Typically this error occurs when there is an additional curly brace at the end of the program.