1.
GetConnection() is method available in
Correct Answer
A. DriverManag
Explanation
The correct answer is DriverManager. The getConnection() method is available in the DriverManager class, which is used to establish a connection to a database. This class provides methods to manage the drivers and establish connections with different databases.
2.
Consider the following code & select the correct output.
String sql ="select rollno, name from student";
PreparedStatement
pst=cn.prepareStatement(sql);
System.out.println(pst.toString());
ResultSet rs=pst.executeQuery();
while(rs.next()){
System.out.println(rs.getString(3)); }
Correct Answer
D. Compiles but error at runtime
Explanation
The code compiles successfully because there are no syntax errors. However, it will result in an error at runtime because the query is selecting only the "rollno" and "name" columns from the "student" table, but in the while loop, it is trying to retrieve the value of the 3rd column using rs.getString(3). Since there are only 2 columns in the result set, it will throw an error at runtime.
3.
What is the default type of ResultSet in JDBC applications?
Correct Answer
A. Read-only
Explanation
The default type of ResultSet in JDBC applications is read-only. This means that the ResultSet object can only be used to retrieve data from the database and cannot be used to update or modify the data. This is the most common type of ResultSet used in most JDBC applications, as it provides a simple and efficient way to retrieve data from the database without the need for any updates or modifications.
4.
An application can connect to different databases at the same time.
Correct Answer
A. True
Explanation
An application can connect to different databases at the same time because modern applications are designed to be flexible and capable of handling multiple database connections simultaneously. This allows the application to retrieve and store data from different sources, enabling more complex and diverse functionality. Additionally, connecting to multiple databases can improve performance by distributing the workload across different systems.
5.
A) When one uses a callable statement, in that the case only parameters are sent over the network not SQL query.B) In preparing statement SQL, query will compile for the first time only.
Correct Answer
B. Both are true
Explanation
When using a callable statement, only the parameters are sent over the network, not the SQL query itself. This is because the SQL query is already compiled and stored on the database server. In the case of a prepared statement, the SQL query is compiled for the first time it is executed and then stored on the database server for future use. Therefore, both statements in the answer are true.
6.
Consider the code below & select the correct output from the options:
String sql ="select * from ?";
String table=" txyz ";
PreparedStatement
pst=cn.prepareStatement(sql);
pst.setString(1,table );
ResultSet rs=pst.executeQuery();
while(rs.next()){
System.out.println(rs.getString(1)); }
Correct Answer
C. Compiles but an error at run time
Explanation
The code is attempting to use a placeholder "?" in the SQL query and then set its value using the `setString()` method. However, placeholders can only be used for values, not for table or column names. Therefore, the code will compile without any errors, but it will throw an error at runtime when trying to execute the query.
7.
Sam wants to develop a Student management system, which requires frequent insert operations about student details. In order to insert student records which statement interface will give good performance?
Correct Answer
C. Prepared statement
Explanation
A prepared statement would give good performance for frequent insert operations about student details in a student management system. Prepared statements are precompiled SQL statements that can be executed multiple times with different parameter values, reducing the overhead of parsing and optimizing the query each time it is executed. This can result in improved performance and efficiency when performing repetitive database operations like inserting student records.
8.
All data members in an interface are by default
Correct Answer
C. Public, static, and final
Explanation
In Java, all data members in an interface are by default public, static, and final. Public means that the data members can be accessed from anywhere. Static means that the data members belong to the interface itself, rather than to any specific instance of the interface. Final means that the data members cannot be modified once they are initialized. These default modifiers ensure that the data members in an interface are accessible, shared, and cannot be changed.
9.
Which of the following is correct for an abstract class? (Choose TWO)
Correct Answer(s)
A. An abstract class is one that contains general-purpose methods.
B. An abstract class is one that contains some defined methods and some undefined methods.
Explanation
An abstract class is one that contains general-purpose methods. This means that the methods in the abstract class can be used for various purposes and can be implemented differently by different subclasses.
An abstract class is one that contains some defined methods and some undefined methods. This means that the abstract class can have some methods that are fully implemented and can be used directly, while other methods are declared without an implementation and must be implemented by the subclasses.
Note: The question is complete and readable.
10.
Which of the following statement gives the use of CLASSPATH?
Correct Answer
C. Holds the location of a User-Defined classes, packages, and JARs
Explanation
The CLASSPATH is used to specify the location of user-defined classes, packages, and JAR files in Java. It allows the Java compiler and runtime environment to locate these files when they are needed for execution. The CLASSPATH variable can be set either through the command line or through environment variables. By specifying the correct location of user-defined classes, packages, and JAR files in the CLASSPATH, Java programs can access and utilize these files during runtime.
11.
Which of the following options give the valid argument types for the main() method? (Choose
2)
Correct Answer(s)
B. String args[]
D. String[] args
Explanation
The main() method in Java is the entry point for a Java program. It takes an array of strings as its parameter, which is typically named "args". The options "String args[]" and "String[] args" both declare the parameter as an array of strings, which is a valid argument type for the main() method. Therefore, the correct answer is "String args[], String[] args".
12.
Which of the following options give the valid package names? (Choose 3)
Correct Answer(s)
A. Dollorpack.$pack.$$pack
B. $$.$$.$$
C. _score.pack.__pack
Explanation
The correct answer is dollorpack.$pack.$$pack, $$.$$.$$, _score.pack.__pack. These package names follow the rules for valid package names in Java, which include starting with a letter or underscore, followed by letters, numbers, or underscores. The first option starts with a letter, followed by a dollar sign, and then another dollar sign. The second option consists of three dollar signs. The third option starts with an underscore, followed by letters and underscores. The other options do not follow the rules for valid package names.
13.
The term 'Java Platform' refers to
Correct Answer
B. Java Runtime Environment (JRE)
Explanation
The term 'Java Platform' refers to Java Runtime Environment (JRE). The Java Platform is a software platform that includes the Java Virtual Machine (JVM), the Java class libraries, and the Java programming language. It provides the necessary tools and runtime environment for running Java applications and applets. The JRE consists of the JVM, class libraries, and other supporting files that are required to run Java programs. It does not include the Java Compiler (Javac), Java Database Connectivity (JDBC), or Java Debugger.
14.
Which of the following methods are needed for loading a database driver in JDBC?
Correct Answer
C. Register driver () method
Explanation
The Register driver () method is needed for loading a database driver in JDBC. This method is used to register the driver class with the DriverManager. It is necessary to register the driver before establishing a connection to the database. The other methods mentioned in the options, such as Class for name () and Get connection, are not specifically related to loading the driver, but rather for establishing a connection and retrieving a connection from the DriverManager.
15.
Consider the following code & select the correct option for output.
String sql ="select empno,ename from emp";
PreparedStatement
pst=cn.prepareStatement(sql);
System.out.println(pst.toString());
ResultSet rs=pst.executeQuery();
System.out.println(rs.getString(1)+ "
"+rs.getString(2));
Correct Answer
C. Compiles but an error at runtime
Explanation
The code will compile successfully but will throw an error at runtime because the ResultSet rs has not been moved to the first row before calling rs.getString(1) and rs.getString(2). Therefore, it will throw an exception indicating that the ResultSet cursor is before the first row.