Thursday, 12 April 2018

ASN.1: OCTET STRING

Type: OCTET STRING
Description: This is used to represent binary data that is multiple of 8 bits. Octet string can be of any length.

It can be represented in two forms.
         Binary – '1000100'B
         Hexa - '44'H       

Example
id OCTET STRING

Example Schema
Occupation ::=  BIT STRING {
    clerk        (0),
    watchman     (1),
    engineer     (2),
    manager      (3)
}
    
Hobbies ::= BIT STRING {
    chess     (0),
    cricket   (1),
    hockey    (2),
    football  (3),
    others    (4)
}
    
Employee ::= SEQUENCE {
 name VisibleString,
 isPermanentEmployee BOOLEAN,
 id OCTET STRING,
 age INTEGER (15..60),
 occupation Occupation,
 hobbies Hobbies
}

Sample data for above schema
employee1 Employee ::= {
 name "Rama Krishna",
 isPermanentEmployee FALSE,
 id '10001000'B,
 age 30,
 occupation '010'B,
 hobbies {chess, football}
}

XML encoding of above data
<?xml version="1.0" encoding="UTF-8"?>
<Employee>
  <name>Rama Krishna</name>
  <isPermanentEmployee><false/></isPermanentEmployee>
  <id>88</id>
  <age>30</age>
  <occupation>01</occupation>
  <hobbies>1001</hobbies>
</Employee>






Previous                                                 Next                                                 Home

ASN.1: BIT STRING

Type: BIT STRING
Description: Used to represent bit arrays. Specific bits can be identified by parenthesized integers and assigned names. It is used to model the binary data of arbitrary length.  The length of the string of bits must be a multiple of four when hexadecimal is used.

Values can be represented in 3 possible forms:
a.   binary - '01'B,
b.   hex - '9'H, and
c.   named - {chess, football}

Examples
Occupation ::=  BIT STRING {
 clerk        (0),
    watchman     (1),
 engineer     (2),
    manager      (3)
}
    
Hobbies ::= BIT STRING {
 chess     (0),
 cricket   (1),
 hockey    (2),
 football  (3),
 others    (4)
}

The numbers in parentheses indicate location in the string of bits. In the above example, first bit is chess, second bit is cricket, third bit is hockey and so on.

Example Schema
Occupation ::=  BIT STRING {
    clerk    (0),
    watchman  (1),
    engineer  (2),
    manager   (3)
}
    
Hobbies ::= BIT STRING {
 chess     (0),
 cricket   (1),
 hockey    (2),
 football  (3),
 others    (4)
}
    
Employee ::= SEQUENCE {
 name VisibleString,
 isPermanentEmployee BOOLEAN,
 id INTEGER,
 age INTEGER (15..60),
 occupation Occupation,
 hobbies Hobbies
}

Sample data for above schema
employee1 Employee ::= {
 name "Rama Krishna",
 isPermanentEmployee FALSE,
 id 12345,
 age 30,
 occupation '010'B,
 hobbies {chess, football}
}

XML encoding of above data
<?xml version="1.0" encoding="UTF-8"?>
<Employee>
  <name>Rama Krishna</name>
  <isPermanentEmployee><false/></isPermanentEmployee>
  <id>12345</id>
  <age>30</age>
  <occupation>01</occupation>
  <hobbies>1001</hobbies>
</Employee>



Previous                                                 Next                                                 Home

Get all the currencies supported in Java

Currency class provides 'getAvailableCurrencies' methods to get all the currencies.
Set<Currency> currencies = Currency.getAvailableCurrencies();

Test.java
package com.sample.test;

import java.util.Currency;
import java.util.Set;

public class Test {

 public static void main(String args[]) throws Exception {
  Set<Currency> currencies = Currency.getAvailableCurrencies();

  System.out.println("Currency Code \t Display Name");
  for (Currency currency : currencies) {
   String currencyCode = currency.getCurrencyCode();
   String displayName = currency.getDisplayName();

   System.out.println(currencyCode + "\t" + displayName);

  }
 }
}


