Java 8 - String.join() Example

I have been writing about new features of Java SE 8 since it's release in March 2014. Initially, my focus areas on much talked about lambda expressions and streams, but slowly I realize that Java 8 is not just about them. It has many more new features which will help Java developers in their day-to-day job as much lambdas and streams. One of them is the ability to join the String with any delimiter. It has added a class called StringJoiner in java.util package which we have seen earlier, but it has also added a new method on String class, the join() method, which finally allows you to join Strings in Java. You might have faced scenarios in past where you have a list of String or an array of String and you want to join them by a comma. Unfortunately, Java didn't have anything like Android's TextUtils.join() or JavaScript's Array.join() method which can join String on a delimiter.

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.