Search This Blog

Friday, 20 February 2015

Null in Java...

java.lang.NullPointerException and you will learn your lesson hard way. Robust programming is an art and your team, customer and user will appreciate that. In my experience, one of the main reasons of NullPointerException are not enough knowledge about null in Java. Many of you already familiar with null but for those, who are not, can learn some old and new things about null keyword. Let's revisit or learn some important things about null in Java.




What is Null in Java

As I said, null is very very important concept in Java. It was originally invented to denote absence of something e.g. absence of user, a resource or anything, but over the year it has troubled Java programmer a lot with nasty null pointer exception. In this tutorial, we will learn basic facts about null keyword in Java and explore some techniques to minimize null checks and how to avoid nasty null pointer exceptions.

1) First thing, first,  null is a keyword in Java, much like public, static or final. It's case sensitive, you cannot write null as Null or NULL, compiler will not recognize them and give error.

Object obj = NULL; // Not Ok
Object obj1 = null  //Ok

Programmer's which are coming from other language have this problem, but use of modern day IDE's has made it insignificant. Now days, IDE like Eclipse or Netbeans can correct this mistake, while you type code, but in the era of notepad, Vim and Emacs, this was a common issue which could easily eat your precious time.


2) Just like every primitive has default value e.g. int has 0, boolean has false, null is the default value of any reference type, loosely spoken to all object as well. Just like if you create a boolean variable, it got default value as false, any reference variable in Java has default value null. This is true for all kind of variables e.g. member variable or local variable, instance variable or static variable, except that compiler will warn you if you use a local variable without initializing them. In order to verify this fact, you can see value of reference variable by creating a variable and them printing it's value, as shown in following code snippet :

What is null in Javaprivate static Object myObj;
public static void main(String args[]){
    System.out.println("What is value of myObjc : " + myObj);
} 

What is value of myObjc : null

This is true for both static and non-static object, as you can see here that I made myObj a static reference so that I can use it directly inside main method, which is static method and doesn't allow non-static variable inside.


3) Unlike common misconception, null is not Object or neither a type. It's just a special value, which can be assigned to any reference type and you can type cast null to any type, as shown below :

String str = null; // null can be assigned to String
Integer itr = null; // you can assign null to Integer also
Double dbl = null;  // null can also be assigned to Double
        
String myStr = (String) null; // null can be type cast to String
Integer myItr = (Integer) null; // it can also be type casted to Integer
Double myDbl = (Double) null; // yes it's possible, no error

You can see type casting null to any reference type is fine at both compile time and runtime, unlike many of you might have thought, it will also not throw NullPointerException at runtime.


4) null can only be assigned to reference type, you cannot assign null to primitive variables e.g. int, double, float or boolean. Compiler will complain if you do so, as shown below.

int i = null; // type mismatch : cannot convert from null to int
short s = null; //  type mismatch : cannot convert from null to short
byte b = null: // type mismatch : cannot convert from null to byte
double d = null; //type mismatch : cannot convert from null to double
        
Integer itr = null; // this is ok
int j = itr; // this is also ok, but NullPointerException at runtime

As you can see, when you directly assign null to primitive error it's compile time error, but if you assign null to a wrapper class object and then assign that object to respective primitive type, compiler doesn't complain, but you would be greeted by null pointer exception at runtime. This happens because of autoboxing in Java, and we will see it in next point.


5) Any wrapper class with value null will throw java.lang.NullPointerException when Java unbox them into primitive values. Some programmer makes wrong assumption that, auto boxing will take care of converting null into default values for respective primitive type e.g. 0 for int, false for boolean etc, but that's not true, as seen below.

Integer iAmNull = null;
int i = iAmNull; // Remember - No Compilation Error

but when you run above code snippet you will see Exception in thread "main" java.lang.NullPointerException  in your console. This happens a lot while working with HashMap and Integer key values. Code like shown below will break as soon as you run.

import java.util.HashMap;
import java.util.Map;


/**
 * An example of Autoboxing and NullPointerExcpetion
 * 
 * @author WINDOWS 8
 */

public class Test {

