Posts Tagged ‘Java’

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 ...

How to Redirect Standard Output/Error in Java

System.out and System.err stream objects are mapped to "standard" output and error stream respectively. By default, Java display standard output/error on display console.Thus, when we print a statement using System.out:System.out.println("Hello World!"); System.err.println("errr.. Hello World!");It prints the messages to default console.What if you want to reassign the "standard" output and error stream? Lets say you want to redirect all those standard out messages in a ...

Read / Write Excel file in Java using Apache POI

Read / Write Excel file in Java using Apache POI
Apache POI is a powerful Java library to work with different Microsoft Office file formats such as Excel, Power point, Visio, MS Word etc. The name POI was originally an acronym for Poor Obfuscation Implementation, referring humorously to the fact that the file formats seemed to be deliberately obfuscated, but poorly, since they were successfully reverse-engineered.In this tutorial we will use Apache POI library ...

How to update JSTL Locale dynamically

How to update JSTL Locale dynamically
When you use JSTL format tag <fmt:formatDate> and <fmt:formatNumber>, JSTL automatically takes care of locale resolution. Depending on the browser's locale setting JSTL will display the date and numbers.You may want to override this default behavior. For example in case where you want to display date format only in en_US locale irrespective of user locale setting of browser. Or you may want to store user ...
Tags: , ,

Eclipse: Ignore “not declare static final serialVersionUID” warning

Eclipse: Ignore
Whenever you write a Java class in Eclipse which implements java.io.Serializable interface, you'll get this warning:The serializable class XXXX does not declare a static final serialVersionUID field of type longWhy do we need serialVersionUID? Whenever we implement java.io.Serializable interface, we explicitly tell JVM that this class can be serialized. Meaning, we might convert object of this ...

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: ,

Java: Passing Array to Oracle Stored Procedure

This tutorial guides us on how to pass Array objects from Java to stored procedures in Oracle and also, how to retrieve an array object in Java.All PLSQL arrays can not be called from java. An array needs to be created as TYPE, at SCHEMA level in the database and then it can be used ...

Java MD5 Hashing & Salting: Secure Your Passwords

Java MD5 Hashing & Salting: Secure Your Passwords
The MD5 Message-Digest Algorithm is a widely used cryptographic hash function that produces a 128-bit (16-byte) hash value. MD5 has been employed in a wide variety of security applications, and is also commonly used to check data integrity. MD5 was designed by Ron Rivest in 1991 to replace an earlier hash function, MD4. An MD5 hash ...
Page 1 of 812345...Last »