Posts Tagged ‘java 5’

Dynamic Property Loader using Java Dynamic Proxy pattern

While reading through Stackoverflow, I came up to this interesting question: Java Properties File binding to Java Interface. The idea is simple but quite helpful.Basically we create an interface like:interface LoginConstants extends Constants { @DefaultStringValue("Welcome to my super app") @Key("appDescription") String appDescription();@DefaultStringValue("Ok") @Key("okButtonLabel") String okButtonLabel(); }And whenever we want to use ...

Java: How to Load CSV file into Database

Java: How to Load CSV file into Database
Loading CSV file into Database can be cumbersome task if your Database provider does not offer an out of box feature for this. Most of the time you'll spend up in creating valid insert statements and putting up values escaping all special characters. Importing CSV files gets a bit complicated when you start doing things like ...

Read / Write CSV file in Java

Read / Write CSV file in Java
If you want to work with Comma-separated Files (CSV) in Java, here's a quick API for you.As Java doesn't support parsing of CSV files natively, we have to rely on third party library. Opencsv is one of the best library available for this purpose. It's open source and is shipped ...
Tags: ,

Check if String is valid Date in Java

In Java, we play a lot with Dates. Here's one more scenario. You have a string which has date in it. You want to convert it into a valid java.util.Date object. Now in Java you can convert a String to Date using SimpleDateFormat class. But we will add a little more complexity on ...
Tags: ,

Hibernate One To One Annotation Mapping Tutorial

Let us understand how One-to-one relationship is implemented in Hibernate using Annotations. For this we will use our previous article One-to-one mapping in Hibernate using XML mapping and enhance it to support Annotations.Tools and Technologies used in this article:Java JDK 1.5 above MySQL 5 above Eclipse 3.2 above Hibernate 3 above Maven 3 above1. Database with One-to-one relationship tables We will use the same tables we created in our ...

Convert String to Enum Instance in Java

Recently while working in one of the requirement, I had to convert String values to Enum. I didn't realize there is a simplest way of doing this. Here is the solution.Whenever an ENUM is complied in Java, two static methods are added by compiler called valueOf() and values(). We can use valueOf() method to convert any String value to ENUM. For example lets say we ...
Tags: , ,

Static Import in Java: New way to Import things in Java!

Static Import is a new feature added in Java 5 specification. Java 5 has been around the corner for some time now, still lot of people who are new in Java world doesn't know about this feature.Although I have not used this feature in my work, still it is interesting to know about.What is ...

Varargs in Java: Variable argument method in Java 5

Varargs in Java: Variable argument method in Java 5
I think I am late for writing about varargs. The feature of variable argument has been added in Java 5 since its launch. Still I will write something about varargs. varargs has been implemented in many languages such as C, C++ etc. These functionality enables to write methods/functions which takes variable length of arguments. For example the ...