From the course: Java 8+ Essential Training: Syntax and Structure

Unlock the full course today

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

Pass arguments to a console application

Pass arguments to a console application - Java Tutorial

From the course: Java 8+ Essential Training: Syntax and Structure

Start my 1-month free trial

Pass arguments to a console application

- [Instructor] The main method of a Java class accepts an array of strings. These strings are provided by passing in values or parameters from the command line, and I'll show you how to do this using a project that I've already created. From the welcome screen, I'll choose Open. Then I'll go to my Desktop where I've placed my Exercise Files. On Windows, I can press Control + D, and on Mac, press Command + D. Then I'll drill down into my Exercise Files to chapter two, 02_07, and I'll open the project PassArgs. This is a beginning Java class with an empty main method. When you receive these arguments, they're received as an array of strings. An array is an ordered set of values. Here's some pretty standard code for looping through those values. I'll place the cursor inside the main method, then I'll type the expression foreach, all one word, lowercase. Then I'll press Tab, and that expands to some mysterious syntax. Now, just follow along with the code, and I'll explain what it's doing…

Contents