Java Command Line Arguments Interview MCQ Questions and Answers

Study and learn Interview MCQ Questions and Answers on Command Line Arguments in Java. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.

Go through Java Theory Notes on Command Line Arguments before reading these objective questions.



1) A command-line argument in Java is a value passed at the time of ___ a program.
A) Compiling
B) Running
C) -
D) -
Answer [=]
Answer[=]
2) Command-line arguments help in a way of ____ data to a program.
A) Inputting
B) Outputting
C) -
D) -
Answer [=]
Answer[=]
3) The command-line arguments are passes at ____.
A) Runtime
B) the time of executing a Java program.
C) the time of compiling a Java program.
D) None
Answer [=]
Answer[=]
4) When a Java program is executed once, how many times can you pass data using the Command-line arguments?
A) 1
B) 8
C) 16
D) None
Answer [=]
Answer[=]
5) If you need to accept data at runtime, you use ___ in Java.
A) Command-line arguments
B) Java IO statements
C) -
D) -
Answer [=]
Answer[=]
6) Which is the method that accepts data passed in the form of command-line arguments in Java?
A) show() method
B) main() method
C) display() method
D) print() method
Answer [=]
Answer[=]
7) The command-line arguments in Java are used along with a ____ command.
A) javac
B) java or javaw
C) javap
D) All the above
Answer [=]
Answer[=]


 

8) The type of Arguments the MAIN method accepts is ___.
A) Integer[]
B) Float[]
C) Long[]
D) String[]
Answer [=]
Answer[=]
9) The data that is passed at the time of running a Java program as command-line arguments are converted into ___ data type.
A) Integer array
B) Float array
C) Character array
D) String array
Answer [=]
Answer[=]
10) The delimiter used to separate command-line arguments in Java is ____.
A) Semicolon (;)
B) Colon (:)
C) Space
D) Comman (,)
Answer [=]
Answer[=]
11) Can you pass a sentence with multiple words separated by spaces as a single command-line argument in Java?
A) Yes
B) No
C) -
D) -
Answer [=]
Answer[=]
12) What is the output of the below Java program with command-line arguments?
public class CommandLineArgs1
{
  public static void main(String[] args)
  {
    for(String str: args)
    {
      System.out.println(str);
    }
    if(args.length == 0)
      System.out.println("No arguments passed");
}
c:\folder>java CommandLineArgs1 car brake horn
A)
car brake horn
B)
car
brake
horn
C)
horn brake car
D)
horn
brake
car
Answer [=]
Answer[=]
13) Is there any limit to the number of spaces between two arguments of command-line arguments in Java?
A) Yes
B) No
C) -
D) -
Answer [=]
Answer[=]
14) To pass a string as a command-line argument in Java, you need to surround the text within a pair of ___.
A) Single Quotes ('abc def')
B) Double Quotes ("abc def")
C) Double Spaces(  abc def  )
D) Triple Single Quotes ('''abc  def''')
Answer [=]
Answer[=]


 

15) Choose the correct way of receiving command-line arguments with in the MAIN method in Java?
A)
public static void main(String[] args)
{

}
B)
public static void main(String args[])
{

}
C)
public static void main(String anyName[])
{

}
D) All the above.
Answer [=]
Answer[=]
16) what is the output of the below Java program with command-line arguments?
public class CommandLineArguments2
{
  public static void main(String[] args)
  {
    System.out.println(args[1]);
  }
}

C:\folder>java CommandLineArguments2 TIGER
A) CommandLineArguments2
B) TIGER
C) Compiler error
D) None
Answer [=]
Answer[=]
17) Which is the exception or error that is thrown if a non-existing command-line argument is referred to in a Java program?
A) StackOverflowError
B) IndexOutOfBoundsException
C) ArrayIndexOutOfBoundsException
D) ArithmeticException
Answer [=]
Answer[=]
18) Any type of data that can be typed on a console or ECLIPSE can be passed as a command-line argument. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
Answer[=]
19) Which are the methods used to parse string values to the respective data types in Java?
A) Boolean.parseBoolean(), Byte.parseByte()
B) Integer.parseInt(), Long.parseLong()
C) Float.parseFloat(), Double.parseDouble()
D) All the above
Answer [=]
Answer[=]
20) What is the output of the below Java program?
public class CommandLineArguments3
{
  public static void main(String[] args)
  {
    String name = args[0];
    int age = Integer.parseInt(args[1]);
    Boolean married = Boolean.parseBoolean(args[2]);
    Float salary = Float.parseFloat(args[3]);
    System.out.println("Name="+name + ", Age=" + age + ", Married=" + married + ", Salary=$"+ salary);
  }
}

C:\folder>java CommandLineArguments3 Marker 25 false 5025.35
A) Name=Marker, Age=25, Married=false, Salary=$5025.35
B) Name=Marker, Age=25, Married=false, Salary=$5025
C) Compiler error
D) None
Answer [=]
Answer[=]


Like or Share

Show some care. Like or Subscribe. [FB]...[Youtube]

C MCQ App by ExamTray 

Android APP

Java MCQ App by ExamTray 

Android APP
ALL MCQ App by ExamTray Android APP

Ad

 

Try Some Java Books

Book Price
1. Java - The Complete Reference  Check Price
2. Core Java: An Integrated Approach, Black Book Check Price
3. Java All-in-One for Dummies Check Price
4. OCP Java SE 8: Programmer II Check Price
5. Programming with Java Check Price
6. Head First Java Check Price

We may get some affiliate commission for the above purchases.