Microsoft excel is the most widely used program to maintain data. Hence it becomes vital that the data from a java program be directly written to an excel file in different rows and columns. Java itself does not provide any features to perform excel related operations but there are external libraries written in java which support this. Two of the common libraries are Apache POI and jexcel (or jxl). Both of them provide convenient methods to handle excel files. This post will be using jexcel (or jxl) api for its demonstration.Read More →

Most applications require calculating current date for different reasons. It may be for logging events, for saving the creation, updation or deletion time of entities, recording the login details of a user and so on. Java provides different methods to calculate current date and time. Following article explains different methods to obtain current date and/or time in java.Read More →

What is Stack ? A linear data structure which stores newly added items at its top and retrieves newly added items from its top. Consider a pile of books where each new book added to the pile is placed at its top and at the time of removal, the book at the top is removed. A stack works on LIFO (Last In First Out) principle and supports only two operations :Read More →

Practical Scenario Suppose your application has to read an XML file and store its contents in a database such as each set of nodes is created as a record. For Example, there are multiple employee nodes with employee details in your xml and you have to store each employee details as a record in database. The process would be pretty easy if you have some mechanism to get the employee details form the XML in the form of java objects as then you could iterate those objects and store them by using JDBC or directly save them using any ORM framework (such as Hibernate).Read More →

Scenario Suppose your application fetches a record from a database and it needs to create an XML out of it. There are chances that your application uses an ORM framework such as Hibernate and the database record is fetched in the form of entity classes. Now you have two ways, iterate over the object properties and create each XML node manually using the XML DOM apis (How to create XML from Java program using DOM parser) or follow the approach detailed here.Read More →

Scenario In practical applications, when you create a profile (of a User or a Company say), you are required to maintain a picture or an icon to uniquely identify the entity so that every time the user or company visits the application, it finds the same picture which was last uploaded over the application. For Example, when a Facebook user uploads his picture, it is added to his photos list and every time he logs in, he can see the picture in that list. This can be done when you save the picture somewhere and retrieve it from there every time its required. A databaseRead More →

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 →

An Exception is an undesirable state which arises out of some unexpected condition or scenario which was not handled during application development or due to some unexpected circumstances arising in the execution environment. Java provides support for handling exception conditions during application execution using try–catch blocks. Exceptions in java are categorized into two parts : Checked Exceptions Exceptions which need to be declared or handled during application development are checked exceptions. They are called checked because their appropriate handling is checked at compile time by the compiler. Handling implies either they are caught in a try-catch block or are declared to be thrown (using throwsRead More →