Java Programming Language Quiz Coding

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 Cvktech
C
Cvktech
Community Contributor
Quizzes Created: 10 | Total Attempts: 42,133
Questions: 20 | Attempts: 1,400

SettingsSettingsSettings
Java Quizzes & Trivia

Total Questions=20


Questions and Answers
  • 1. 

    --Controller Servlet in struts

    • A.

      ActionServlet

    • B.

      FrontControllerServlet

    • C.

      FormBean class

    • D.

      Action class

    Correct Answer
    A. ActionServlet
    Explanation
    The correct answer is ActionServlet. In the Struts framework, the Controller Servlet is responsible for receiving and handling all the incoming requests. It acts as a front controller, receiving requests from the client and dispatching them to the appropriate Action classes. The ActionServlet is the default controller servlet provided by the Struts framework. It initializes the framework, manages the request processing flow, and delegates the request handling to the appropriate Action classes.

    Rate this question:

  • 2. 

    Which of the collection classes will follow the InsertionOrder

    • A.

      ArrayList

    • B.

      LinkedHash set

    • C.

      Vector

    • D.

      All the above

    Correct Answer
    D. All the above
    Explanation
    All three collection classes mentioned (ArrayList, LinkedHashSet, and Vector) follow the InsertionOrder. This means that the elements in these collections are stored and retrieved in the order in which they were inserted. In ArrayList, elements are stored in an array and can be accessed using their index. In LinkedHashSet, elements are stored in a hash table with a linked list running through it, preserving the order of insertion. Vector is similar to ArrayList but is synchronized, making it thread-safe. Therefore, all three classes maintain the insertion order of elements.

    Rate this question:

  • 3. 

    Http protocol is a _____________

    • A.

      State full

    • B.

      State less

    • C.

      Both

    • D.

      None

    Correct Answer
    B. State less
    Explanation
    The given question is asking about the nature of the HTTP protocol. The correct answer is "stateless." This means that the HTTP protocol does not retain any information or state between requests. Each request is treated as an independent transaction, and the server does not remember any previous requests or interactions with the client. This allows for a more scalable and efficient system, as the server does not need to store and manage session data for each client.

    Rate this question:

  • 4. 

    Public static void parse(String str) {  try {  float f = Float.parseFloat(str);  } catch (NumberFormatException nfe) {  f = 0;  } finally {  System.out.println(f);  }  }  public static void main(String[] args) {  parse("invalid");  } What is the result?

    • A.

      0.0

    • B.

      Compilation fails.

    • C.

      A ParseException is thrown by the parse method at runtime

    • D.

      A NumberFormatException is thrown by the parse method at runtime.

    Correct Answer
    B. Compilation fails.
    Explanation
    The code in the main method calls the parse method and passes the string "invalid" as an argument. In the parse method, there is a try-catch block that attempts to parse the string as a float using the Float.parseFloat method. If the parsing fails and a NumberFormatException is thrown, the catch block sets the value of f to 0. However, since the variable f is declared within the try block, it is not accessible outside of it. Therefore, when the code tries to print the value of f in the finally block, a compilation error occurs because f is not recognized. Hence, the correct answer is "Compilation fails."

    Rate this question:

  • 5. 

    Public class Yippee2 {  static public void main(String [] yahoo) {  for(int x = 1; x < yahoo.length; x++) {  System.out.print(yahoo[x] + " ");  } . }  } and the command line invocation: java Yippee2 a b c What is the result?

    • A.

      A b

    • B.

      B c

    • C.

      a b c

    • D.

      Compilation fails.

    • E.

      An exception is thrown at runtime.

    Correct Answer
    B. B c
    Explanation
    The code starts iterating through the yahoo array from index 1 (since x is initialized to 1) and prints each element followed by a space. So, the output will be "b c" as it skips the first element "a" and starts printing from the second element "b" followed by "c".

    Rate this question:

  • 6. 

    Public class Test {  public static void main(String [] args) {  int x = 5; boolean b1 = true;  boolean b2 = false; f ((x == 4) && !b2 )  System.out.print("1 "); System.out.print("2 ");. if ((b2 = true) && b1 )  System.out.print("3 "); }  } What is the result?

    • A.

      2

    • B.

      3

    • C.

      1 2

    • D.

      2 3

    Correct Answer
    D. 2 3
    Explanation
    The result is "2 3" because the first if statement evaluates to false since the condition (x == 4) is false. Therefore, the code inside the if statement is not executed. The second if statement evaluates to true since the assignment b2 = true returns true, and b1 is true. Therefore, the code inside the second if statement is executed, resulting in the output "3 ". Finally, the "2 " is printed outside of any if statements, resulting in the final output "2 3".

    Rate this question:

  • 7. 

    Public class Hello { String title;  int value; public Hello() {  title += " World";  }  public Hello(int value) {  this.value = value;  title = "Hello";  Hello();  }  } and:  Hello c = new Hello(5); System.out.println(c.title); What is the result?

    • A.

      Hello

    • B.

      Hello World

    • C.

      Compilation fails.

    • D.

      Hello World 5

    Correct Answer
    C. Compilation fails.
    Explanation
    The code will not compile because there is a syntax error in the constructor. The line "Hello();" is attempting to call the constructor within the constructor, which is not allowed.

    Rate this question:

  • 8. 

    Public class Wow {  public static void go(short n) {System.out.println("short");}  public static void go(Short n) {System.out.println("SHORT");}  public static void go(Long n) {System.out.println(" LONG");}  public static void main(String [] args) {  Short y = 6;  int z = 7;  go(y);  go(z);  }  } What is the result?

    • A.

      Short LONG

    • B.

      SHORT LONG

    • C.

      Compilation fails.

    • D.

      An exception is thrown at runtime.

    Correct Answer
    C. Compilation fails.
    Explanation
    The code will not compile because there is no matching method signature for the argument passed in the second call to the "go" method. The argument "z" is of type int, and there is no method that accepts an int as an argument. Therefore, the code will not compile.

    Rate this question:

  • 9. 

    Which of the following are correct as per MVC architecture

    • A.

      Two jsp files should interact with each other.

    • B.

      Every web application should contain only one controller.

    • C.

      View can directly interact with model.

    • D.

      A web application can contain 4 layers

    Correct Answer
    B. Every web application should contain only one controller.
    Explanation
    In MVC architecture, the controller is responsible for handling user input and updating the model and view accordingly. Having multiple controllers in a web application can lead to confusion and inconsistency in handling user requests. Therefore, it is recommended to have only one controller in a web application to ensure proper coordination and organization of the application's functionality.

    Rate this question:

  • 10. 

    <% int a = 10; %> <%! int a = 20; %> <%! int b = 30; %> The value of b multiplied by a is <%= b * a %>

    • A.

      The code will not compile

    • B.

      The value of b multiplied by a is 30

    • C.

      The value of b multiplied by a is 300

    • D.

      The value of b multiplied by a is 600

    Correct Answer
    C. The value of b multiplied by a is 300
    Explanation
    The given code snippet includes two scriptlet declarations, and . These scriptlet declarations are used to declare variables that can be accessed throughout the entire page. Therefore, the variable "a" is declared twice, once with a value of 10 and once with a value of 20. However, the variable "b" is only declared once with a value of 30. When the expression is evaluated, it will use the value of "b" (30) multiplied by the value of "a" (10), resulting in 300. Therefore, the correct answer is "The value of b multiplied by a is 300."

    Rate this question:

  • 11. 

    If i want to use the name of the person across multiple pages then we have to store that person name in ___

    • A.

      Request

    • B.

      Session

    • C.

      Application

    • D.

      Servletrequest

    Correct Answer
    B. Session
    Explanation
    To use the name of a person across multiple pages, it is necessary to store that person's name in the session. The session is a mechanism that allows the server to store information about a user's interactions with a website. By storing the person's name in the session, it can be accessed and used on different pages throughout the user's session. This ensures that the person's name remains available and consistent as they navigate through the website.

    Rate this question:

  • 12. 

    Using which object we can reduce the network traffing in JDBC

    • A.

      Statement

    • B.

      PreparedStatement

    • C.

      ResultSet

    • D.

      CallableStatement

    Correct Answer
    B. PreparedStatement
    Explanation
    PreparedStatement can reduce network traffic in JDBC because it allows the database to compile and optimize the SQL statement only once, and then reuse the compiled statement with different parameter values. This reduces the amount of data that needs to be sent over the network for each execution of the statement, resulting in improved performance and reduced network traffic.

    Rate this question:

  • 13. 

    Using which class object we can call Stored Procedures inJDBC

    • A.

      Statement

    • B.

      PreparedStatement

    • C.

      ResultSet

    • D.

      CallableStatement

    Correct Answer
    D. CallableStatement
    Explanation
    CallableStatement is the correct answer because it is a JDBC interface that provides methods to call stored procedures in a database. It allows the execution of SQL statements that may contain input and output parameters. CallableStatement extends the PreparedStatement interface and provides additional methods specifically for calling stored procedures. Therefore, using a CallableStatement object, we can easily call and execute stored procedures in JDBC.

    Rate this question:

  • 14. 

     Which object is responsible for reading confiuguration file in hibernate

    • A.

      Session

    • B.

      SessionFactory

    • C.

      Configuration

    • D.

      Transaction

    Correct Answer
    C. Configuration
    Explanation
    The Configuration object is responsible for reading the configuration file in Hibernate. It is used to configure and bootstrap Hibernate, including reading the hibernate.cfg.xml file which contains the necessary configuration settings for the Hibernate framework. The Configuration object is used to create a SessionFactory, which in turn is used to create Session objects for interacting with the database.

    Rate this question:

  • 15. 

    Which of the following is a Legacy class in collections

    • A.

      HashSet

    • B.

      ArrayList

    • C.

      Vector

    • D.

      TreeSet

    Correct Answer
    C. Vector
    Explanation
    Vector is considered a legacy class in collections because it was one of the original classes introduced in Java's early versions. It is part of the Java Collections Framework but has been largely replaced by the more modern ArrayList class. Vector is synchronized, which means it is thread-safe, but this can also lead to performance issues in multi-threaded environments. Therefore, it is generally recommended to use ArrayList instead of Vector in most cases.

    Rate this question:

  • 16. 

    What will be the output of the following JSP page?      <% a = 100; %>    <% int a = 200; %>    <%! int a = 300; %>    a = <%= a %>, <%= this.a %>  

    • A.

      A = 200, 100

    • B.

      A = 300, 100

    • C.

      A = 100, 200

    • D.

      a = 200, 300

    Correct Answer
    A. A = 200, 100
    Explanation
    The output of the JSP page will be "a = 200, 100". This is because the first declaration of "a" assigns it the value of 100. The second declaration of "a" is a local variable within the tags and assigns it the value of 200. The third declaration of "a" is a global variable within the tags and assigns it the value of 300. The final line of code outputs the values of "a" using the tags, which will output the value of the local variable "a" (200) followed by the value of the global variable "a" (100).

    Rate this question:

  • 17. 

    Which of the following design patterns is used to separate the task of writing the GUI screens and business logic? Select 1 correct option.

    • A.

      View Logic

    • B.

      Front Controller

    • C.

      Model View Controller

    • D.

      Business View

    Correct Answer
    C. Model View Controller
    Explanation
    The Model View Controller (MVC) design pattern is used to separate the task of writing the GUI screens and business logic. In MVC, the model represents the data and business logic, the view represents the GUI screens, and the controller acts as an intermediary between the model and the view, handling user input and updating the model and view accordingly. This separation of concerns allows for easier maintenance and testing of the application.

    Rate this question:

  • 18. 

     Regarding the processing of a BodyTag handler, in which of the following cases a BodyContent object will be "pushed" into the pageContext? Select 1 correct option.

    • A.

      If the doStartTag() returns EVAL_BODY_INCLUDE

    • B.

      If the doStartTag() returns EVAL_BODY_BUFFERED

    • C.

      If the doStartTag() returns SKIP_BODY

    • D.

      If the doStartTag() DOES NOT return SKIP_BODY

    Correct Answer
    C. If the doStartTag() returns SKIP_BODY
    Explanation
    If the doStartTag() returns SKIP_BODY, a BodyContent object will be "pushed" into the pageContext.

    Rate this question:

  • 19. 

    Your web application named "FWorks" uses SpecialMath.class. This is an unbundled class and is not contained in any jar file. Where will you keep this class file? Select 1 correct option.

    • A.

      FWorks/WEB-INF

    • B.

      FWorks/WEB-INF/classes

    • C.

      FWorks/WEB-INF/lib/classes

    • D.

      FWorks/classes

    Correct Answer
    B. FWorks/WEB-INF/classes
    Explanation
    The correct answer is FWorks/WEB-INF/classes. This is because in a web application, the classes that are not contained in any jar file are typically stored in the WEB-INF/classes directory.

    Rate this question:

  • 20. 

    Identify the implicit objects available to EL expressions.

    • A.

      RequestScope

    • B.

      PageScope

    • C.

      Header

    • D.

      PageContext

    • E.

      All the avove

    Correct Answer
    E. All the avove
    Explanation
    The implicit objects available to EL expressions include requestScope, pageScope, header, and pageContext. These objects provide access to various information and functionalities within the application. The requestScope object allows access to attributes stored in the request scope, the pageScope object allows access to attributes stored in the page scope, the header object allows access to HTTP request headers, and the pageContext object provides access to the page context. Therefore, all of the above options are correct.

    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
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 25, 2011
    Quiz Created by
    Cvktech
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.