Convert windows path to unix in java

File separator is "/" on UNIX and "\" on Windows. Using FilenameUtils convert path between windows and UNIX is easily. FilenameUtils.separatorsToSystem method can help you to use correct separator.

Jackson convert json to generic object example

It is easy using Jackson to convert JSON string to Object. In this page I will show you how to convert JSON string to generic object with Jackson. TypeReference is very useful when you convert json string to generic object (like Map, List or other generic object).

Calculate time ago in java

The code below shows how to calculate relative time. Invoke getRelativeTime method by passing a timestamp.

Jackson ignore unrecognized field

You will get UnrecognizedPropertyException if you convert json string to object with unknown field. There are 2 ways to avoid this problem. Use JsonIgnoreProperties annotation or add DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES to ObjectMapper configuration. Examples are in the following.

Jackson convert object to pretty json

We use Jackson convert object to json string. If you do not add any configuration the string is plain-text without formatted. There are 2 ways to make the json pretty when using Jackson convert object to json.

Different garbage collectors in java

In this page we will go through different garbage collectors in java. I have introduced the algorithms of garbage collection in last blog. There are 7 garbage collections in hotspot virtual machine.

Algorithm of garbage collection in java

There are several garbage collectors in java. If your program is small you do not need change the default collector in virtual machine. But if your program become bigger and bigger you need think about change the JVM arguments or even change the collector of virtual machine to make it run efficiently. In this blog I will introduce the algorithm of them. In general, there are 4 algorithms to garbage collection.

Markdown quotes

It is easy to use markdown write formatted text. If you want add quotes in your text you can add > before the line. Examples like following.

Monitor IO in Linux

There are a lot of tools to monitor IO in Linux. iotop is one of the most common command to monitor IO of each process. iostat is another common commands. I will show you how to use them in this blog.

Use top command in Linux

We often use top command to see the tasks in Linux. There are many numbers in the output of top. In this page I will shortly introduce them. The output of top command is like following.

Use ESC to close Windows Explorer in Windows

As we all know, we can use Alt+F4 to close any windows in Window. But Alt+F4 is hard for us to press. Every time I have to find the F4 button. I want change the way to close windows especially for Window Explorer. Recently I found AutoHotkey can help me solve this problem. In this blog I will show you how to close Windows Explorer with ESC button.

Make a request with Apache HttpClient

Sometimes we need request the resources programmatically. Apache HttpClient is one of the best way to make a request in your project. This blog will show you how to make "Get" and "Post" request for restful resource. The structure of this project is like following.

Plus or minus date in java by joda time

Plus or minus date in java is boring. joda-time can help you finish this task easily. If you use JDK8 you may not need use joda-time, there is a new date API in JDK8. For more detail you can click here. In this blog I will show you how to use joda-time plus or minus date.

Spring unit test example

Unit test can help you correct the logic error. In this page I will show you how to use unit test in spring. I create a simple project to display a sentence in the page. The structure of this project is like following.

Spring MVC forward redirect example

You can return jsp file name in Spring MVC controller when you want client show this page. You can also add forward or redirect keyword at the front of jsp file. I will show you how to "redirect" and "forward" a page in this blog.