10 Examples of Joining String in Java 8 - StringJoiner and String.join()

It's quite common in day to day programming to join Strings e.g. if you have an array or List of String let's say {Sony, Apple, Google} and you want to join them by comma to produce another String "Sony, Apple, Google", there is not an easy way to do it in Java. You need to iterate through array or list and then use a StringBuilder to append a comma after each element and finally to remove the last comma because you don't want a comma after the last element. A JavaScript-like Array.join() method or join() method of Android's TextUtils class is what you need in this situation, but you won't find any of such method on String, StringBuffer, StringBuilder, Arrays, or Collections class until Java 8. Now, you have a class called StringJoiner which allows you to join multiple String by a delimiter.

Why use Log4j logging vs System.out.println in Java

Printing messages to the console is an integral part of development, testing and debugging a Java program. If you are working on a Server side application, where you can not see what's going on inside the server, your only visibility tool is a log file; without logs, you can not do any debugging or see what's going on inside your application. Though, Java has pretty handy System.out.println() methods to print something on console, which can also be routed to log file but not sufficient for a real-world Java application. If you are running a Java program in Linux or any UNIX based system, Log4j or SLF4j or any other logging framework offers a lot more features, flexibility, and improvement on message quality, which is not possible using the System.out.println() statement.

How to install Maven on Windows 7,8 or 10?

There is no difference in installing Maven on Windows7, Windows 8, Windows 8.1 or Windows 10, you can follow the same steps to install Maven in any version Windows operating system. Installing Maven is very easy, just download the Apache Maven ZIP file from Apache Maven Project website (https://maven.apache.org/download.cgi). You can download the apache-maven-3.3.9-bin.zip for using Maven in your 64-bit Windows machine. Remember, Maven 3.3 requires JDK 1.7 or above to run, so make sure you already installed JDK 7 or JDK8. Once you download the binary distribution of Maven, half of the job is down. Now, you only need to extract the binary distribution and add the bin folder in PATH or add a couple of environment variable e.g. M2, M2_HOME into your Windows machine.