From the course: Java 8 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Passing arguments to a console application

Passing arguments to a console application - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Passing arguments to a console application

- When you run a java class from the console or a command prompt, the run time looks for the main method, and you can pass values, known as arguments, into that main method as strings. For this demonstration, I'll use the Main.java file in the Arguments folder under the Exercise folder. You can open this, again, with any text editor. And I'll open it, as I did before, with Notepad. When you run from the console, you can pass string values in, and they'll show up in this array of strings. You can address each item in the array individually using the name of the array, a pair of brackets, and an index or a numeric value. So, for example, if I wanted to output a value, which is the first argument passed in on the command line, I would once again use System.out.println and then I would use this expression: args[0]. The first item in the array has an index value of zero. Java always uses zero based array indexing. I'll save that change, and then, once again, I'll go to a command prompt…

Contents