Java Programming Quiz

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Rahul Kumar
R
Rahul Kumar
Community Contributor
Quizzes Created: 3 | Total Attempts: 10,786
Questions: 15 | Attempts: 4,754

SettingsSettingsSettings
Java Programming Quiz - Quiz

An interesting Java programming quiz is here for you if you use Java programming or are learning this language. The quiz is not going to be easy in any way. The questions designed in the quiz are useful for testing your knowledge of various coding and allowing learning and practicing better with this quiz. Hope you give your best and score high marks on this test. All the very best to you in advance.


Questions and Answers
  • 1. 

    GetConnection() is method available in

    • A.

      DriverManag

    • B.

      Driver Interface

    • C.

      ResultSet Interface

    • D.

      Statement Interface

    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.

    Rate this question:

  • 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)); }

    • A.

      Will show only name

    • B.

      Compilation error

    • C.

      Will show the city

    • D.

      Compiles but error at runtime

    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.

    Rate this question:

  • 3. 

    What is the default type of ResultSet in JDBC applications?

    • A.

      Read-only

    • B.

      Updatable, forward only.

    • C.

      Read-only, scroll

    • D.

      Updatable, scroll sensitive.

    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.

    Rate this question:

  • 4. 

    An application can connect to different databases at the same time.

    • A.

      True

    • B.

      False

    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.

    Rate this question:

  • 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.

    • A.

      Both are false

    • B.

      Both are true

    • C.

      Only A is false

    • D.

      Only B is false

    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.

    Rate this question:

  • 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)); }

    • A.

      Will show all rows of the first column

    • B.

      Compilation error

    • C.

      Compiles but an error at run time

    • D.

      Compiles but runs without output

    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.

    Rate this question:

  • 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?

    • A.

      Statement

    • B.

      Callable Statement

    • C.

      Prepared statement

    • D.

      Row set

    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.

    Rate this question:

  • 8. 

    All data members in an interface are by default

    • A.

      Abstract and final

    • B.

      Public and abstract

    • C.

      Public, static, and final

    • D.

      Default and abstract

    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.

    Rate this question:

  • 9. 

    Which of the following is correct for an abstract class? (Choose TWO)

    • 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.

    • C.

      An abstract class is one that contains only static methods.

    • D.

      An abstract class can be declared final.

    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.

    Rate this question:

  • 10. 

    Which of the following statement gives the use of CLASSPATH?

    • A.

      Holds the location of Core Java Class Library (Bootstrap classes)

    • B.

      Holds the location of the Java Extension Library

    • C.

      Holds the location of a User-Defined classes, packages, and JARs

    • D.

      Holds the location of Java Software

    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.

    Rate this question:

  • 11. 

    Which of the following options give the valid argument types for the main() method? (Choose 2)

    • A.

      String [][]args

    • B.

      String args[]

    • C.

      String[] args[]

    • D.

      String[] args

    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".

    Rate this question:

  • 12. 

    Which of the following options give the valid package names? (Choose 3)

    • A.

      Dollorpack.$pack.$$pack

    • B.

      $$.$$.$$

    • C.

      _score.pack.__pack

    • D.

      [email protected]@ckage.innerp@ckage

    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.

    Rate this question:

  • 13. 

    The term 'Java Platform' refers to

    • A.

      Java Compiler (Javac)

    • B.

      Java Runtime Environment (JRE)

    • C.

      Java Database Connectivity (JDBC)

    • D.

      Java Debugger

    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.

    Rate this question:

  • 14. 

    Which of the following methods are needed for loading a database driver in JDBC?

    • A.

      Register driver method

    • B.

      Class for name ()

    • C.

      Register driver () method

    • D.

      Get connection

    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.

    Rate this question:

  • 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));

    • A.

      Will show the first employee

    • B.

      Compilation error

    • C.

      Compiles but an error at runtime

    • D.

      Compiles but no output

    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.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Jul 03, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jan 10, 2019
    Quiz Created by
    Rahul Kumar
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.