Posts

List of all countries in JSON

[ { "name" : "Afghanistan" , "code" : "AF" }, { "name" : "land Islands" , "code" : "AX" }, { "name" : "Albania" , "code" : "AL" }, { "name" : "Algeria" , "code" : "DZ" }, { "name" : "American Samoa" , "code" : "AS" }, { "name" : "AndorrA" , "code" : "AD" }, { "name" : "Angola" , "code" : "AO" }, { "name" : "Anguilla" , "code" : "AI" }, { "name" : "Antarctica" , "code" : "AQ" }, { "name" : "Antigua and Barbuda" , "code" : "AG" }, { "name" : "Argentina" , "code" : "AR" }, { "name" : ...

Singleton Design Pattern for Utility Clases

public class DateUtility {   private static DateUtility instance;         public static DateUtility getInstance() {    synchronized (DateUtility.class) {      if (instance == null) {        instance = new DateUtility();      } } return instance; }  public String convertDateToString(Date date) { ....................................... } } Usage : DateUtility.getInstance().convertDateToString();

Add PMD rules into your project

pom.xml <properties>              <pmd.failOnViolation>true</pmd.failOnViolation> </properties> <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-pmd-plugin</artifactId>             <version>3.1</version>             <executions>               <execution>                 <id>pmd</id>                 <phase>verify</phase>               ...

Convert XSD element choice with "maxOccurs=unbounded" into individual list of objects

Problem defined here: http://archive.oreilly.com/pub/a/onjava/2003/12/10/jaxb.html?page=2 Plugins used: https://github.com/highsource/jaxb2-basics/wiki/JAXB2-Simplify-Plugin XSD Sample <xs:schema xmlns:tns="http://www.omnicogroup.com/FPF/namespace" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.omnicogroup.com/FPF/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema">   <xs:element  name="transaction">     <xs:complexType>       <xs:sequence>         <xs:choice maxOccurs="unbounded">           <xs:element  name="TransactionDetails">             <xs:complexType>               <xs:sequence>        ...

RESTful API + POST + json body

Library :        <dependency>             <groupId>com.fasterxml.jackson.core</groupId>             <artifactId>jackson-databind</artifactId>             <version>2.7.2</version>         </dependency> Mapper Class public class MapperUtil {     private final static ObjectMapper mapper = new ObjectMapper();     public static <T> T readAsObjectOf(Class<T> clazz, String value) {         try {             return mapper.readValue(value, clazz);         } catch (IOException e) {             logger.error(e.getMessage());      ...

JDBC Data Types Equivalent in Java

SQL JDBC/Java setXXX getXXX VARCHAR java.lang.String setString getString CHAR java.lang.String setString getString LONGVARCHAR java.lang.String setString getString BIT boolean setBoolean getBoolean NUMERIC java.math.BigDecimal setBigDecimal getBigDecimal TINYINT byte setByte getByte SMALLINT short setShort getShort INTEGER int setInt getInt BIGINT long setLong getLong REAL float setFloat getFloat FLOAT float setFloat getFloat DOUBLE double setDouble getDouble VARBINARY byte[ ] setBytes getBytes BINARY byte[ ] setBytes getBytes DATE java.sql.Date setDate getDate TIME java.sql.Time setTime getTime TIMESTAMP java.sql.Timestamp setTimestamp getTimestamp CLOB java.sql.Clob setClob getClob BLOB java.sql.Blob setBlob getBlob ARRAY java.sql.Array setARRAY getARRAY REF java.sql.Ref SetRef getRef STRUCT java.sql.Struct SetStruct getStruct