    public static void main(String args[]) throws InterruptedException {
        
      Map numberAndCount = new HashMap<>();

      int[] numbers = {3, 5, 7,9, 11, 13, 17, 19, 2, 3, 5, 33, 12, 5};
      
      for(int i : numbers){
         int count = numberAndCount.get(i);
         numberAndCount.put(i, count++); // NullPointerException here
      }       
    }

}

Output:
Exception in thread "main" java.lang.NullPointerException
 at Test.main(Test.java:25)

This code looks very simple and innocuous. All you are doing is finding how many times a number has appeared in a array, classic technique to find duplicates in Java array. Developer is getting the previous count, increasing it by one and putting it back into Map. He might have thought that auto-boxing will take care of converting Integer to int , as it doing while calling put method, but he forget that when there is no count exist for a number, get() method of HashMap will return null, not zero because default value of Integer is null not 0, and auto boxing will throw null pointer exception while trying to convert it into an int variable. Imagine if this code is inside an if loop and doesn't run in QA environment but as soon as you put into production, BOOM :-)


6)instanceof operator will return false if used against any reference variable with null value or null literal itself, e.g.

Integer iAmNull = null;
if(iAmNull instanceof Integer){
   System.out.println("iAmNull is instance of Integer");                             

}else{
   System.out.println("iAmNull is NOT an instance of Integer");
}

Output : iAmNull is NOT an instance of Integer

This is an important property of instanceof operation which makes it useful for type casting checks.


7) You may know that you cannot call a non-static method on a reference variable with null value, it will throw NullPointerException, but you might not know that, you can call static method with reference variables with null values. Since static methods are bonded using static binding, they won't throw NPE. Here is an example :            

public class Testing {             
   public static void main(String args[]){
      Testing myObject = null;
      myObject.iAmStaticMethod();
      myObject.iAmNonStaticMethod();                             
   }
              
   private static void iAmStaticMethod(){
        System.out.println("I am static method, can be called by null reference");
   }
              
   private void iAmNonStaticMethod(){
 System.out.println("I am NON static method, don't date to call me by null");
   }
 
}

Output:
I am static method, can be called by null reference
Exception in thread "main" java.lang.NullPointerException
               at Testing.main(Testing.java:11)


8) You can pass null to methods, which accepts any reference type e.g. public void print(Object obj) can be called as print(null). This is Ok from compiler's point of view, but behavior is entirely depends upon method. Null safe method, doesn't throw NullPointerException in such case, they just exit gracefully. It is recommended to write null safe method if business logic allows.

9) You can compare null value using ==  (equal to ) operator and !=  (not equal to) operator, but cannot use it with other arithmetic or logical operator e.g. less than or greater than. Unlike in SQL, in Java null == null will return true, as shown below :

public class Test {

    public static void main(String args[]) throws InterruptedException {
        
       String abc = null;
       String cde = null;
       
       if(abc == cde){
           System.out.println("null == null is true in Java");
       }
       
       if(null != null){
           System.out.println("null != null is false in Java"); 
       }
       
       // classical null check
       if(abc == null){
           // do something
       }
       
       // not ok, compile time error
       if(abc > null){
           
       }
    }
}

Output:
null == null is true in Java

That's all about null in Java. By some experience in Java coding and by using simple tricks to avoid NullPointerExcpetion, you can make your code null safe. Since null can be treated as empty or uninitialized value it's often source of confusion, that's why it's more important to document behavior of a method for null input. Always remember, null is default value of any reference variable and you cannot call any instance method, or access an instance variable using null reference in Java.


9 Difference between TCP and UDP Protocol - Java Network Interview Question

