Core Java Interview Questions – Command Line Arguments

This Core Java Interview Questions-Command Line Arguments page provides all the core java interview questions on command line arguments including why we need to compile and run the java application from the command prompt, what is the signature of the main method, why the main signature is of type string and many more questions with suitable answers.


Why is main method signature String array?
Used to read command line arguments in java application.


What are command line arguments in Java?
Passing input values(arguments) to the program from the command prompt while invoking the application.


Who will collect command line arguments in the program?
main(String args[]) collects these arguments and store into an array of type String.


Why Java application invocation from the command prompt?
The command prompt is Operating System which gives permission to run every program.


Why arguments array of type String ?
main(int[ ]) can collects only integers.
main(float[ ]) can collect only float values.
but main(String[ ])can collects any type of input data values from command line.


How to process command line String arguments?
We can use String to primitive conversions to process arguments in case of int, float , double…


How to find length of command line arguments array?
Using pre-defined “length” variable of Array class.


What is the output if we try to access an element which is out of bounds in arguments array?
It causes Runtime error (ArrayIndexOutOfBoundsException)


>Core Java Interview Questions – OOPS<

Share this