Java abs() Method

Math.abs() method gives the absolute value of the passed argument. This method accepts arguments of type  int, float, long, double. Avaliable methods   Simple Example output:   Real World Example Problem I need the difference between two dates in minutes. The result should be always a positive number. Solution So here is my utility method … Read more

Two Sum (Java) – Leetcode

Problem: Given an array of integers, return indices of the two numbers such that they add up to a specific target. Example   Solution Java Solution Output Analysis Time complexity depends on the put and containsKey operations of HashMap which is normally O(1). Time complexity of this solution is O(n). Space complexity depends on the … Read more

upgrade jaxws-rt 2.2.1 to 2.2.10 with SpringBeanAutowiringSupport

Recently I did an upgrade of my webapp which was using jaxws-rt version 2.2.1 to the currently latest version which is 2.2.10.  Here I am listing the issues that I faced while upgrade. Versions Java 7 apache-tomcat-7.0.57 spring- 3.1.1.RELEASE jaxws-rt-2.1.1 Webservice When I tried to updgrade the jaxws-rt, I had issues with spring @Autowired not working … Read more

WSServletContextListener contextInitialized twice

Today I was trying to upgrade the jaxws-rt in my project. I was using version 2.2.1. I tried to upgrade to version 2.2.10 (latest right now).  And i was deploying my war file to tomcat 7.0.57. After changing the version, on deploy i used to get the contextinitialized message twice in the catalina.out. So  the … Read more

Java MongoDB : Insert a document

In this tutorial we will see how to insert a document in mongodb using java driver. To create the document using the Java driver, we use the Document class.   In this example we will also create an embedded document. Tools used mongo java driver : 3.3.0 mongodb : 3.2.8 maven : 3 java : … Read more

Java MongoDB – Auto Sequence ID example

In this tutorial, we will show you how to generate an auto-incrementing sequence id in MongoDB using Java. Here is the clean example and we will implement it in java. Tools Used Mongodb version :  3.2.8 Mongo Java driver : 3.3.0 Java version: 1.7 Eclipse : 4.5 Maven dependency Java Example  

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