Search This Blog

Tuesday, 3 January 2012

Power of ... in Java

you can pass the any number of paramters when u specified(...). Normally it holds the data in array format.  Consider the below examples.
class ParameterExample
{
    public static void main(String... ag) //it same as String[] ag
    {
        String ary[]=ag;
        System.out.println(ary.length);
    }
}







class ParameterExample
{
    public static void main(String... ag) //it same as String[] ag
    {
        stringDisplay("H","A","I");
    }
    static void stringDisplay(String...a) //it get the data as Array Format
    {
        for(String o:a)
        System.out.print(o);
    }
   
}

Tuesday, 11 October 2011

Getting Tomorrow Date using Java Example

public class TomorrowDate{
       public static void main(String[] av) {

               Date date = new Date();
               long t = date .getTime();
               t += 1*24*60*60*1000;
               Date tDate= new Date(t);
               SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
               String s = formatter.format(tDate);
               System.out.println("TomorrowDate is "+s);

       }
}