TCP and UDP are two transport layer protocols, which are extensively used in internet for transmitting data between one host to another. Good knowledge of how TCP and UDP works is essential for any programmer. That's why difference between TCP and UDP is one of the most popular programming interview question. I have seen this question many times on various Java interviews , especially for server side Java developer positions. Since FIX (Financial Information Exchange) protocol is also a TCP based protocol, several investment banks, hedge funds, and exchange solution provider looks for Java developer with good knowledge of TCP and UDP. Writing fix engines and server side components for high speed electronic trading platforms needs capable developers with solid understanding of fundamentals including data structure, algorithms and networking. By the way, use of TCP and UDP is not limited to one area, its at the heart of internet. The protocol which is core of internet, HTTP is based on TCP. One more reason, why Java developer should understand these two protocol in detail is that Java is extensively used to write multi-threaded, concurrent and scalable servers. Java also provides rich Socket programming API for both TCP and UDP based communication. In this article, we will learn key differences between TCP and UDP protocol, which is useful to every Java programmers. To start with, TCP stands for Transmission Control Protocol and UDP stands for User Datagram Protocol, and both are used extensively to build Internet applications.




Difference between TCP vs UDP Protocol

I love to compare two things on different points, this not only makes them easy to compare but also makes it easy to remember differences. When we compare TCP to UDP, we learn difference in how both TCP and UDP works, we learn which provides reliable and guaranteed delivery and which doesn't. Which protocol is fast and why, and most importantly when to choose TCP over UDP while building your own distributed application. In this article we will see difference between UDP and TCP in 9 points, e.g. connection set-up, reliability, ordering, speed, overhead, header size, congestion control, application, different protocols based upon TCP and UDP and how they transfer data. By learning these differences, you not only able to answer this interview question better but also understand some important details about two of the most important protocols of internet.


1) Connection oriented vs Connection less
TCP handshake process SYN, SYN-ACK and ACK
First and foremost difference between them is TCP is a connection oriented protocol, and UDP is connection less protocol. This means  a connection is established between client and server, before they can send data. Connection establishment process is also known as TCP hand shaking where control messages are interchanged between client and server. Attached image describe the process of TCP handshake, for example which control messages are exchanged between client and server. Client, which is initiator of TCP connection, sends SYN message to server, which is listening on a TCP port. Server receives and sends a SYN-ACK message, which is received by client again and responded using ACK. Once server receive this ACK message,  TCP connection is established and ready for data transmission. On the other hand, UDP is a connection less protocol, and point to point connection is not established before sending messages. That's the reason, UDP is more suitable for multicast distribution of message, one to many distribution of data in single transmission.


2) Reliability
TCP provides delivery guarantee, which means a message sent using TCP protocol is guaranteed to be delivered to client. If message is lost in transits then its recovered using resending, which is handled by TCP protocol itself. On the other hand, UDP is unreliable, it doesn't provide any delivery guarantee. A datagram package may be lost in transits. That's why UDP is not suitable for programs which requires guaranteed delivery.


3) Ordering
Apart from delivery guarantee, TCP also guarantees order of message. Message will be delivered to client in the same order, server has sent, though its possible they may reach out of order to the other end of the network. TCP protocol will do all sequencing and ordering for you. UDP doesn't provide any ordering or sequencing guarantee. Datagram packets may arrive in any order. That's why TCP is suitable for application which need delivery in sequenced manner, though there are UDP based protocol as well which provides ordering and reliability by using sequence number and redelivery e.g. TIBCO Rendezvous, which is actually a UDP based application.


4) Data Boundary
TCP does not preserve data boundary, UDP does. In Transmission control protocol, data is sent as a byte stream, and no distinguishing indications are transmitted to signal message (segment) boundaries. On UDP, Packets are sent individually and are checked for integrity only if they arrived. Packets have definite boundaries which are honoured upon receipt, meaning a read operation at the receiver socket will yield an entire message as it was originally sent. Though TCP will also deliver complete message after assembling all bytes. Messages are stored on TCP buffers before sending to make optimum use of network bandwidth.


5) Speed
In one word, TCP is slow and UDP is fast. Since TCP does has to create connection, ensure guaranteed and ordered delivery, it does lot more than UDP. This cost TCP in terms of speed, that's why UDP is more suitable where speed is a concern, for example online video streaming, telecast or online multi player games.


