facebook twitter pinterest google plus Youtube
www.TestsTestsTests.com
Free Online Java Tests – JOptionPane Test- Java Language Programming

Java JOptionPane Test
Free Online Java Programming Tests
Java Language Programming

Test yourself on Java Programming JOptionPane – Importing javax.swing package to get an input using JOptionPane in the program.

10 Question Multiple Choice Quiz with Answers and Answer Explanations

1) What is the java package that should be imported in the java program so that JOptionPane can be used?
a) javax.swing package.
b) java.io package.
c) javax.io package.
d) java.swing package.

2) What is the correct import declaration of a java package for JOptionPane class to be used in the program?
a) import javax.swing.JOptionPane;
b) import javax.swing.*;
c) Both a and b
d) None of the above

3) Which of the following is a correct statement that will display a dialog box with a message, a text field and an OK button as shown in the picture below?

Java Test - JOptionPane Dialogue Box 1
a) String name = JOptionPane.showDialogInput(“Enter your name”);
b) String name = JOptionPane.showinputdialog(“Enter your name”);
c) String name = JOptionPane.showdialoginput(“Enter your name”);
d) String name = JOptionPane.showInputDialog(“Enter your name”);

4) Which of the following is a correct statement that will display a dialog box with a message, a text field and an OK button as shown in the picture below?

Java Test - JOptionPane Dialogue Box 2
a) JOptionPane.showDialogMessage(null, “Hello World!”);
b) JOptionPane.showMessageDialog(null, “Hello World!”);
c) JOptionPane.showmessagedialog(null, “Hello World!”);
d) JOptionPane.showdialogmessage(null, “Hello World!”);

5) Which of the following is a correct statement that accepts a whole number value using JOptionPane?
a) String number = Integer.parseInt(JOptionPane.showInputDialog(“Enter a number:”));
b) int number = JOptionPane.showInputDialog(“Enter a number:”);
c) int number = Integer.parseInt(JOptionPane.showInputDialog(“Enter a number:”));
d) None of the above

6) Which is the correct statement that displays a whole number value of variable num using JOptionPane?
a) JOptionPane.showMessageDialog(null, “The number is “+num);
b) JOptionPane.showMessageDialog(null, “The number is num”);
c) JOptionPane.showMessageDialog(null, “The number is “+num”)
d) JOptionPane.showMessageDialog(null, “The number is “num);

7) Which of the following is a correct statement that accepts any number value using JOptionPane?
a) int number = Integer.parseInt(JOptionPane.showInputDialog(“Enter a number:”));
b) String number = Integer.parseInt(JOptionPane.showInputDialog(“Enter a number:”));
c) float number = JOptionPane.showInputDialog(“Enter a number:”);
d) float number = Float.parseFloat(JOptionPane.showInputDialog(“Enter a number:”));

8) What is the symbol needed so that all the classes in the javax.swing package can be used in the java program?
a) The semicolon ; symbol.
b) The asterisk * symbol.
c) The percent % symbol.
d) The colon : symbol.

9) In the given statement: float number = Float.parseFloat(JOptionPane.showInputDialog(“Enter a number:”)); What is the default data type of the input in JOptionPane?
a) float
b) char
c) String
d) int

10) What kind of interface is being used in the JOptionPane?
a) graphical user interface
b) menu driven interface
c) command line interface
d) none of the above