Posted In: Date, Java Core

Convert date string to one format to another

This function will convert date string format to another format. Test

Read More

Tags:

by , on April 2nd, 2017

Posted In: Java Core

How to run a task periodically in Java – ScheduledExecutorService

Example of using ScheduledExecutorService in a standalone program This example will check sms each 10 seconds. Program will close after one hour (sendSmsHandle.cancel(true))

Read More

Tags:

by , on March 30th, 2017

Posted In: Exception, Java Core

NullPointerException – Handle it in Enterprise Application

  NullPointerException is most common exception that will occur when you start writing real applications. NullPointerException occurs when you declare a variable but did not create an object. Object obj = null; obj.doSomething();   I am going to write about some precautions that we could take to avoid NullPointerException in real life application.   1. […]

Read More

Tags:

by , on February 23rd, 2017

Posted In: Hashmap, Java Core

Hashmap/Hashtable uses in an enterprise application – example3

Use case – We have list of objects (in this case users). We want to remove duplicate users depending on some criteria. In this example with first name and last name. We do not have source of user class. So you cannot override equals and hashcode method. Result {SuperMan=User [firstName=Super, lastName=Man], XMen=User [firstName=X, lastName=Men], RobinHood=User […]

Read More

Tags: , ,

by , on January 30th, 2017

Posted In: Java Core, Set

How to remove duplicate objects while adding to Collection and Sort – Example2

Use case – We have list of objects (in this case users). We want to remove duplicate users depending on some criteria. Then sort them. In this example with first name. Both of this can be achieved by overriding equals and Comparable.compareTo methods. Result [User [age=35, firstName=Bat, lastName=Man], User [age=35, firstName=Robin, lastName=Hood], User [age=30, firstName=Super, […]

Read More

Tags: , , , , ,

by , on January 30th, 2017

Posted In: Hashmap, Java Core

Hashmap/Hashtable uses in an enterprise application – example2

Use case – Fetch data from database with one to many relationship. Example Fetch list of users from database. Each user can have multiple roles. We have three tables 1. USER_MASTER 2. USER_ROLE_MASTER 3. USER_ROLE_MAPPING Our User object will look like this

Read More

Tags: ,

by , on January 29th, 2017

Posted In: Hashmap, Java Core

Hashmap/Hashtable uses in an enterprise application – example1

Comparing file data You have two files. First is master file and second is subset data. Use case is to check sample data against master file and see if it is valid. For this example you have user master data. You want to check validity of sub set user data. Result [User [userId=2, age=30, firstName=Super1, […]

Read More

Tags: , ,

by , on January 26th, 2017

Posted In: Java Core, Set

How to remove duplicate objects while adding to Collection – Example1

You have list of objects (in this case users). You want to remove duplicate users depending on some criteria. You could iterate through the list ,check some condition and remove duplicates or you could use little simpler approach using HashSet and overridden equals method as below. Result [User [age=30, firstName=Super, lastName=Man], User [age=35, firstName=Bat, lastName=Man], […]

Read More

Tags: , , , ,

by , on January 25th, 2017

  • Categories