6) Heavy weight vs Light weight
Because of the overhead mentioned above, Transmission control protocol is considered as heavy weight as compared to light weight UDP protocol. Simple mantra of UDP to deliver message without bearing any overhead of creating connection and guaranteeing delivery or order guarantee keeps it light weight. This is also reflected in their header sizes, which is used to carry meta data.


7) Header size
TCP has bigger header than UDP. Usual header size of a TCP packet is 20 bytes which is more than double of 8 bytes, header size of UDP datagram packet. TCP header contains Sequence Number, Ack number, Data offset, Reserved, Control bit, Window, Urgent Pointer, Options, Padding, Check Sum, Source port, and Destination port. While UDP header only contains Length, Source port, Destination port, and Check Sum. Here is how TCP and UDP header looks like :

TCP Header Format

UDP Header Format 



8) Congestion or Flow control
TCP does Flow Control. TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control. On the other hand, UDP does not have an option for flow control.


9) Usage and application
Where does TCP and UDP are used in internet? After knowing key differences between TCP and UDP, we can easily conclude, which situation suits them. Since TCP provides delivery and sequencing guaranty, it is best suited for applications that require high reliability, and transmission time is relatively less critical. While UDP is more suitable for applications that need fast, efficient transmission, such as games. UDP's stateless nature is also useful for servers that answer small queries from huge numbers of clients. In practice, TCP is used in finance domain e.g. FIX protocol is a TCP based protocol, UDP is used heavily in gaming and entertainment sites.


10) TCP and UDP based Protocols
One of the best example of TCP based higher end protocol is HTTP and HTTPS, which is every where on internet. In fact most of the common protocol you are familiar of e.g. Telnet, FTP and SMTP all are based over Transmission Control Protocol. UDP don't have any thing as popular as HTTP but UDP is used in protocol like DHCP (Dynamic Host Configuration Protocol) and DNS (Domain Name System). Some of the other protocol, which is based over User Datagram protocol is Simple Network Management Protocol (SNMP), TFTP, BOOTP and NFS (early versions).


That's all about difference between TCP and UDP protocol. Always remember to mention that TCP is connection oriented, reliable, slow, provides guaranteed delivery and preservers order of messages, while UDP is connection less, unreliable, no ordering guarantee, but fast protocol. TCP overhead is also much higher than UDP, as it transmits more meta data per packet than UDP. It's worth mentioning that header size of Transmission control protocol is 20 bytes, compared to 8 bytes header of User Datagram protocol. Use TCP, if you can't afford to lose any message, while UDP is better for high speed data transmission, where loss of single packet is acceptable e.g. video streaming or online multi player games. While working in TCP/UDP based application on Linux, it's also good to remember basic networking commands e.g. telnet and netstat, they help tremendously to debug or troubleshoot any connection issue.

Thursday, 22 January 2015

Must know about Strings in JAVA

1) Strings are not null terminated in Java.
 
Unlike C and C++, String in Java doesn't terminate with null character. Instead String are Object in Java and backed by character array. You can get the character array used to represent String in Java by calling toCharArray() method of java.lang.String class of JDK.

2) Strings are immutable and final in Java
 
Strings are immutable in Java it means once created you cannot modify content of String. If you modify it by using toLowerCase(), toUpperCase() or any other method,  It always result in new String. Since String is final there is no way anyone can extend String or override any of String functionality. Now if you are puzzled why String is immutable or final in Java. checkout the link.

3) Strings are maintained in String Pool
 
Advanced Java String tutorial and example programmers As I Said earlier String is special class in Java and all String literal e.g. "abc"  (anything which is inside double quotes are String literal in Java) are maintained in a separate String pool, special memory location inside Java memory, more precisely inside PermGen Space. Any time you create a new String object using String literal, JVM first checks String pool and if an object with similar content available, than it returns that and doesn't create a new object. JVM doesn't perform String pool check if you create object using new operator.
You may face subtle issues if you are not aware of this String behaviour , here is an example

String name = "Scala"; //1st String object
String name_1 = "Scala"; //same object referenced by name variable
String name_2 = new String("Scala") //different String object
//this will return true
if(name==name_1){
System.out.println("both name and name_1 is pointing to same string object");
}
//this will return false
if(name==name_2){
System.out.println("both name and name_2 is pointing to same string object");
}

