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 It is always advisable not to use configuration values inside your application code directly. Rather, supply them through configuration files which are external to the code. For Example, almost all applications involve database interaction wherein they connect to a database. Obviously there are database connection parameters such as database server url, database port etc. If they are hard-coded inside the code, then for every change in those parameters (suppose for a change in database server URL), the code will have to be touched. If they are supplied through an external properties file, then changing them would only require a restart of application or notRead 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 →