org.postgresql.util.PSQLException: ERROR: invalid input syntax for integer: “”

Recently I was working on a project where I faced an issue. A column in a GUI was sorting properly for sometime but stopped working suddenly one day. Let us start debugging the issue. Exception org.postgresql.util.PSQLException: ERROR: invalid input syntax for integer: “” Problem Code So we starting looking at the code and found a query … Read more

ExecutorService tutorial

The ExecutorService avaliable since java 1.5 is an Executor that provides the possibility to track the progress and manage termination of the asynchronous tasks. In the below examples we are going to look at how to provide the unit of code to be executed asynchronously to the ExecutorService. We will then do the shutdown of … Read more

Largest of three numbers java program

Overview Here is a java program to find the largest of the three numbers.  In this example the user will input three numbers and the program will output the largest number Largest of three numbers Example output:

Generate Unique id using UUID in java

Java provides a class java.util.UUID which can be used to generate a randon UUID. Here is a sample code to create a UUID. Output: So the above code can be used to assign ids to entities e.g; Suppose you are writing Person java class and want each person to have a unique id, you can use … Read more

Convert an int to a String in java

How to convert an int to a String in java? Integer to String conversion can be done using a number of options. Let us look at some of them. String.valueOf(int) String class provides utility methods to convert an int to a String. String.valueOf(int) method is very widely used and is considered a good practice for conversion. … Read more

Download an Excel using Servlet

How to download an Excel using Servlet? Create a workbook using any frameworks and write out the created workbook to response.getoutputstream(). For creating the excelsheet I am using apache poi. Set the content type of response to “application/vnd.ms-excel” and set response header as   “Content-Disposition”, “attachment; filename=YourExcelName.xls”. Download an Excel using Servlet Example   Discussion Should I close HttpServletResponse.getOutputStream()? You … Read more

Flatten a list of Strings

In this tutorial we would see at various ways to concatenate a list of strings and insert a separator “,”  in between the concatenated strings. Java 8 output Using org.apache.commons.lang3.StringUtils output : Using loop See concatenation comparison for choosing a better way for string concatenation. output