Java Tutorial
IntroductionEnvironment SetupIDEBuild ManagementLanguage SpecificationBasic ProgramVariablesData TypesPackagesModifiersConditionalsLoopsObject OrientedClassesSuperInterfacesEnumStatic importInheritanceAbstractionEncapsulationPolymorphismBoxing & UnboxingConversion Formatting numbers Arrays Command line arguments in java Variable Number of arguments in Java Exception handling in Java String handling in Java StringBuffer and StringBuilder in Java Mathematical Operations in Java Date and Time in Java Regular expressions in Java Input output programming in Java File Handling Nested Classes Collections Generics Serialization Socket programming Multi-Threading Annotations Lambda Expressions Reflections in Java Singleton class in Java Runtime Class in JavaHow to load resource in JavaHow to load properties file in JavaAdvanced
Log4j – Logging framework in JavaInterview Questions in JavaWe can pass the input arguments to the Java program through command line. main() method accepts those arguments in the form of string array. Below example explains how we can use command line arguments in Java.
package commandline;
/**
* Created by ssalunke on 20/04/2016.
*/
public class CommandLine {
public static void main(String [] args) {
//javac commandline/CommandLine.java
//java -cp . commandline.CommandLine sagar salunke
System.out.println("Total number of arguments -> " + args.length);
System.out.println("value of first argument -> " + args[0]);
System.out.println("value of second argument -> " + args[1]);
}
}
Here is the output of above example.
Total number of arguments -> 2
value of first argument -> Sagar
value of second argument -> Salunke
Web development and Automation testing
solutions delivered!!