XML stands for eXtended Markup Language and is a widely used standard for transmitting information across systems mainly due to the flexibility it provides in creating the structure and data it can contain. That is, application developers can create their own structure which suits their application as there are no pre-defined tags in XML. Scenario Since it is a widely used standard, there arises a vital requirement to create an XML document either in the form of a String or a physical file from java application. Practical scenario isRead More →

JDBC stands for Java DataBase Connectivity and is a technology for database connectivity from java program. JDBC is a collection of multiple interfaces and classes which provides methods for database connection and operations. Operations include executing SQL queries for fetching records, inserting and updating or deleting data from a database table directly from a java program. For performing any operation on a database using JDBC, requires some steps. They are :Read More →

A typical java application uses some values which are not suitable to be given in code such as log generation path, output location, configuration file path, timeout values etc. Since these values vary from system to system and user to user, their values can not be pre-fixed. One user may want his logs to be generated in “myLogs” folder, another user may want the logs to be generated in “appLogs” folder. If given in code, they cannot be changed without developer intervention. Further, this change would require a re-build of code.Read More →

It may happen that you need to add some days to a particular date and the resultant date is falling on either Saturday or Sunday. So you have to calculate the next working date. Practical Application : This is usually required in payments industry where the dates are written to files and these files are then uploaded to server but the server rejects the file if the date is a holiday. In such cases the date should be checked to be a holiday before writing it to file and incremented to a working day and then written to the file so that it is notRead More →

Comparison between two dates is a task that every developer has to perform. Comparison implies determining which date is earlier or later of the two dates. It would be great if we are aware of different ways in which we can achieve it. Below are some of the ways for comparing two dates using java api classes and their methods.Read More →

Overall notion of Singleton class lies in getting one and only one instance of the class. Much of our functionality relies on the base that there will be only one object of a class we intentionally designed to be Singleton. What if the same class produces more than one object in some scenario? Woaaah!!! Our code blows away.Read More →

Sort list of objects on a field Suppose you have a list which contains objects of your own class rather than java’s built in classes such as java.lang.Integer, java.lang.String etc. Now you want this list to be sorted on a particular field of this class. Let’s say we have a User class which contains user details such as name, age, address etc., and we have a list of various users. Now we want a list wherein users are listed in the order of their increasing age. That is, we need to sort the above list in the order of age. Collections.sort method You can sortRead More →

Iterating over a collection is a task that most developers are required to perform during their development task and most of us keep on using the same way which we have used earlier though there are many ways to do this. In this post I am going to list down all those ways. We all might be familiar with these ways. Still, keep on reading to refresh!!! First let’s initialize a list List list = Arrays.asList(new String[]{ “first”,”second”,”third”,”fourth”, “fifth” }); Now let’s begin iteration: Method 1: Using for loop for (int count = 0; count < list.size(); count++) { System.out.println("Item:: " + list.get(count)); } DetailRead More →

There may be a scenario, if we want to determine whether a string is completely numeric or not, such as we want a user to input a number and our program should multiply it by 5 and return the result. User is a human. He may mistakenly input an alphanumeric string by mistake or to check the correctness of our program. Off course, we would not like to show an exception trace to the user instead of the result. Better we check the input for its validity before processing. Below are various ways using which we may check that an input String is completely aRead More →