Output
Currency Code   Display Name
ERN Eritrean Nakfa
COP Colombian Peso
CUP Cuban Peso
TJS Tajikistani Somoni
ZWL Zimbabwean Dollar (2009)
GHS Ghanaian Cedi
CHW CHW
BDT Bangladeshi Taka
ZMW ZMW
GYD Guyanaese Dollar
DKK Danish Krone
PYG Paraguayan Guarani
BND Brunei Dollar
XAF CFA Franc BEAC
HNL Honduran Lempira
SZL Swazi Lilangeni
MXN Mexican Peso
NGN Nigerian Naira
SDD Sudanese Dinar (1992-2007)
BMD Bermudan Dollar
TZS Tanzanian Shilling
CHF Swiss Franc
CRC Costa Rican Colón
SYP Syrian Pound
FKP Falkland Islands Pound
PLN Polish Zloty
UYU Uruguayan Peso
ZAR South African Rand
UGX Ugandan Shilling
PTE Portuguese Escudo
ILS Israeli New Sheqel
RUB Russian Ruble
BYR Belarusian Ruble (2000-2016)
XBC European Unit of Account (XBC)
GIP Gibraltar Pound
KZT Kazakhstani Tenge
CYP Cypriot Pound
LKR Sri Lankan Rupee
GEL Georgian Lari
XFU French UIC-Franc
CSD Serbian Dinar (2002-2006)
XAG Silver
KWD Kuwaiti Dinar
RON Romanian Leu
GHC Ghanaian Cedi (1979-2007)
MNT Mongolian Tugrik
SEK Swedish Krona
SAR Saudi Riyal
ANG Netherlands Antillean Guilder
XFO French Gold Franc
XTS Testing Currency Code
MAD Moroccan Dirham
SOS Somali Shilling
RWF Rwandan Franc
ZWN ZWN
INR Indian Rupee
KHR Cambodian Riel
JOD Jordanian Dinar
MGF Malagasy Franc
GMD Gambian Dalasi
VND Vietnamese Dong
UZS Uzbekistan Som
VEF Venezuelan Bolívar
LSL Lesotho Loti
ESP Spanish Peseta
FRF French Franc
NZD New Zealand Dollar
MDL Moldovan Leu
ZWR Zimbabwean Dollar (2008)
QAR Qatari Rial
IRR Iranian Rial
DZD Algerian Dinar
LYD Libyan Dinar
MVR Maldivian Rufiyaa
VUV Vanuatu Vatu
SBD Solomon Islands Dollar
KMF Comorian Franc
ZWD Zimbabwean Dollar (1980-2008)
LAK Laotian Kip
ZMK Zambian Kwacha
CAD Canadian Dollar
AOA Angolan Kwanza
ETB Ethiopian Birr
BRL Brazilian Real
NOK Norwegian Krone
TND Tunisian Dinar
YER Yemeni Rial
MRO Mauritanian Ouguiya
SGD Singapore Dollar
JMD Jamaican Dollar
CDF Congolese Franc
CVE Cape Verdean Escudo
SDG Sudanese Pound
SHP Saint Helena Pound
ISK Icelandic Króna
TRL Turkish Lira (1922-2005)
BEF Belgian Franc
ROL Romanian Leu (1952-2006)
BOB Bolivian Boliviano
GWP Guinea-Bissau Peso
ATS Austrian Schilling
NIO Nicaraguan Córdoba
BGN Bulgarian Lev
ITL Italian Lira
BIF Burundian Franc
BSD Bahamian Dollar
WST Samoan Tala
LRD Liberian Dollar
XXX Unknown Currency
LUF Luxembourgian Franc
MTL Maltese Lira
ARS Argentine Peso
PAB Panamanian Balboa
CLP Chilean Peso
HKD Hong Kong Dollar
HRK Kuna
XOF CFA Franc BCEAO
XDR Special Drawing Rights
USN US Dollar (Next day)
GBP British Pound Sterling
COU COU
TMT Turkmenistani Manat
AFA Afghan Afghani (1927-2002)
FIM Finnish Markka
EEK Estonian Kroon
PEN Peruvian Sol
UAH Ukrainian Hryvnia
TOP Tongan Pa?anga
SIT Slovenian Tolar
SCR Seychellois Rupee
XBB European Monetary Unit
IEP Irish Pound
KGS Kyrgystani Som
USD US Dollar
CLF Chilean Unit of Account (UF)
LVL Latvian Lats
CNY Chinese Yuan
LBP Lebanese Pound
BYB Belarusian Ruble (1994-1999)
AUD Australian Dollar
AZN Azerbaijani Manat
UYI UYI
HUF Hungarian Forint
NPR Nepalese Rupee
XBA European Composite Unit
AWG Aruban Florin
MYR Malaysian Ringgit
AMD Armenian Dram
BWP Botswanan Pula
BZD Belize Dollar
MXV Mexican Investment Unit
XCD East Caribbean Dollar
MGA Malagasy Ariary
SRG Surinamese Guilder
KRW South Korean Won
XAU Gold
RUR Russian Ruble (1991-1998)
ALL Albanian Lek
MKD Macedonian Denar
BTN Bhutanese Ngultrum
AFN Afghan Afghani
TRY Turkish Lira
DJF Djiboutian Franc
PKR Pakistani Rupee
CUC Cuban Convertible Peso
EUR Euro
CHE CHE
XUA ADB Unit of Account
MWK Malawian Malawi Kwacha
XSU Sucre
HTG Haitian Gourde
TTD Trinidad and Tobago Dollar
BBD Barbadian Dollar
XBD European Unit of Account (XBD)
AYM AYM
MZM Mozambican Metical (1980-2006)
SKK Slovak Koruna
KYD Cayman Islands Dollar
BAM Bosnia-Herzegovina Convertible Mark
AED United Arab Emirates Dirham
SVC Salvadoran Colón
OMR Omani Rial
USS US Dollar (Same day)
KPW North Korean Won
MOP Macanese Pataca
ADP Andorran Peseta
EGP Egyptian Pound
GRD Greek Drachma
BOV Bolivian Mvdol
STD São Tomé and Príncipe Dobra
AZM Azerbaijani Manat (1993-2006)
JPY Japanese Yen
SRD Surinamese Dollar
XPD Palladium
TMM Turkmenistani Manat (1993-2009)
XPT Platinum
YUM Yugoslavian New Dinar (1994-2002)
VEB Venezuelan Bolívar (1871-2008)
NAD Namibian Dollar
DOP Dominican Peso
MMK Myanma Kyat
IQD Iraqi Dinar
DEM German Mark
THB Thai Baht
MZN Mozambican Metical
LTL Lithuanian Litas
XPF CFP Franc
MUR Mauritian Rupee
SSP South Sudanese Pound
RSD Serbian Dinar
CZK Czech Republic Koruna
PHP Philippine Peso
PGK Papua New Guinean Kina
BHD Bahraini Dinar
TWD New Taiwan Dollar
NLG Dutch Guilder
GTQ Guatemalan Quetzal
IDR Indonesian Rupiah
SLL Sierra Leonean Leone
BYN Belarusian Ruble
GNF Guinean Franc
KES Kenyan Shilling
TPE Timorese Escudo
BGL Bulgarian Hard Lev
FJD Fijian Dollar