if you compare name and name_1 using equality operator "==" it will return true because both are pointing to same object. While name==name_2 will return false because they are pointing to different string object. It's worth remembering that equality "==" operator compares object memory location and not characters of String. By default Java puts all string literal into string pool, but you can also put any string into pool by calling intern() method of java.lang.String class, like string created using new() operator.

4) Use Equals methods for comparing String in Java
 
String class overrides equals method and provides a content equality, which is based on characters, case and order. So if you want to compare two String object, to check whether they are same or not, always use equals() method instead of equality operator. Like in earlier example if  we use equals method to compare objects, they will be equal to each other because they all contains same contents. Here is example of comparing String using equals method.

String name = "Java"; //1st String object
String name_1 = "Java"; //same object referenced by name variable
String name_2 = new String("Java") //different String object
if(name.equals(name_1)){
System.out.println("name and name_1 are equal String by equals method");
}
//this will return false
if(name==name_2){
System.out.println("name_1 and name_2 are equal String by equals method");
}

You can also check my earlier post difference between equals() method and == operator for more detail discussion on consequences of comparing two string using == operator in Java.

5) Use indexOf() and lastIndexOf() or matches(String regex) method to search inside String
 
String class in Java provides convenient method to see if a character or sub-string or a pattern exists in current String object. You can use indexOf() which will return position of character or String, if that exist in current String object or -1 if character doesn't exists in String. lastIndexOf is similar but it searches from end. String.match(String regex) is even more powerful, which allows you to search for a regular expression pattern inside String. here is examples of indexOf, lastIndexOf and matches method from java.lang.String class.

String str = "Java is best programming language";
if(str.indexOf("Java") != -1){
     System.out.println("String contains Java at index :" + str.indexOf("Java"));
}
if(str.matches("J.*")){
     System.out.println("String Starts with J");
}
str ="Do you like Java ME or Java EE";
if(str.lastIndexOf("Java") != -1){
      System.out.println("String contains Java lastly at: " + str.lastIndexOf("Java"));
}

As expected indexOf will return 0 because characters in String are indexed from zero. lastIndexOf returns index of second “Java”, which starts at 23 and matches will return true because J.* pattern is any String starting with character J followed by any character because of dot(.) and any number of time due to asterick (*).
Remember matches() is tricky and some time non-intuitive. If you just put "Java" in matches it will return false because String is not equals to "Java" i.e. in case of plain text it behaves like equals method. See here for more examples of String matches() method.
Apart from indexOf(), lastIndexOf() and matches(String regex) String also has methods like startsWith() and endsWidth(), which can be used to check an String if it starting or ending with certain character or String.

6) Use SubString to get part of String in Java
 
Java String provides another useful method called substring(), which can be used to get parts of String. basically you specify start and end index and substring() method returns character from that range. Index starts from 0 and goes till String.length()-1. By the way String.length() returns you number of characters in String, including white spaces like tab, space. One point which is worth remembering here is that substring is also backed up by character array, which is used by original String. This can be dangerous if original string object is very large and substring is very small, because even a small fraction can hold reference of complete array and prevents it from being garbage collected even if there is no other reference for that particular String. Read How Substring works in Java for more details. Here is an example of using SubString in Java:
String str = "Java is best programming language";
    
//this will return part of String str from index 0 to 12
String subString = str.substring(0,12);
    
System.out.println("Substring: " + subString);

7) "+" is overloaded for String concatenation
 
Java doesn't support Operator overloading but String is special and + operator can be used to concatenate two Strings. It can even used to convert int, char, long or double to convert into String by simply concatenating with empty string "". internally + is implemented using StringBuffer prior to Java 5 and StringBuilder from Java 5 onwards. This also brings point of using StringBuffer or StringBuilder for manipulating String. Since both represent mutable object they can be used to reduce string garbage created because of temporary String. Read more about StringBuffer vs StringBuilder here.
     
8) Use trim() to remove white spaces from String
 
