TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Java Tutorials

Command Line Arguments

Overview

This tutorial will teach you how to handle command-line arguments in a Java program. The command line argument is the argument/data passed to the program when we run it.

The arguments are stored in a String array called args that are passed to the Java main() method.

public static void main(String[] args)

Java Program Example

The command line arguments that are passed from the console are stored in a String array and can be retrieved in the Java program.

Let’s write a simple Java program to understand the concept. The following program will print the command line arguments each in a separate line.

/*
 * Command line arguments demo
 * Java Tutorials - www.TestingDocs.com
 */

public class JavaApplication {

 public static void main(String[] args) {
 for (int i = 0; i < args.length; i++) {
 System.out.println(args[i]);
 }
 }
}

Command Line Arguments Java

In Eclipse, Run >> Run Configurations… choose the program and click the arguments tab to provide the Program arguments.

IntelliJ IDE

In IntelliJ IDE we can set the program arguments for the Java application in the run configuration.

Run >> Edit Configurations >> Application >> Program arguments

 

IntelliJ Java Program Arguments

That’s it.

—

Java Tutorials

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/java/

Related Posts

Download Greenfoot Windows

Java Tutorials /

Download & Install Greenfoot on Windows

Java Tutorials /

Java Static Code Analysis

Java Tutorials /

Java Testing Tools

Java Tutorials /

Handle Multiple Exceptions in Java

Exceptions_In_Java

Java Tutorials /

Exceptions in Java Programs

‹ Types of Java Packages› Java Tokens

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version