2. Write a program in java to print "Hello Name" where Name will be passed as command line argument at run time.
Solution:
class User{
public static void main(String[] args){
String name = args[0];
System.out.println("Hello "+name);
}
}
After compilation, run this program as follows and watch the output in next line:
prompt>java User Amit
Hello Amit
Caution: if nothing is passed from command line argument, it will show an Run-time Exception as ArrayIndexOutOfBoundsException, as there will be no element in the String array 'args'.
Back to Exercise
Solution:
class User{
public static void main(String[] args){
String name = args[0];
System.out.println("Hello "+name);
}
}
After compilation, run this program as follows and watch the output in next line:
prompt>java User Amit
Hello Amit
Caution: if nothing is passed from command line argument, it will show an Run-time Exception as ArrayIndexOutOfBoundsException, as there will be no element in the String array 'args'.
Back to Exercise
Nice Blog... Thank you for sharing this information..
ReplyDeleteProvident Kenworth
Vaswani Menlo Park
Marina Skies
I would like to say that you are an amazing blogger...You can inspired me to write blogs for
ReplyDeleteEscort service in Jaipur
Escort service in Jaipur
Escort service in Jaipur
Escort service in Delhi
Escort service in Guwahati
Escort service in Guwahati
Escort service in Guwahati
Escort service in Guwahati
Escort service in Lucknow
Escort service in Aerocity