http://www.technicalpage.net/search/label/SQL

Program Arguments and VM Arguments :




package PackageName;
import java.util.Arrays;
import java.util.regex.Pattern;
 
public class Arguments
{
    public static void main(String[] args) 
    {


                     System.out.println("------ Program Arguments ------");
                     System.out.println("Program Argument 0= "+args[0]);
                     System.out.println("Program Argument 1= "+args[1]);
                     System.out.println("Program Argument 2= "+args[2]);
                     System.out.println("Program Argument 3= "+args[3]);
                     System.out.println("Program Argument 4= "+args[4]);
                     System.out.println("Program Argument 5= "+args[5]);
                     System.out.println("Program Argument 6= "+args[6]);
                     System.out.println("\nProgram Argument "+ Arrays.asList(args)); //returns all the elements
                    
                     System.out.println("\n\n------ Using For loop ------");

                     for(String arg : args){
                           System.out.println("Index of the element "+ Arrays.asList(args).indexOf(arg));//index of the element.(getting index of string element is not that easy. So this code is important.)
                           System.out.println("Value of the element "+ Arrays.asList(arg)); // returns the element(value of the respective element)       
                           System.out.println("Program Argument Value_"+ Arrays.asList(args).indexOf(arg)+" = "+Arrays.asList(arg));
                           System.out.println();            
                     }
                    
                     System.out.println("\n\n------- VM Arguments -------");
                     System.out.println("VM Argument 1= "+System.getProperty("systemProperty1"));
                     System.out.println("VM Argument 3= "+System.getProperty("environment"));
                     System.out.println("VM Argument 3= "+System.getProperty("release"));
      
    }
}


OutPut:
------ Program Arguments ------
Program Argument 0= Test1
Program Argument 1= Test2
Program Argument 2= Test3
Program Argument 3= Test4
Program Argument 4= Test5
Program Argument 5= Test6
Program Argument 6= Test7

Program Argument [Test1, Test2, Test3, Test4, Test5, Test6, Test7, Test8, Test9, Test10]


------ Using For loop ------
Index of the element 0
Value of the element [Test1]
Program Argument Value_0 = [Test1]

Index of the element 1
Value of the element [Test2]
Program Argument Value_1 = [Test2]

Index of the element 2
Value of the element [Test3]
Program Argument Value_2 = [Test3]

Index of the element 3
Value of the element [Test4]
Program Argument Value_3 = [Test4]

Index of the element 4
Value of the element [Test5]
Program Argument Value_4 = [Test5]

Index of the element 5
Value of the element [Test6]
Program Argument Value_5 = [Test6]

Index of the element 6
Value of the element [Test7]
Program Argument Value_6 = [Test7]

Index of the element 7
Value of the element [Test8]
Program Argument Value_7 = [Test8]

Index of the element 8
Value of the element [Test9]
Program Argument Value_8 = [Test9]

Index of the element 9
Value of the element [Test10]
Program Argument Value_9 = [Test10]



------- VM Arguments -------
VM Argument 1= Property1
VM Argument 3= Test
VM Argument 3= Fifth
 

No comments:

Post a Comment