Monday, 3 October 2016

Finding fibonacci number series in java


Fibonacci series : a series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, 13,21,34 ,55,89 etc.

Solution1 using Recursion : 


/**code to get nth fibonacci number **/
public static int fibonacciNumbers(int n){
if(n <= 0 ||  n == 1){
return 1;
} else {
return fibonacciNumbers(n-1) + fibonacciNumbers(n-2);
  }
}
public static void main(String[] args){
int numberOfFibonacci = 15;
long start = System.currentTimeMillis();
java.util.List<Integer> fibnocList = new ArrayList<>();
for (int i = 0; i <= numberOfFibonacci; i++) {
fibnocList.add(fibonacciNumbers(i));
}
System.out.println(fibnocList);
long end = System.currentTimeMillis();
System.out.println("total time taken=" + (end -start)  +  " ms");
}
Output :
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]
total time taken=1 ms
Note : Till 40th element its able to print fibonacci numbers after that time of execution
increase exponentially.
Time complexity is O(n) & Space complexity O(n).


Solution2 using  without Recursion : 



       
/**printing the series of fibonacci number upto length n  **/

public static void fibonacciSeries(int n){
int[] fibArray = new int[n];
if(n < 0 ){
System.out.println("invalid value");
} else {
  for (int i = 0; i < n; i++) {
  if(i== 0 || i==1){
  fibArray[i] =1;
  } else {
  fibArray[i] =  fibArray[i-1] + fibArray[i-2];
  }
}
  }
System.out.println("fibonacci number upto lenth n=" + n + " and series=" + Arrays.toString(fibArray));
}
public static void main(String[] args){
long start = System.currentTimeMillis();
fibonacciSeries(20);
long end = System.currentTimeMillis();
System.out.println("total time taken=" + (end -start)  +  " ms");
}
Note : Time complexity O(n) and space complexity is in place as using the arrays.
Output: 


fibonacci number upto lenth n=20 and series=[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,
233, 377, 610, 987, 1597, 2584, 4181, 6765]
total time taken=0 ms


In both the solutions number 2 solutions is best possible solution with respect to time and space complexity.

Enjoy the code and enjoy the journey of Java!!!!

Sunday, 2 October 2016

Finding all permutations of a String in Java


There are many ways of finding the permutations of a string . From the mathematics point of view there can be n! permutations where n is number of  character in the string.

Solution1  :

Use recursion.
  • Try each of the letters in turn as the first letter and then find all the permutations of the remaining letters using a recursive call.
  • The base case is when the input is an empty string the only permutation is the empty string.

       
public static void perm(String s){
if(s ==null || s.isEmpty()){
return;
}
perm("", s);
}
public static void perm(String prefix , String s){
if(s.length() == 0){
System.out.println(prefix);
} else {
int stringLength = s.length();
for (int i = 0; i < stringLength; i++) {
perm(prefix + s.charAt(i), s.substring(0, i) + s.substring(i+1));
}
}
}
public static void main(String[] args){
perm("abc");
}
output :
abc
acb
bac
bca
cab
cba
Time Complexity would be : O(n*n!) as for each element you required n-1 permutations of the
string so overall n! permutations.
Space complexity would be : O(n)
Note 2: Time taken to execute the method for various length of string:

for n=10 and 10!=3628800 number and total time taken to complete the output is = 93.31 sec
for n=9 and 9!=362880 number and total time taken to complete the output is = 6.312 sec
for n=8 and 8!=40320 number and total time taken to complete the output is = 365 ms
for n=7 and 7!=5040 number and total time taken to complete the output is = 92 ms
for n=6 and 6!=720 number and total time taken to complete the output is = 43 ms
for n=5 and 5!=120 number and total time taken to complete the output is =4 ms
for n=4 and 4!=24 number and total time taken to complete the output is = 1 ms
for n=3 and 3!=6 number and total time taken to complete the output is = 1 ms
for n=2 and 2!=2 number and total time taken to complete the output is = 0 ms