ASN.1: INTEGER : Represent integer values

Type: INTEGER
Description: It is used to represent integer values. It does not have any upper and lower limits, it can be of any magnitude.

Examples
id  INTEGER
age INTEGER (15..60)

In the second example, age is of type integer and the valid values are from 15 to 60.

Example Schema
Employee ::= SEQUENCE {
 firstName VisibleString,
 lastName VisibleString,
 isPermanentEmployee BOOLEAN,
 id INTEGER,
 age INTEGER (15..60)
}

Sample data for above schema
employee1 Employee ::= {
 firstName "Rama Krishna",
 lastName "Gurram",
 isPermanentEmployee FALSE,
 id 12345,
 age 30
}

XML encoding of above data
<?xml version="1.0" encoding="UTF-8"?>
<Employee>
  <firstName>Rama Krishna</firstName>
  <lastName>Gurram</lastName>
  <isPermanentEmployee><false/></isPermanentEmployee>
  <id>12345</id>
  <age>30</age>
</Employee>

INTEGER type has also one possible notation, where you can name the possible values associated with this integer.

FavoriteColors ::= INTEGER {
  red    (0),
  green  (1),       
  yellow (2),
  blue   (3)
}


Example Schema
FavoriteColors ::= INTEGER {
  red    (0),
  green  (1), 
  yellow (2),
  blue   (3)
}

