|
| |||||||||
| Tags: argument, arguments, command line, echo, jav |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| What are Command-Line Arguments in Java?
Hi friends, I have recently started working with the Core Java. Now I am working with the basic classes that are used in Java. I want to know how command line arguments are passed in Java.? Since, you have solved my issues many times I thought that posting here would be helpful. Please tell me what are Command-Line Arguments in Java.?? Any other information would be grateful.!! ![]()
__________________ AMD Sempron 2800+ @ 2Ghz Asus A7V8X-LA 120Gb Seagate barracuda 7200Rpm Ultra-ATA 100 Elixir 512mb DDR Pc3200 (Soon 1Gb) Club 3D Radeon 9600 256Mb Lite-On Cd & Dvd writer combo IDE-Dvd drive 400w Psu Windows Xp Pro Sp2 Advent Wireless Mouse & Keyboard. |
|
#2
| ||||
| ||||
| Re: What are Command-Line Arguments in Java?
You can put any number of arguments in your Java application because, your Java application can accept any number of arguments from the command line. Command-line arguments allow the user to affect the operation of an application. It is not necessary for the operating system to also pass a parameter specifying the number of arguments. The user can enter command-line arguments when invoking the application. When running the java program from java command, the arguments are provided after the name of the class separated by space. You will come to know more about this while doing the coding. |
|
#3
| ||||
| ||||
| Re: What are Command-Line Arguments in Java?
You will have to enter the command-line arguments when invoking the application. Lets take an example so that it would be useful for you to understand the concepts. Suppose a Java application called Align sorts lines in a file. To sort the data in a file named people.txt, a user would enter: Code: java Align people.txt |
|
#4
| ||||
| ||||
| Re: What are Command-Line Arguments in Java?
You are not having an idea of how to pass the command line arguments, so I thought that giving an demonstration would help you. The following example explains the same : Code: public class CmdArgsDemo{
public static void main(String[] args){
System.out.println("The following command line arguments were passed:");
for (int i=0; i < args.length; i++){
System.out.println("arg[" + i + "]: " + args[i]);
}
}
} |
|
#5
| ||||
| ||||
| Re: What are Command-Line Arguments in Java?
The user enters command-line arguments when invoking the application and specifies them after the name of the class to be run. The Java syntax for command-line arguments is as follows : Code: public static void main(String[] args){
. . .
} |
|
#6
| ||||
| ||||
| Re: What are Command-Line Arguments in Java?
The Echo example displays each of its command-line arguments on a line by itself : Code: public class ExampleEcho {
public static void main (String[] args) {
for (String s: args) {
System.out.println(s);
}
}
}
__________________ The FIFA Manager 2009 PC Game |
|
#7
| ||||
| ||||
| Re: What are Command-Line Arguments in Java?
If an application needs to support a numeric command-line argument, it must convert a String argument that represents a number. So i have provided you with a code snippet that converts a command-line argument to an int : Code: int oneArg;
if (args.length > 0) {
try {
oneArg = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
System.err.println("Argument must be an integer");
System.exit(1);
}
}
__________________ Grand Theft Auto 4 PC Video Game |
|
#8
| |||
| |||
| Re: What are Command-Line Arguments in Java?
This simple application displays each of its command line arguments on a line by itself: class Echo { public static void main (String args[]) { for (int i = 0; i < args.length; i++) System.out.println(args[i]); } So hopefully this command line useful in your programming feature. All the Best!! Sophie Johnson |
|
#9
| ||||
| ||||
| What are Command-Line Arguments in Java?
Thank you for replying me and giving me explanation about what are Command-Line Arguments in Java and explanation it in details. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "What are Command-Line Arguments in Java?" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Windows Phone 7 Error: Connection failed because of invalid command-line arguments | Saqlain | Portable Devices | 3 | 28-10-2010 01:16 PM |
| Command Line Arguments in java | Vipul03 | Software Development | 2 | 22-02-2010 04:39 PM |
| I/O from the Command Line in Java | Damien25 | Software Development | 5 | 19-02-2010 12:22 AM |
| PHP command line arguments | Sori | Software Development | 3 | 24-09-2009 01:45 PM |
| How to get command line arguments for windows application in c# | Aaryn | Software Development | 2 | 08-07-2009 01:11 AM |