0% found this document useful (0 votes)
15 views9 pages

2022 Aoop

Uploaded by

daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views9 pages

2022 Aoop

Uploaded by

daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

True/false

1. True - You can place multiple components inside a BorderPane


region.
2. True - In a Java network program, the server application is
responsible for establishing connection by invoking the accept
method.
3. True - When a ResultSet object is initially created, its cursor is
pointing at the first row in the result set.
4. False - If you place multiple catch blocks in a single try block, the
order should be from more specific to more general exceptions, not
necessarily the superclass before subclasses.
5. True - Java doesn’t support multiple inheritance using classes.
6. True - A Java class that extends class Application should implement
the run method.
7. False - executeQuery(String sqlStatement) returns a ResultSet, not a
boolean value.
8. True - Class.forName("com.mysql.jdbc.Driver") loads the MySQL
driver class.
9. False - The class File is used to retrieve information about files and
directories but does not provide any file-processing capabilities.

10. False - Checked exceptions are not runtime exceptions; they are
checked at compile-time.

Choose

Question 1

All JavaFX applications must extend the ___________ class.

• Correct Answer: D) Application

Explanation:
In JavaFX, every application must extend the Application class. This
class provides the essential structure and life cycle methods such as
start(Stage primaryStage), which is the entry point for JavaFX
applications.

Question 2

You use this class to load an image file into memory.

• Correct Answer: C) Image

Explanation:
The Image class in JavaFX is used to load images into memory. It can
be used in conjunction with ImageView to display the image in a
JavaFX application.

Question 3

Which of the following layout managers organize the components


from left to right, starting new rows as necessary?

• Correct Answer: A) HBox

Explanation:
HBox is a layout manager in JavaFX that arranges its children in a
single horizontal row. If you need a layout that arranges components
horizontally, HBox is the right choice.

Question 4

This is one or more statements that are always executed and usually
used to close resources.

• Correct Answer: C) finally block


Explanation:
The finally block in Java is used in a try-catch-finally statement. It
always executes, regardless of whether an exception was thrown or
not, and is typically used for cleanup activities like closing resources.

Question 5

This keyword indicates that a class inherits from another class.

• Correct Answer: B) Extends

Explanation:
The extends keyword in Java is used to create a subclass from a
superclass, indicating inheritance.

Question 6

A method in a subclass having the same name as a method in the


superclass but a different signature is an example of:

• Correct Answer: B) Overriding

Explanation:
Method overriding in Java occurs when a subclass has a method with
the same name, return type, and parameters as a method in its
superclass, allowing the subclass to provide a specific
implementation.

Question 7

What are the key advantages of using PreparedStatement?

• Correct Answer: D) All are correct

Explanation:
PreparedStatement offers several advantages: it allows you to pass
parameterized SQL statements, reuse the statement with different
values, and supports precompiled SQL statements, enhancing
execution time.

Question 8

We can define our own exception (custom exception) by:

• Correct Answer: A) By extending the Exception class

Explanation:
Custom exceptions in Java are created by extending the Exception
class, allowing developers to create specific exceptions that suit their
application’s needs.

Question 9

Which of the following is character-based I/O class?

• Correct Answer: B) PrintWriter

Explanation:
PrintWriter is a character-based I/O class in Java, used for writing
text to an output stream, while FileInputStream, FileOutputStream,
and BufferedInputStream are byte-based I/O classes.

Question 10

This contains the results of an SQL SELECT statement.

• Correct Answer: B) result set

Explanation:
In JDBC, a ResultSet object contains the results of executing an SQL
SELECT query, allowing you to retrieve and process the data returned
by the database.

Question 11

A program uses the FileWriter constructor with the string


“newFile.txt”. What happens if “newFile.txt” already exists?

• Correct Answer: D) The existing file is erased and replaced


with a new, empty one

Explanation:
When a FileWriter is created with a filename, and the file already
exists, the existing file is overwritten, effectively erasing its contents
and creating a new, empty file.

Question 12

Answer = A

Endpoints of logical connections between two hosts and can be used


to send and receive data.

• A) ports: Correct. Ports are endpoints in networking that


allow data to be sent and received.
• B) Connectors: Incorrect. Connectors are not typically
used in this context.
• C) Socket: Incorrect. While sockets are used for
communication, they are not the logical endpoints; ports are.
• D) None: Incorrect. The correct answer is ports.

Question 13
Answer = A
In InetAddress class which method returns the host name of the IP
Address?

• A) public String getHostName(): Correct. This method


returns the host name associated with the IP address.
• B) public String getHostAddress: Incorrect. This method
returns the IP address as a string.
• C) public static InetAddress getLocalHost(): Incorrect. This
method returns the InetAddress object representing the local host.
• D) None of the above: Incorrect. The correct answer is
public String getHostName().

Question 14

Answer = B
Which of the following method is used to retrieve data from
database in JDBC?

• A) executeResult: Incorrect. This is not a method in JDBC.


• B) executeQuery: Correct. This method is used to execute
statements that return a result set.
• C) executeUpdate: Incorrect. This method is used for SQL
statements that update the database.
• D) execute: Incorrect. This method is used to execute any
SQL statement, but not specifically to retrieve data.

Question 15

Answer = C

Which statement pattern is correct if we want to connect to the


MySQL database named “universityDB”?
• A) getConnection(“jdbc/mysql/localhost/universityDB”,
“userName”, “passWord”);: Incorrect. The syntax is wrong; should be
jdbc:mysql://.
• B) getConnection(“com.mysql.jdbc.driver.universityDB”,
“userName”, “passWord”);: Incorrect. This is not the correct URL
format.
• C) getConnection(“jdbc:mysql://localhost/universityDB”,
“userName”, “passWord”);: Correct. This is the correct JDBC URL
format for MySQL.
• D) getConnection(“com/mysql/jdbc/driver/universityDB”,
“userName”, “passWord”);: Incorrect. This is not the correct URL
format.

Question 16

Answer = C

Which Java subclass is different from others in File I/O concept?

• A) InputStream: Incorrect. This is used for reading byte


streams.
• B) OutputStream: Incorrect. This is used for writing byte
streams.
• C) FileWriter: Correct. This is used for writing character
streams.
• D) PrintWriter: Incorrect. This is also used for writing
character streams, but FileWriter is specifically for file writing.

Question 17

Answer = B

Which of these values is returned by the read method if the end of


file (EOF) is encountered?
• A) 0: Incorrect. 0 is not used to indicate EOF.
• B) -1: Correct. The read method returns -1 to indicate the
end of the file.
• C) 1: Incorrect. 1 does not indicate EOF.
• D) null: Incorrect. null is not returned by the read
method.

Question 18

Answer = A

Which of the following is an event source?

• A) An object of a control: Correct. Event sources are


typically GUI components like buttons and text fields.
• B) An event listener: Incorrect. Event listeners are objects
that listen for events.
• C) An inner class: Incorrect. An inner class is not an event
source.
• D) An event adapter: Incorrect. An event adapter is used
to receive events, not to generate them.

Question 19

Answer = B

Which of the following components allows a user to select one of


several options from a “drop-down” menu?

• A) ListBox: Incorrect. A ListBox is typically used for


displaying a list of items, not as a drop-down.
• B) ComboBox: Correct. A ComboBox allows the user to
select one option from a drop-down menu.
• C) RadioButton: Incorrect. RadioButtons allow the user to
select one option from a group, but they are not a drop-down menu.
• D) CheckBox: Incorrect. CheckBoxes allow the user to
select multiple options independently, not from a drop-down menu

You might also like