Solution2 :
Use recursion and swapping.
  • Try each of the index in turn as the current index and then find all the permutations of the remaining letters using a recursive call and swapping the element to the current index.
  • The base case is when the input  is an 0 index the only permutation is the permutated string.

private static void doPerm(StringBuffer str, int index){
    if(index <= 0)
        System.out.println(str);          
    else {
    int n = str.length();
        int currPos = n-index;
doPerm(str, index-1);
        for (int i = currPos+1; i < n; i++) {
            swap(str,currPos, i);
            doPerm(str, index-1);
            swap(str,i, currPos);
        }
    }
}
private  static void swap(StringBuffer str, int pos1, int pos2){
    char t1 = str.charAt(pos1);
    str.setCharAt(pos1, str.charAt(pos2));
}
public static void main(String[] args){
long start = System.currentTimeMillis();
String str = "abcd";
StringBuffer strBuf = new StringBuffer(str);
    doPerm(strBuf,str.length());
long end = System.currentTimeMillis();
System.out.println("total time taken=" + (end -start)  +  " ms");
}
Time Complexity would be : O(n*n!) as for each element you required n-1 permutations of the
string so overall n! permutations.But the use of String buffer and in memory swapping
the elements reduces the execution time.
Space complexity would be : O(n)
Note 2: Time taken to execute the method for various length of string:

for n=10 and 10!=3628800 number and total time taken to complete the output is = 33.31 sec
for n=9 and 9!=362880 number and total time taken to complete the output is = 3.312 sec
for n=8 and 8!=40320 number and total time taken to complete the output is = 185 ms
for n=7 and 7!=5040 number and total time taken to complete the output is = 42 ms
for n=6 and 6!=720 number and total time taken to complete the output is = 13 ms
for n=5 and 5!=120 number and total time taken to complete the output is =4 ms
for n=4 and 4!=24 number and total time taken to complete the output is = 1 ms
for n=3 and 3!=6 number and total time taken to complete the output is = 1 ms
for n=2 and 2!=2 number and total time taken to complete the output is = 0 ms
This solution is seems to be more  optimal solution as compare to solution 1.So 
highly recommended. 

solution 1 & solution 2 are taking same time upto 5 elements in the string but as we grow larger say upto 10 characters , solution 2 fit the most with respect to the time complexity and taking 1/3rd time as compare to solution1. It uses the technique to swap the elements in memory and use of string buffer reduces the time.
Solution 2 is highly recommended for finding the permutations of the string.

Two solutions are being mentioned and compare with the time . Clearly 2nd solution is much more optimal solution and its uses in memory swapping the element and making permutation of the other string excluding the current index character. Above two solutions gives all the permutations of a string while to remove the duplicates output need to be write in a Set to avoid any duplicates.

Solution 3 without recursions and without duplicates :  



      
public static Set<String> generatePermutation(String input){
Set<String> set = new HashSet<String>();
if(input == null){ return null; }
if (input == "") {return set;}
Character a = input.charAt(0);
if (input.length() > 1){
input = input.substring(1);
Set<String> permSet = generatePermutation(input);
for (String x : permSet){
for (int i = 0; i <= x.length(); i++) {
set.add(x.substring(0, i) + a + x.substring(i));
}
}
} else {
set.add(a + "");
}
return set;
}
public static void main(String[] args){
long start = System.currentTimeMillis();
String str = "AACC";
System.out.println(generatePermutation(str));
long end = System.currentTimeMillis();
System.out.println("total time taken=" + (end -start)  +  " ms");
}
Output :
[CACA, ACAC, ACCA, AACC, CCAA, CAAC]
total time taken=1 ms
Note : No duplicates are in the output and this is the most optimal solution for
finding the permutations  of a string.       
 


Enjoy coding and enjoy Java!!!!!

Tuesday, 30 August 2016