Person ::= SEQUENCE {
  firstName VisibleString,
  lastName VisibleString,
  favoriteColor FavoriteColors
}

Sample data for above schema

person Person ::= {
  firstName "Rama Krishna",
  lastName "Gurram",
  favoriteColor green
}

XML encoding of above data

<?xml version="1.0" encoding="UTF-8"?>
<Person>
  <firstName>Rama Krishna</firstName>
  <lastName>Gurram</lastName>
  <favoriteColor>1</favoriteColor>
</Person>


Previous                                                 Next                                                 Home

Wednesday, 11 April 2018

Get week names in Java

In this post, you are going to learn.
a.   What is DateFormatSymbols API
b.   How to get an instance of DateFormatSymbols
c.   How to get all the week full & short names using DateFormatSybmols API.
d.   How to get localized week names?

What is DateFormatSymbols API?
'java.text.DateFormatSymbols' class encapsulates localized date-time formatting data. By using this class, you can get
a.   Names of the months,
b.   Short names of the months.
c.   The names and short names of the days of the week, and
         d. The time zone data

How to get an instance of DateFormatSymbols?
DateFormatSymbols class provides below constructors to get an instance of 'DateFormatSymbols' class.
DateFormatSymbols()
DateFormatSymbols(Locale locale)

How to get all the week full & short names using DateFormatSybmols API?
By calling 'getWeekdays' and 'getShortWeekdays' APIS, you can get the week full and short names.

Test.java
package com.sample.test;

import java.text.DateFormatSymbols;

public class Test {

 public static void main(String args[]) throws Exception {
  DateFormatSymbols dateFormatSymbols = new DateFormatSymbols();

  String[] weekDays = dateFormatSymbols.getWeekdays();

  System.out.println("Full Week Names:");
  for (String week : weekDays) {
   System.out.println(week);
  }

  System.out.println("\nShort Week Names: ");
  String[] shortWeekDays = dateFormatSymbols.getShortWeekdays();
  for (String week : shortWeekDays) {
   System.out.println(week);
  }

 }
}

Output
Full Week Names:

Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday

Short Week Names: 

Sun
Mon
Tue
Wed
Thu
Fri
Sat

How to get localized week names?
By defining the 'DateFormatSymbols' using specific locale, you can get locale specific names.

DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(Locale.GERMANY);


Test.java
package com.sample.test;

import java.text.DateFormatSymbols;
import java.util.Locale;

public class Test {

 public static void main(String args[]) throws Exception {
  DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(Locale.GERMANY);

  String[] weekDays = dateFormatSymbols.getWeekdays();

  System.out.println("Full Week Names:");
  for (String week : weekDays) {
   System.out.println(week);
  }

  System.out.println("\nShort Week Names: ");
  String[] shortWeekDays = dateFormatSymbols.getShortWeekdays();
  for (String week : shortWeekDays) {
   System.out.println(week);
  }

 }
}


Output
Full Week Names:

Sonntag
Montag
Dienstag
Mittwoch
Donnerstag
Freitag
Samstag

Short Week Names: 

