Thursday, 29 November 2012

HTTP Response Codes - Decision chart

This is a decision chart that I found on the internet, which shows how response codes are identified. Will be helpful if someone is trying to triage response codes issues.

Please Download this image and Zoom to see the details.

Java Annotations

What are Annotations?

Annotations was introduced in J2SE 5. These are tags that help us insert metadata into the source code so that they can be processed by tools.
In the Java programming language, an annotation is used like a modifier, and it is placed before the annotated item, without a semicolon.



Types of Annotations

Standard Annotation : Are applied to regular java classes, methods and statements
Meta Annotations:  Applied to annotation definition to describe the behavior of the annotation being declared and how it can be used.

Standard Annotations

These are the Annotations that are provided by Java to help us when writing our classes

 Meta Annotations

These are annotations used when defining an annotation
@Target : Elements of the Java class to which annotation is applicable
       @Retention :   When are the annotations loaded into the JVM
         @Inherited : meta-annotation applies only to annotations for classes.  
If an Inherited meta-annotation is pre sent on an annotation type declaration, and the user queries the annotation type on a class declaration, and the class declaration has no annotation for this type, then the class's superclass will automatically be queried for the annotation type

This process will be repeated until an annotation for this type is found, or the top of the class hierarchy (Object) is reached. If no superclass has an annotation for this type, then the query will indicate that the class in question has no such annotation.

       @Inherited Example:
@Target(ElementType.METHOD, ElementType.CLASS)
public @interface  changelog
    String author() default "author" ;    // Annotation member
    String date();      // Annotation member
@changelog(author="vidhya", date="30/11/2012")
public  class superclass
public class subclass extends superclass

When subclass is queried for ChangeLog annotation, it will be successful as the changelog annotation is @inherited.
@Documented: If a type declaration is annotated with Documented, its annotations become part of the public API of the annotated elements.

 How to Define an Annotation and read it

Each annotation must be defined by an annotation interface. The methods of the interface  correspond to the elements of the annotation.

@Target(ElementType.METHOD, ElementType.CLASS)
Public @interface  ChangeLog
    String author();    // Annotation member
    String date();      // Annotation member

3 Types of annotation Definition

1. Marker - No Parameters, just used to denote a type. @Test in Junit 1.4 onwards
2. Single Value Annotation  - This contains just one value @name("Single Value")
3. Multiple parameter annotation - has many parameters @user(id="1234", name="user1")


//Defined Annotation 
@ChangeLog(author="user1", date="10/10/2012") 
public class MyTest
 @ChangeLog(author="user2", date="20/08/2012")
 public void test1()

// The Annotation Reader
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class AnnotationTest
  public static void main( String[] args ) throws Exception
    //access the class annotation
    Class clazz = MyTest.class;
    System.out.println( clazz.getAnnotation(ChangeLog.class ) );
    //access the method annotation
    Method method = clazz.getMethod( "test1" );
    ChangeLog changelog = (ChangeLog) method.getAnnotation(ChangeLog.class);
    System.out.println("--- Changelog Author:"");

Tuesday, 20 November 2012

Change Timezone in linux

Changing timezone in linux can be done using the below steps. Timezone is set using a symbolic link at /etc/localtime.

1. Check Date
     [root@vidhya-dev-vm1 ~]# date
     Tue Nov 20 14:23:51 IST 2012

2. To see how the current localtime is set
     [root@vidhya-dev-vm1 ~]# ll /etc/localtime

     lrwxrwxrwx. 1 root root 39 Nov 20 11:47 /etc/localtime -> /usr/share/zoneinfo/right/Asia/Calcutta

3. Check all the timezones
     [root@vidhya-dev-vm1 ~]# ls /usr/share/zoneinfo/
     Africa      Brazil   Egypt    GB         Hongkong     Jamaica    MST      Portugal    ROK        WET
     America     Canada   Eire     GB-Eire    HST          Japan      MST7MDT  posix       Singapore  W-SU
     Antarctica  CET      EST      GMT        Iceland      Kwajalein  Navajo   posixrules  Turkey
     Arctic      Chile    EST5EDT  GMT0       Indian       Libya      NZ       PRC         UCT        Zulu
     Asia        CST6CDT  Etc      GMT-0      Iran         MET        NZ-CHAT  PST8PDT     Universal
     Atlantic    Cuba     Europe   GMT+0  Mexico     Pacific  right       US
     Australia   EET      Factory  Greenwich  Israel       Mideast    Poland   ROC         UTC

4. Backup existing timezone and link new timezone
     [root@vidhya-dev-vm1 ~]# mv /etc/localtime /root/localtime_bak
     [root@vidhya-dev-vm1 ~]# ln -sf /usr/share/zoneinfo/America/Denver /etc/localtime
     [root@vidhya-dev-vm1 ~]# date
     Tue Nov 20 01:56:59 MST 2012