Virus affected folder having files is not displaying - How to see the files on Windows


In case of virus affected folders are many time doesn't show the content in the folder. If one open the folder properties then number of files are shown but on entering folder , no file is visible.

To resolve it following 2 steps are to be followed : 

1 .  Show hidden Files,Folders and Drives : 

Go to Control Panel  --> Appearance  and Personalization  --> Folder Options -- > Show hidden files and folders -- > Click on radio button [Show hidden files,folders and drives] 

Now all the hidden files , folders and drives would be visible.

In case of  files are still missing in the folder though size of the folder is showing number of files present in the folder --> follow the step2 

2. Displaying the hidden files of the folder due to affect of  Virus : 

a ) Use some antivirus to scan the folder to clean up the virus.
b)  Go to Start --> Run --> Type cmd and press Enter.

Assuming your drive letter as F: where a folder is affected by virus and folder is not displaying any files though they are exist in the folder.

Copy this command :

attrib -h -r -s /s /d f:\*.*

copy the above command --> Right-click in the Command prompt to paste it --> Enter

Now check your drive for the files in the folder -- > It will display entire files in the folder.

Enjoy the virus free access of the files in your drives. Don't forget to protect your system with an antivirus.

Friday, 12 August 2016

Generating the Pdf from HTML

Generating PDF from PDF template is a time & memory consuming process. It's sometime not feasible to use it while processing larger data set.

One of the very good features of creating PDF using HTML is appropriate and simple to use and easy to maintain.

There are many libraries are available for reference  PDF library link 

I will be discuss here itextpdf library of creation as it is simple and easy to maintain. For the Maven based project pom entry :

<!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf -->    
<dependency>
    &lt;d&gt;<groupid>com.itextpdf</groupid>
    <artifactid>itextpdf</artifactid>
    <version>5.5.9</version>
</dependency>
   
 

Following is the code snippet to use for conversion of html into pdf :
import com.itextpdf.text.Document;
import com.itextpdf.text.html.simpleparser.HTMLWorker;
import com.itextpdf.text.pdf.PdfWriter;
@SuppressWarnings("deprecation")
public static void createPDFUsingHtml(String htmlFilePath,String outputPDFFilePath){
try {
Document document = new Document();
OutputStream file = new FileOutputStream(outputPDFFilePath);
PdfWriter writer = PdfWriter.getInstance(document,file );
///if want to keep password encrypted then add password here else passwordless pdf will be created
writer.setEncryption("".getBytes(), "".getBytes(),PdfWriter.ALLOW_PRINTING, PdfWriter.STANDARD_ENCRYPTION_128);
document.open();
HTMLWorker htmlWorker = new HTMLWorker(document);
String htmlcontent = readFile(htmlFilePath);
htmlWorker.parse(new StringReader(htmlcontent));
document.close();
} catch (Exception e)
{
e.printStackTrace();
}
}

When run a main  program on the html  test.html


   
public static void main(String[] args){
createPDFUsingHtml("/Users/test/test.html", "/Users/test/test.pdf");
}

Output of the created pdf : test.pdf

Your PDF is ready with a very  simple way and doesn't require any extra effort of creation of the pdf template. Instead just make a simple HTML  template which can be created from any online tool .
Just make your html ready and then your PDF will be created immediately.

Enjoy Coding !!!!



Wednesday, 10 August 2016

Reading file in Java


Reading file data is something used day to day life of a developer. Java had continuously  worked on the improvisation of file reading and writing as these are heavy process sometime and memory consuming.

Lets take case by case :

1. Reading a file data using FileReader : 

Method to used :