So
Mo
Di
Mi
Do
Fr
Sa






ASN.1: BOOLEAN type: Represent TRUE/FALSE states

Type: BOOLEAN
Description: Boolean is used to represent TRUE, FALSE states. It is similar to boolean type in programming languages. 

Example
isPassedInExam BOOLEAN ::= TRUE
canIReadTheFile BOOLEAN ::= FALSE

Example schema
Employee ::= SEQUENCE {
 firstName VisibleString,
 lastName VisibleString,
 isPermanentEmployee BOOLEAN
}

Data can be represented like below.

employee1 Employee ::= {
 firstName "Hari Krishna",
 lastName "Gurram",
 isPermanentEmployee FALSE
}


employee2 Employee ::= {
 firstName "Venkata",
 lastName "Madala",
 isPermanentEmployee TRUE
}

XML encoding of the above data looks like below.

<?xml version="1.0" encoding="UTF-8"?>
<Employee>
  <firstName>Hari Krishna</firstName>
  <lastName>Gurram</lastName>
  <isPermanentEmployee><false/></isPermanentEmployee>
</Employee>


<?xml version="1.0" encoding="UTF-8"?>
<Employee>
  <firstName>Venkata</firstName>
  <lastName>Madala</lastName>
  <isPermanentEmployee><true/></isPermanentEmployee>
</Employee>




Previous                                                 Next                                                 Home

Tuesday, 10 April 2018

Get all the month names in Java

In this post, you are going to learn.
a.   What is DateFormatSymbols API
b.   How to get an instance of DateFormatSymbols
c.   How to get all the months full & short names using DateFormatSybmols API.
d.   How to get localized month names?

What is DateFormatSymbols API?
'java.text.DateFormatSymbols' class encapsulates localized date-time formatting data. By using this class, you can get
         a. Names of the months,
         b. Short names of the months.
         c. The names and short names of the days of the week, and
         d. The time zone data

How to get an instance of DateFormatSymbols?
DateFormatSymbols class provides below constructors to get an instance of 'DateFormatSymbols' class.
DateFormatSymbols()
DateFormatSymbols(Locale locale)

How to get all the months full & short names using DateFormatSybmols API?
DateFormatSymbols API provides getMonths, getShortMonths APIS to get the month name and short form of the month names.

Find the below working application.

Test.java
package com.sample.test;

import java.text.DateFormatSymbols;

public class Test {

  public static void main(String args[]) throws Exception {
   DateFormatSymbols dateFormatSymbols = new DateFormatSymbols();

   String[] months = dateFormatSymbols.getMonths();
   
   System.out.println("Full Month Names:");
   for(String month : months){
    System.out.println(month);
   }
   
   System.out.println("\nShort Month Names: ");
   String[] shortMonths = dateFormatSymbols.getShortMonths();
   for(String month : shortMonths){
    System.out.println(month);
   }
   
 }
}

Output
Full Month Names:
January
February
March
April
May
June
July
August
September
October
November
December


Short Month Names: 
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec

How to get localized month names?
You should create a DateFormatSymbols instance by specifying the locale.
DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(Locale.GERMANY);

Below application print the month names in Germany.


Test.java
package com.sample.test;

import java.text.DateFormatSymbols;
import java.util.Locale;

public class Test {

  public static void main(String args[]) throws Exception {
   DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(Locale.GERMANY);

   String[] months = dateFormatSymbols.getMonths();
   
   System.out.println("Full Month Names:");
   for(String month : months){
    System.out.println(month);
   }
   
   System.out.println("\nShort Month Names: ");
   String[] shortMonths = dateFormatSymbols.getShortMonths();
   for(String month : shortMonths){
    System.out.println(month);
   }
   
 }
}

Output
Full Month Names:
Januar
Februar
März
April
Mai
Juni
Juli
August
September
Oktober
November
Dezember


Short Month Names: 
Jan
Feb
Mär
Apr
Mai
Jun
Jul
Aug
Sep
Okt
Nov
Dez