String in Java provides trim() method to remove white space from both end of String. If trim() removes white spaces it returns a new String otherwise it returns same String. Along with trim() String also provides replace() and replaceAll() method for replacing characters from String. replaceAll method even support regular expression. Read more about How to replace String in Java here.

9) Use split() for splitting String using Regular expression
 
String in Java is feature rich. it has methods like split(regex) which can take any String in form of regular expression and split the String based on that. particularly useful if you dealing with comma separated file (CSV) and wanted to have individual part in a String array. There are other methods also available related to splitting String, see this Java tutorial to split string for more details.

10) Don't store sensitive data in String
 
String pose security threat if used for storing sensitive data like passwords, SSN or any other sensitive information. Since String is immutable in Java there is no way you can erase contents of String and since they are kept in String pool (in case of String literal) they stay longer on Java heap ,which exposes risk of being seen by anyone who has access to Java memory, like reading from memory dump. Instead char[] should be used to store password or sensitive information. See Why char[] is more secure than String for storing passwords in Java for more details.


11) Character Encoding and String

Apart from all these 10 facts about String in Java, the most critical thing to know is what encoding your String is using. It does not make sense to have a String without knowing what encoding it uses. There is no way to interpret an String if you don't know the encoding it used. You can not assume that "plain" text is ASCII. If you have a String, in memory or stored in file, you must know what encoding it is in, or you cannot display it correctly. By default Java uses platform encoding i.e. character encoding of your server, and believe me this can cause huge trouble if you are handling Unicode data, especially if you are converting byte array to XML String. I have faced instances where our program fail to interpret Strings from European language e.g. German, French etc. because our server was not using Unicode encodings like UTF-8 or UTF-16. Thankfully, Java allows you to specify default character encoding for your application using system property file.encoding. See here to read more about character encoding in Java

That's all about String in Java. As I have said String is very special in Java, sometime even refer has God class. It has some unique feature like immutability, concatenation support, caching etc, and to become a serious Java programmer, detailed knowledge of String is quite important. Last but not the least don't forget about character encoding while converting a byte array into String in Java. Good knowledge of java.lang.String is must for good Java developers.

How to make Altenate Heap?

/*
Here is the Solution in java language. Code has two classes...
 1> Main
 2> AlternateHP 
 */

import java.util.Scanner;

public class Main {
    private static Scanner s;

    public static void main(String args[])throws Exception
    {       
        s = new Scanner(System.in);
        System.out.println("how many element u want to sort->");
        int n=Integer.parseInt(s.nextLine());
       
        int[] a=new int[n+1];
       
        System.out.println("eneter elements->");
        for(int i=1;i<=n;i++)
        {
            a[i]=Integer.parseInt(s.nextLine());
        }
        AlternateHP h=new AlternateHP(a);
       
        h.BuildHeap(a);
       
        for(int i=1;i<=n;i++)
        {
            System.out.println(a[i]);
        }
       
    }

}
 

public class AlternateHP {
   
    public static  int i=1;
    public int p;
    public static int q=0;
    public int heapsize;
    AlternateHP(int a[])
    {
       
        heapsize=a.length-1;
        p=heapsize/2;
    }

    public void BuildHeap(int[] a) {
        int row=1;
       
        while(i!=p+1)
        {
           
            if(row%2==1)
            {
                int c=1;
                while(c<=(int)Math.pow(2, row-1) && i<=p)
                {
                    //System.out.println("min");
                    this.MinHeapify(a, i);
                    i++;
                    c++;
                }
            }
            if(row%2==0)
            {
                int c=1;
                while(c<=(int)Math.pow(2, row-1) && i<=p)
                {
                    //System.out.println("max");
                    this.MaxHeapify(a, i);
                    i++;
                    c++;
                }
            }
            row++;
        }
       
    }
    public void MaxHeapify(int[] a,int i)
    {
       
        int largest;
        int l=(2*i);
        int r=(2*i)+1;

        if(l<=heapsize && a[l]>a[i])
        {
        largest=l;
        }
        else
        {
            largest=i;
        }
        if(r<=heapsize && a[r]>a[largest])
        {
            largest=r;
        }
        if(largest!=i)
        {
            int temp=a[i];
            a[i]=a[largest];
            a[largest]=temp;
        }
    }
    public void MinHeapify(int[] a,int i)
    {
       
        int smallest;
        int l=(2*i);
        int r=(2*i)+1;

        if(l<=heapsize && a[i]>a[l])
        {
             smallest=l;
        }
        else
        {
             smallest=i;
        }
        if(r<=heapsize && a[r]<a[ smallest])
        {
             smallest=r;
        }
        if( smallest!=i)
        {
            int temp=a[i];
            a[i]=a[ smallest];
            a[ smallest]=temp;
        }
    }
    public void swap(int[] a,int p, int q)
    {
        int t=a[p];
        a[p]=a[q];
        a[q]=t;
    }
   
}