public static String readFile(String filePath) {
  StringBuilder sb = new StringBuilder();
  BufferedReader br = null;
  try {
   br = new BufferedReader(new FileReader(filePath));
   String line = br.readLine();
   while (line != null) {
    sb.append(line);
    sb.append("\n");
    line = br.readLine();
   }
  } catch(Exception e){
   e.printStackTrace();
  } finally {
   if(br!=null){
    try {
     br.close();
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  }
  return sb.toString();
 }   


2. Reading a file data using NIO: 

Method to used :

public static String readFileUsingNio(String filePath){
String content = null;
try {
content = new String(Files.readAllBytes(Paths.get(filePath)));
} catch (Exception e) {
e.printStackTrace();
}
return content;


There are other libraries available of apache common etc where utility of reading file is given.

But as an Architect I feel adding Non Blocking I/O  features in Java 7  is being one of the finest revolution in the I/O  operation . It is always recommended to use Java features are they are fully trusted and robust. Using lesser third party libraries is always advisable as lesser dependencies means lesser chances of getting the bug and code maintainability remains cleans. 

Wednesday, 29 June 2016

To check if object attribute exist or not in Freemarker


Starting from freemarker 2.3.7, you can use this syntax :

${(object.attribute)!}

or, if you want display a default text when the attribute is null :

${(object.attribute)!"some text”}

OR you can use the ??  test operator:

This checks if the attribute of the object is not null:

<#if object.attribute??></#if>

This checks if object or attribute is not null:

<#if (object.attribute)??></#if>

OR you can use the ?has_content operator :

<#if object.attribute?has_content>
          Attribute exist!!
</#if>

OR you can use the _exists operator :

<#if_exists object.attribute>
  Attribute exists = ${ object.attribute} 

</#if_exists>

Use of Freemarker :  

Freemarker is being used massively in the Emailing , SMS, Content Feeder and also the View part of the MVC frameworks like Spring.

Maven Dependency : 

<!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
<dependency>
    <groupId>org.freemarker</groupId>
    <artifactId>freemarker</artifactId>
    <version>2.3.23</version>
</dependency>

Happy to help post your query in the blog.

Sunday, 27 March 2016

Iteration of a Collection in Freemarker Template

In this blog , we will be demonstrating the iteration of Java Collection viz. Map , List etc with the different examples in the freemarker templates. As all the Java collection implements the Iterable interface, so iteration technique is same for different sort of collections.

    




1. Iteration of a Map in Freemarker Template (FTL)

Lets look how the Map iteration looks like in Java : 

Map<String,Object> personMap = new HashMap<String, Object>();
person.put("name","sachin");
person.put("age, 29);
person.put("occupation","blogger");
for (String key : person.keySet()) {
           System.out.println("key=" + key + ", value=" + person.get(key));
}

Similar Map if we need to iterate in freemarker template then it's as follow: 

<#if personMap?has_content>
<#list personMap?keys as key>
"keys= "${key}, "value=" ${personMap[key]}; 
</#list>
</#if>

Here ?keys is a built-in function in freemarker just like keySet() in Java to 
provide the list of all the keys.

Output :
---------------------------------------
key=name, value=sachin
key=age, value=29
key=occupation, value=blogger
---------------------------------------

2. Iteration of a List in Freemarker Template (FTL)

Lets look how the List iteration looks like in Java 

List<String> nameList = new ArrayList<>();
nameList.add("Amar");
nameList.add("Akbar");
nameList.add("Anthony");
for (String name : nameList) {
System.out.println("name=" + name);
}

Similar List if we need to iterate in freemarker template then it's as follow: 

<#if nameList?has_content>
<#list nameList as name>
"name= "${name}
</#list>
</#if>

Output:
-------------------
name=Amar
name=Akbar
name=Anthony
--------------------------

Here has_content is a built-in function in freemarker just to check the emptiness 
of the collection return true if non-empty else return false.


Enjoy the power of the freemarker template for various purpose like Email Templating , View part of the framework , Generating News Feed etc .

Thursday, 3 March 2016

Installing Freemarker IDE in Eclipse




Steps to install Freemarker IDE in eclipse Mars  :


  1. Go to Help  --> Install New Software 
  2.  Out of the  following URL for updating site of http://download.jboss.org/jbosstools/updates/stable/mars/
  3. For Older eclipse version use from the following 
  • http://download.jboss.org/jbosstools/updates/stable/luna/
  • http://download.jboss.org/jbosstools/updates/stable/juno/
  • http://download.jboss.org/jbosstools/updates/stable/indigo/
  • http://download.jboss.org/jbosstools/updates/stable/helios/



 4.  Update the  work with : 
         http://download.jboss.org/jbosstools/updates/stable/mars/    and select JBoss                                        Application Developers ---> Select FreeMarker IDE


4. Click on Finish and then FreeMarker IDE is installed on your eclipse with a restart.





Congrats your template engine is ready to work !!!!!!!!


Tuesday, 29 December 2015

TimeZone Ids In Java and Date Serialization with TimeZone using Jackson




1. There are total of 617 number  of  supported time zone IDs  available in the JDK version 1.8  and following is the list of all the IDs obtained from the java.util.TimeZone  :
--------------------
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
Africa/Brazzaville
Africa/Bujumbura
Africa/Cairo
Africa/Casablanca
Africa/Ceuta
Africa/Conakry
Africa/Dakar
Africa/Dar_es_Salaam
Africa/Djibouti
Africa/Douala
Africa/El_Aaiun
Africa/Freetown
Africa/Gaborone
Africa/Harare
Africa/Johannesburg
Africa/Juba
Africa/Kampala
Africa/Khartoum
Africa/Kigali
Africa/Kinshasa
Africa/Lagos
Africa/Libreville
Africa/Lome
Africa/Luanda
Africa/Lubumbashi
Africa/Lusaka
Africa/Malabo
Africa/Maputo
Africa/Maseru
Africa/Mbabane
Africa/Mogadishu
Africa/Monrovia
Africa/Nairobi
Africa/Ndjamena
Africa/Niamey
Africa/Nouakchott
Africa/Ouagadougou
Africa/Porto-Novo
Africa/Sao_Tome
Africa/Timbuktu
Africa/Tripoli
Africa/Tunis
Africa/Windhoek
America/Adak
America/Anchorage
America/Anguilla
America/Antigua
America/Araguaina
America/Argentina/Buenos_Aires
America/Argentina/Catamarca
America/Argentina/ComodRivadavia
America/Argentina/Cordoba
America/Argentina/Jujuy
America/Argentina/La_Rioja
America/Argentina/Mendoza
America/Argentina/Rio_Gallegos
America/Argentina/Salta
America/Argentina/San_Juan
America/Argentina/San_Luis
America/Argentina/Tucuman
America/Argentina/Ushuaia
America/Aruba
America/Asuncion
America/Atikokan
America/Atka
America/Bahia
America/Bahia_Banderas
America/Barbados
America/Belem
America/Belize
America/Blanc-Sablon
America/Boa_Vista
America/Bogota
America/Boise
America/Buenos_Aires
America/Cambridge_Bay
America/Campo_Grande
America/Cancun
America/Caracas
America/Catamarca
America/Cayenne
America/Cayman
America/Chicago
America/Chihuahua
America/Coral_Harbour
America/Cordoba
America/Costa_Rica
America/Creston
America/Cuiaba
America/Curacao
America/Danmarkshavn
America/Dawson
America/Dawson_Creek
America/Denver
America/Detroit
America/Dominica
America/Edmonton
America/Eirunepe
America/El_Salvador
America/Ensenada
America/Fort_Wayne
America/Fortaleza
America/Glace_Bay
America/Godthab
America/Goose_Bay
America/Grand_Turk
America/Grenada
America/Guadeloupe
America/Guatemala
America/Guayaquil
America/Guyana
America/Halifax
America/Havana
America/Hermosillo
America/Indiana/Indianapolis
America/Indiana/Knox
America/Indiana/Marengo
America/Indiana/Petersburg
America/Indiana/Tell_City
America/Indiana/Vevay
America/Indiana/Vincennes
America/Indiana/Winamac
America/Indianapolis
America/Inuvik
America/Iqaluit
America/Jamaica
America/Jujuy
America/Juneau
America/Kentucky/Louisville
America/Kentucky/Monticello
America/Knox_IN
America/Kralendijk
America/La_Paz
America/Lima
America/Los_Angeles
America/Louisville
America/Lower_Princes
America/Maceio
America/Managua
America/Manaus
America/Marigot
America/Martinique
America/Matamoros
America/Mazatlan
America/Mendoza
America/Menominee
America/Merida
America/Metlakatla
America/Mexico_City
America/Miquelon
America/Moncton
America/Monterrey
America/Montevideo
America/Montreal
America/Montserrat
America/Nassau
America/New_York
America/Nipigon
America/Nome
America/Noronha
America/North_Dakota/Beulah
America/North_Dakota/Center
America/North_Dakota/New_Salem
America/Ojinaga
America/Panama
America/Pangnirtung
America/Paramaribo
America/Phoenix
America/Port-au-Prince
America/Port_of_Spain
America/Porto_Acre
America/Porto_Velho
America/Puerto_Rico
America/Rainy_River
America/Rankin_Inlet
America/Recife
America/Regina
America/Resolute
America/Rio_Branco
America/Rosario
America/Santa_Isabel
America/Santarem
America/Santiago
America/Santo_Domingo
America/Sao_Paulo
America/Scoresbysund
America/Shiprock
America/Sitka
America/St_Barthelemy
America/St_Johns
America/St_Kitts
America/St_Lucia
America/St_Thomas
America/St_Vincent
America/Swift_Current
America/Tegucigalpa
America/Thule
America/Thunder_Bay
America/Tijuana
America/Toronto
America/Tortola
America/Vancouver
America/Virgin
America/Whitehorse
America/Winnipeg
America/Yakutat
America/Yellowknife
Antarctica/Casey
Antarctica/Davis
Antarctica/DumontDUrville
Antarctica/Macquarie
Antarctica/Mawson
Antarctica/McMurdo
Antarctica/Palmer
Antarctica/Rothera
Antarctica/South_Pole
Antarctica/Syowa
Antarctica/Troll
Antarctica/Vostok
Arctic/Longyearbyen
Asia/Aden
Asia/Almaty
Asia/Amman
Asia/Anadyr
Asia/Aqtau
Asia/Aqtobe
Asia/Ashgabat
Asia/Ashkhabad
Asia/Baghdad
Asia/Bahrain
Asia/Baku
Asia/Bangkok
Asia/Beirut
Asia/Bishkek
Asia/Brunei
Asia/Calcutta
Asia/Chita
Asia/Choibalsan
Asia/Chongqing
Asia/Chungking
Asia/Colombo
Asia/Dacca
Asia/Damascus
Asia/Dhaka
Asia/Dili
Asia/Dubai
Asia/Dushanbe
Asia/Gaza
Asia/Harbin
Asia/Hebron
Asia/Ho_Chi_Minh
Asia/Hong_Kong
Asia/Hovd
Asia/Irkutsk
Asia/Istanbul
Asia/Jakarta
Asia/Jayapura
Asia/Jerusalem
Asia/Kabul
Asia/Kamchatka
Asia/Karachi
Asia/Kashgar
Asia/Kathmandu
Asia/Katmandu
Asia/Khandyga
Asia/Kolkata
Asia/Krasnoyarsk
Asia/Kuala_Lumpur
Asia/Kuching
Asia/Kuwait
Asia/Macao
Asia/Macau
Asia/Magadan
Asia/Makassar
Asia/Manila
Asia/Muscat
Asia/Nicosia
Asia/Novokuznetsk
Asia/Novosibirsk
Asia/Omsk
Asia/Oral
Asia/Phnom_Penh
Asia/Pontianak
Asia/Pyongyang
Asia/Qatar
Asia/Qyzylorda
Asia/Rangoon
Asia/Riyadh
Asia/Saigon
Asia/Sakhalin
Asia/Samarkand
Asia/Seoul
Asia/Shanghai
Asia/Singapore
Asia/Srednekolymsk
Asia/Taipei
Asia/Tashkent
Asia/Tbilisi
Asia/Tehran
Asia/Tel_Aviv
Asia/Thimbu
Asia/Thimphu
Asia/Tokyo
Asia/Ujung_Pandang
Asia/Ulaanbaatar
Asia/Ulan_Bator
Asia/Urumqi
Asia/Ust-Nera
Asia/Vientiane
Asia/Vladivostok
Asia/Yakutsk
Asia/Yekaterinburg
Asia/Yerevan
Atlantic/Azores
Atlantic/Bermuda
Atlantic/Canary
Atlantic/Cape_Verde
Atlantic/Faeroe
Atlantic/Faroe
Atlantic/Jan_Mayen
Atlantic/Madeira
Atlantic/Reykjavik
Atlantic/South_Georgia
Atlantic/St_Helena
Atlantic/Stanley
Australia/ACT
Australia/Adelaide
Australia/Brisbane
Australia/Broken_Hill
Australia/Canberra
Australia/Currie
Australia/Darwin
Australia/Eucla
Australia/Hobart
Australia/LHI
Australia/Lindeman
Australia/Lord_Howe
Australia/Melbourne
Australia/NSW
Australia/North
Australia/Perth
Australia/Queensland
Australia/South
Australia/Sydney
Australia/Tasmania
Australia/Victoria
Australia/West
Australia/Yancowinna
Brazil/Acre
Brazil/DeNoronha
Brazil/East
Brazil/West
CET
CST6CDT
Canada/Atlantic
Canada/Central
Canada/East-Saskatchewan
Canada/Eastern
Canada/Mountain
Canada/Newfoundland
Canada/Pacific
Canada/Saskatchewan
Canada/Yukon
Chile/Continental
Chile/EasterIsland
Cuba
EET
EST5EDT
Egypt
Eire
Etc/GMT
Etc/GMT+0
Etc/GMT+1
Etc/GMT+10
Etc/GMT+11
Etc/GMT+12
Etc/GMT+2
Etc/GMT+3
Etc/GMT+4
Etc/GMT+5
Etc/GMT+6
Etc/GMT+7
Etc/GMT+8
Etc/GMT+9
Etc/GMT-0
Etc/GMT-1
Etc/GMT-10
Etc/GMT-11
Etc/GMT-12
Etc/GMT-13
Etc/GMT-14
Etc/GMT-2
Etc/GMT-3
Etc/GMT-4
Etc/GMT-5
Etc/GMT-6
Etc/GMT-7
Etc/GMT-8
Etc/GMT-9
Etc/GMT0
Etc/Greenwich
Etc/UCT
Etc/UTC
Etc/Universal
Etc/Zulu
Europe/Amsterdam
Europe/Andorra
Europe/Athens
Europe/Belfast
Europe/Belgrade
Europe/Berlin
Europe/Bratislava
Europe/Brussels
Europe/Bucharest
Europe/Budapest
Europe/Busingen
Europe/Chisinau
Europe/Copenhagen
Europe/Dublin
Europe/Gibraltar
Europe/Guernsey
Europe/Helsinki
Europe/Isle_of_Man
Europe/Istanbul
Europe/Jersey
Europe/Kaliningrad
Europe/Kiev
Europe/Lisbon
Europe/Ljubljana
Europe/London
Europe/Luxembourg
Europe/Madrid
Europe/Malta
Europe/Mariehamn
Europe/Minsk
Europe/Monaco
Europe/Moscow
Europe/Nicosia
Europe/Oslo
Europe/Paris
Europe/Podgorica
Europe/Prague
Europe/Riga
Europe/Rome
Europe/Samara
Europe/San_Marino
Europe/Sarajevo
Europe/Simferopol
Europe/Skopje
Europe/Sofia
Europe/Stockholm
Europe/Tallinn
Europe/Tirane
Europe/Tiraspol
Europe/Uzhgorod
Europe/Vaduz
Europe/Vatican
Europe/Vienna
Europe/Vilnius
Europe/Volgograd
Europe/Warsaw
Europe/Zagreb
Europe/Zaporozhye
Europe/Zurich
GB
GB-Eire
GMT
GMT0
Greenwich
Hongkong
Iceland
Indian/Antananarivo
Indian/Chagos
Indian/Christmas
Indian/Cocos
Indian/Comoro
Indian/Kerguelen
Indian/Mahe
Indian/Maldives
Indian/Mauritius
Indian/Mayotte
Indian/Reunion
Iran
Israel
Jamaica
Japan
Kwajalein
Libya
MET
MST7MDT
Mexico/BajaNorte
Mexico/BajaSur
Mexico/General
NZ
NZ-CHAT
Navajo
PRC
PST8PDT
Pacific/Apia
Pacific/Auckland
Pacific/Bougainville
Pacific/Chatham
Pacific/Chuuk
Pacific/Easter
Pacific/Efate
Pacific/Enderbury
Pacific/Fakaofo
Pacific/Fiji
Pacific/Funafuti
Pacific/Galapagos
Pacific/Gambier
Pacific/Guadalcanal
Pacific/Guam
Pacific/Honolulu
Pacific/Johnston
Pacific/Kiritimati
Pacific/Kosrae
Pacific/Kwajalein
Pacific/Majuro
Pacific/Marquesas
Pacific/Midway
Pacific/Nauru
Pacific/Niue
Pacific/Norfolk
Pacific/Noumea
Pacific/Pago_Pago
Pacific/Palau
Pacific/Pitcairn
Pacific/Pohnpei
Pacific/Ponape
Pacific/Port_Moresby
Pacific/Rarotonga
Pacific/Saipan
Pacific/Samoa
Pacific/Tahiti
Pacific/Tarawa
Pacific/Tongatapu
Pacific/Truk
Pacific/Wake
Pacific/Wallis
Pacific/Yap
Poland
Portugal
ROK
Singapore
SystemV/AST4
SystemV/AST4ADT
SystemV/CST6
SystemV/CST6CDT
SystemV/EST5
SystemV/EST5EDT
SystemV/HST10
SystemV/MST7
SystemV/MST7MDT
SystemV/PST8
SystemV/PST8PDT
SystemV/YST9
SystemV/YST9YDT
Turkey
UCT
US/Alaska
US/Aleutian
US/Arizona
US/Central
US/East-Indiana
US/Eastern
US/Hawaii
US/Indiana-Starke
US/Michigan
US/Mountain
US/Pacific
US/Pacific-New
US/Samoa
UTC
Universal
W-SU
WET
Zulu
EST
HST
MST
ACT
AET
AGT
ART
AST
BET
BST
CAT
CNT
CST
CTT
EAT
ECT
IET
IST
JST
MIT
NET
NST
PLT
PNT
PRT
PST
SST

VST
-----------------------

2. In the Jackson setting the Timezone can help in the serialization of the Date data correct with the given timezone , there are two ways of setting the timezone for Jackson frequently used in the Spring framework : 
a) Using Object wrapper : 

         ObjectMapper mapper = new ObjectMapper();
         DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy'T'HH:mm:ss.SSSZ");
         dateFormat.setTimeZone(TimeZone.getTimeZone("IST"));
         mapper.setDateFormat(dateFormat);

b)  In the  Jackson 2.x version using the  annotation : 

@JsonFormat(shape=JsonFormat.Shape.STRING,pattern="dd-MM-yyyy'T'HH:mm:ss.SSSZ", timezone="IST")
private Date date;