Command Line Argument
In Java, command line argument is an argument i.e passed at the time of java program run.
In main method there is a single dimension array of String type, that we use to take arguments.
You can pass N (1,2,3 and so on) numbers of arguments from the command prompt.
Example :
In below example, we are receiving only one argument and print the value.
public class CommandLineDemo { public static void main(String []ar) { String arg1 = ar[0]; System.out.println("Argument is: "+arg1); } }OUTPUT : To run this program you have to pass at-least one argument, otherwise you will get exception.
COMPILE : javac CommandLineDemo.java RUN : java CommandLineDemo JavaProwess [ OUTPUT ] JavaProwess
Example :
In this example, we will take N numbers of argument and print all value,Remember, after every space runtime will indexed the argument for array.
class CommandLineDemo { public static void main(String []ar) { for(int i=0;i< ar.length;i++) System.out.print(ar[i]+" "); } }OUTPUT :
COMPILE : javac CommandLineDemo.java RUN : java CommandLineDemo C C++ and Java Prowess [ OUTPUT ] C C++ and Java Prowess
Next topic is Input/Output
Training For College Campus
We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies
like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.
Please mail your requirement at info@prowessapps.in
Projects For Students
Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.
Students can mail requirement at info@prowessapps.in