Thursday, 25 December 2014

How much prize money is given to " Bharat Ratna " awardees ???


‘Bharat Ratna: The highest civilian Award of the country, was instituted in the year 1954.
  • Any person without distinction of race, occupation, position or sex is eligible for these awards.
  • It is awarded in recognition of exceptional service/performance of the highest order in any field of human endeavour.
  • The recommendations for Bharat Ratna are made by the Prime Minister himself to the President. No formal recommendations for this are necessary.
  • The number of annual awards is restricted to a maximum of three in a particular year.
  • On conferment of the award, the recipient receives a Sanad (certificate) signed by the President and a medallion.
  • In terms of Article 18 (1) of the Constitution , the award cannot be used as a prefix or suffix to the recipient's name. However, should an award winner consider it necessary, he/she may use the following expression in their bio-data/letterhead/visiting card etc. to indicate that he/she is a recipient of the award: ‘Awarded Bharat Ratna by the President’ or ‘Recipient of Bharat Ratna Award’
  • The Award does not carry any monetary grant.  Since it is highest award, it has several emoluments and perks.  But Some important ones are:
  1. Free first class flight journey anywhere in India.
  2. Free first class train journey.
  3. Pension equal to or 50% of Prime Minister of India's salary.
  4.  Can attend the Parliament meetings and sessions.
  5. Precedence at par with Cabinet Rank.
  6.  Eligible for Z category protection, if needed.
  7. Special Guest in Republic Day and Independence Day.
  8. Status equal to VVIP.


The Bharat Ratna holders however, come 7th in the Indian order of precedence

The Bharat Ratna holders however, come 7th in the Indian order of precedence behind:
  1. The President
  2. The Vice-President
  3. The Prime Minister
  4. The State Governors
  5. The former Presidents and the Deputy Prime Minister
  6. The Lok Sabha Speaker and Chief Justice of India
  7. Bharat Ratna Winners


Wednesday, 24 December 2014

The top 4 civilian honors of india

Bharat Ratna : The decoration is in the form of a peepal leaf, about 5.8 cm long, 4.7 cm wide and 3.1 mm thick. It is of toned bronze. On its obverse is embossed a replica of the sun, 1.6 cm in diameter, below which the words Bharat Ratna are embossed in Devanagari script. On the reverse are State emblem and the motto, also in Devanagari. The emblem, the sun and the rim are of platinum. The inscriptions are in burnished bronze.

Padma Vibhushan : The badge design is "mainly circular" 1-3/16-inch burnished bronze (changed from toned bronze in 1957) badge with geometrical patterns. The center had a lotus flower with four major petals embossed in white gold. Above and below this flower, the name of the decoration Padma Vibhushan was embossed in silver-gilt.

Padma Bhushan : The badge design is "mainly circular" 1-3/16-inch burnished bronze (changed from toned bronze in 1957) badge with geometrical patterns. The center had a lotus flower with three major petals embossed in white gold. Above and below this flower, the name of the decoration Padma Bhushan was embossed in silver-gilt.

Padma Shri : On its obverse, the words "Padma", meaning lotus in Sanskrit and "Shri", in Devanagari, appear above and below a lotus flower. The geometrical pattern on either side is in burnished bronze. All embossing is in white gold.



Blog Archive