Read CSV File Using Java Scanner Class

Here I am demonstrating how to read / parse CSV file using java scanner class.

For example my csv file (user.csv) looks like below.

Rockey,22,India
Bill,23,US
Sonia,23,Germany


Now I am creating java class for mapping the above fields in csv file.


How to diagnose memory leaks in java

Memory leaks doesn't have to be hard/scary/tedious problem to solve, if you follow below mentioned 3 simple steps:

Step 1: Capture baseline heap dump

You need to capture heap dump when it’s in healthy state. Start your application. Let it take real traffic for 10 minutes. At this point capture heap dump. Heap Dump is basically snapshot of your memory. It contains all objects that are residing in the memory, values stored in those objects, inbound & outbound references of those object. You can capture Heap dump can be captured using following command:


jmap -dump:format=b,file=<file-path> <pid>

where

pid: is the Java Process Id, whose heap dump should be captured

file-path: is the file path where heap dump will be written in to.

How to Avoid Liferay DXP Upgrading Pitfalls?

Timely upgrades can be proved a strategic move towards lifting the operational excellence to the next level. Experienced management individuals know very well that how the essential pieces of functionalities can greatly improve performance of process along with addressing the security challenges. Hence, they favor the technology upgrades anticipating reasonable amount of Return on Investment (ROI).

As Liferay DXP is a revolutionary version of Liferay enterprise portal launched in 2016, lot many organizations would rather opt for upgrading to Liferay DXP.

Iterate HashMap Using Java

In this tutorial, I am showing how to iterate through a HashMap using java in different useful ways.

If you are using Java 8 for the map iteration, you can use lambda expression as like method 5.

You can also use with generics as method 3, and without generics as method 4, if you are using old versions of jdk.

Convert Java InputStream to String

In this tutorial, I am showing how to convert Java InputStream to String using Plain Java, Java 8, Apache Commons IO library and Guava.

An InputStream is connected to some data streams like a file, memory bufferes, network connection, pipe etc. It is used for reading the data from above sources.

You can also see an example for convert Java String to InputStream (java String to InputStream).

What Is Garbage Collection Log? How To Enable & Analyze?

Objects are created in the memory to service incoming requests. Once requests are serviced, newly created objects will become useless (i.e. garbage). This garbage must be evicted from the memory so that there is enough room created in the memory to service the new incoming requests. If there isn’t sufficient memory, the application can experience poor response times, OutOfMemoryError, and fatal crashes.

Create ArrayList from Array In Java

In this tutorial, I am showing how to Create ArrayList from array using java in different useful ways.

1) You can use Arrays.asList(array) to convert an array to an Arraylist.
2) If you are working with java 8 you can use stream api Stream.of(array).collect(Collectors.toCollection(ArrayList::new))

3) If you are working with java 9 you can use List.of("Hello", "World"), where this list is backed by an array.

How To Check Array Contains Certain Value Java

In this example, I am showing How can I test if an array contains a certain value efficiently

In java 8 you can use Stream.of(array).anyMatch(x -> x == "world") for checking for string value (Example 1) .If it is integer value you can use IntStream.of(array2).anyMatch(x -> x == 0) (Example 2)

In java old version you can use Arrays.toString(array) to checking for string values (Example 3)