Posts

Showing posts from 2014

Java Variable Arguments

Java variable arguments (varargs) was introduced in java 1.5.usage of varargs is  if u want to pass more arguments to the method say example more than 3 or 4 of same data type then we can go for varargs which makes the code simple and neat. Before varargs developer used two options creating a collection like list or set and passing all the data with that overloading  method with different parameter  But we have some disadvantages  in the methods mentioned above lets  take method overloading private int varargsDemo(int i, int j) {         int result =i*j;         return result;     }        private int varargsDemo(int i, int j,int k) {         int result =i*j*k;         return result;     } Here you can see if you use overloading your code becomes little clumsy and you need to create more number of overloading methods also the main thing is you should know the max number of arguments you want to pass before your write the code. now consider collections     pr

Why serialVersionUID Is Required??

Image
   serialVersionUID is used to identify the class during deserialization process.if you don't mention serialVersionUID in your class then  by default JVM will generate it . JVM generated  serialVersionUID will be a 64 bit hash value of class name ,method and fields.But there is a problem in not declaring serialVersionUID manually. Let me explain it with the example ,   This is my class which i want to serialize public class Employee implements Serializable {         /**      *      */     public int getEmpId() {         return empId;     }     public void setEmpId(int empId) {         this.empId = empId;     }     public String getEmpName() {         return empName;     }     public void setEmpName(String empName) {         this.empName = empName;     }     private int empId;     transient private String empName; } In the above code i didn't  declare serialVersionUID. Below code used to serialize the Employee object public class Serializ

Call Handle Bar Helper Function From Another Helper Function

Hi all, This is my new post after long time :P                                I am Learning Handlebar now :) I am not going to explain you the basics of handlebar and make my post as bored one .Instead let me explain the feature which most of us don't know. If you are new to handlebar here is the link you can refer it and learn basics                                 http://handlebarsjs.com/ From the above link you will get to know there is  a feature called helper function in handlebars . Here i am going to explain how to call a helper function from another helper function. some times  you may get into a situation where you want to perform some operation as the result of another in that situation you can use this logic.  Template      This is my template , {{#checkAndFormat "India"}}{{/checkAndFormat}}              Helper 1:                           Handlebars.registerHelper('checkAndFormat', function (value, options) {     var s