Spring Boot in a Single File

Over the years spring has become more and more complex as new functionalities have been added. Just visit the page-https://spring.io/projects and we will see all the spring projects we can use in our application for different functionalities. If one has to start a new spring project we have to add build path or add maven dependencies, configure application server, add spring configuration . So a lot of effort is required to start a new spring project as we have to currently do everything from scratch....

April 11, 2017 · 5 min · Rezha Julio

Manage Your JVM Environment with SDKMAN

SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. It provides a convenient Command Line Interface (CLI) and API for installing, switching, removing and listing Candidates. Formerly known as GVM the Groovy enVironment Manager, it was inspired by the very useful RVM and rbenv tools, used at large by the Ruby community. Install Software Development Kits for the JVM such as Java, Groovy, Scala, Kotlin and Ceylon....

April 10, 2017 · 2 min · Rezha Julio

Updating interfaces by using default methods

Take the following interface: public interface Cooking { public void fry(); public void boil(); public void chop(); } To add new functionality, simply adding a new method to Cooking called microwave() will cause problems. Any class that previously implemented Cooking will now have to be updated in order to function again. To avoid this, give microwave() a default implementation: public interface Cooking { public void fry(); public void boil(); public void chop(); default void microwave() { //some code implementing microwave } } As microwave() already has a default implementation defined in the Cooking interface definition, classes that implement it now don’t need to implement microwave() in order to work....

April 9, 2017 · 1 min · Rezha Julio

Converting Stacktrace to String

To store stack trace as a string, you can use Throwable.printStackTrace(...) For example: public static String getStackTrace( Throwable throwable ){ Writer result = new StringWriter(); PrintWriter printWriter = new PrintWriter(result); throwable.printStackTrace(printWriter); return result.toString(); } In the above example, getStackTrace takes a Throwable as a parameter and uses printStackTrace to print it to a PrintWriter output stream. This output is collected by the StringWriter and converted to a string using StringWriter.toString()....

April 8, 2017 · 1 min · Rezha Julio

Synchronized Statement in Java

synchronized statements can be used to avoid memory inconsistency errors and thread interference in multi-threaded programs. When a thread executes code within a synchronized statement, the object passed as a parameter is locked. When writing a synchronized block, the object providing the lock must be specified after the synchronized keyword: public class Rezha { private int sum; public void addToSum(int value) { synchronized(this) { sum += value; } } } In this example the object providing the lock is this, which is the instance of Rezha that the method is being called in....

April 7, 2017 · 1 min · Rezha Julio