Java 2 Final Exam Preview

By Viet Ho
Viet Ho, Software development
Viet, a versatile software developer, proficient in the development stack, excels in front-end with Svelte, TypeScript, and JavaScript. He's skilled in CSS, CSS libraries, Spring framework, Java, Golang, and MySQL. He thrives in Agile teamwork.
Quizzes Created: 2 | Total Attempts: 391
, Software development
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
Questions: 40 | Attempts: 120

SettingsSettingsSettings
Java Quizzes & Trivia

Made by Viet Ho at
Saint Paul College, Fall 2017


Questions and Answers
  • 1. 

    Like a loop, a recursive method must have:

    • A.

      A counter.

    • B.

      Some way to control the number of times it repeats itself.

    • C.

      A return statement.

    • D.

      A predetermined number of times it will execute before terminaƭng.

    Correct Answer
    B. Some way to control the number of times it repeats itself.
    Explanation
    A recursive method must have some way to control the number of times it repeats itself because without a control mechanism, the method would continue to call itself indefinitely, leading to infinite recursion. This control mechanism could be a condition or a base case that determines when the recursion should stop. By having a control mechanism, the recursive method can ensure that it terminates after a certain number of repetitions, preventing infinite recursion and allowing the program to execute correctly.

    Rate this question:

  • 2. 

    How many times will the following method call itself if the value 10 is passed as an argument?public static void message(int n){    if (n > 0)    {        System.out.println("Print this line.\n");        message(n + 1);    }} 

    • A.

      1

    • B.

      9

    • C.

      10

    • D.

      An infinite number of times

    Correct Answer
    D. An infinite number of times
    Explanation
    The given method is a recursive method that calls itself as long as the value passed as an argument is greater than 0. Since the method calls itself with an incremented value of n each time, and there is no condition to stop the recursion, it will continue to call itself indefinitely, resulting in an infinite number of method calls.

    Rate this question:

  • 3. 

    Recursive algorithms are usually less efficient than:

    • A.

      Iterative algorithms.

    • B.

      Quantum algorithms

    • C.

      Pseudocode algorithms.

    • D.

      None of these.

    Correct Answer
    A. Iterative algorithms.
    Explanation
    Recursive algorithms are usually less efficient than iterative algorithms because recursive algorithms involve repeated function calls and memory allocation, which can lead to a higher overhead. In contrast, iterative algorithms use loops to repeatedly execute a set of instructions, eliminating the need for function calls and reducing memory usage. This makes iterative algorithms more efficient in terms of time and space complexity compared to recursive algorithms. Quantum algorithms and pseudocode algorithms are not directly related to the efficiency comparison between recursive and iterative algorithms, so they are not the correct answer.

    Rate this question:

  • 4. 

    Look at the following pseudo code algorithm:algorithm Test14(int x)     if (x < 8)         return (2 * x)     else         return (3 * Test14(x - 8) + 8) end Test14 What is the base case for the algorithm?

    • A.

      X < 8

    • B.

      2 * x

    • C.

      3 * Test14(x ­ 8) + 8

    • D.

      X >= 8

    Correct Answer
    A. X < 8
    Explanation
    The base case for the algorithm is when x is less than 8. In this case, the algorithm returns 2 * x.

    Rate this question:

  • 5. 

    Look at the following pseudocode algorithm:algorithm Test14(int x)    if (x < 8)        return (2 * x)    else        return (3 * Test14(x - 8) + 8)end Test14What is the recursive case for the algorithm?

    • A.

      X < 8

    • B.

      2 * x

    • C.

      X != 8

    • D.

      X >= 8

    Correct Answer
    D. X >= 8
    Explanation
    The recursive case for the algorithm is x >= 8. This means that when the input value x is greater than or equal to 8, the algorithm will recursively call itself with the new input value x - 8. This recursive call will continue until the base case is reached, which is when x is less than 8.

    Rate this question:

  • 6. 

    Look at the following method: public static int Test2(int x, int y){    if (x < y)    {        return -5;    }    else    {        return (Test2(x - y, y + 5,) + 6);    }}What is the base case for the method?

    • A.

      X < y

    • B.

      -­5

    • C.

      Test2(x ­ y, y + 5) + 6

    • D.

      +6

    Correct Answer
    A. X < y
    Explanation
    The base case for the method is x < y. This is because if x is less than y, the method will return -5 and terminate without making a recursive call.

    Rate this question:

  • 7. 

    This term is used for methods that directly call themselves.

    • A.

      Direct recursion

    • B.

      Simple recursion

    • C.

      Absolute recursion

    • D.

      Native recursion

    Correct Answer
    A. Direct recursion
    Explanation
    Direct recursion is the term used for methods that directly call themselves. In this type of recursion, a function calls itself within its own code. This allows the function to repeat its execution until a certain condition is met, making it a powerful tool for solving problems that can be broken down into smaller, similar subproblems. By calling itself, the function creates a recursive loop that continues until the base case is reached, at which point the recursion stops.

    Rate this question:

  • 8. 

    Like ________, a recursive method must have some way to control the number of times it repeats.

    • A.

      A loop

    • B.

      Any method

    • C.

      A class constructor

    • D.

      An event

    Correct Answer
    A. A loop
    Explanation
    A recursive method, like a loop, must have some way to control the number of times it repeats. In both cases, there needs to be a condition or base case that determines when the repetition should stop. Without this control, the recursive method or loop would continue indefinitely, resulting in an infinite loop or recursion. Therefore, a loop is a suitable comparison to explain the need for a control mechanism in a recursive method.

    Rate this question:

  • 9. 

    The number of times that a method calls itself is known as the:

    • A.

      Height of recursion.

    • B.

      Depth of recursion.

    • C.

      Width of recursion.

    • D.

      Length of recursion.

    Correct Answer
    B. Depth of recursion.
    Explanation
    The correct answer is "Depth of recursion" because the depth of recursion refers to the number of times a method calls itself. It represents how many levels of nested recursive calls are made within the method. The depth increases with each recursive call, as the method continues to call itself until a base case is reached.

    Rate this question:

  • 10. 

    Look at the following pseudocode algorithm: Algorithm gcd(x, y)    if (x < y)        gcd(y, x)    else        if (y = 0)            return x        else            return gcd(y, x mod y)end gcdWhat is the base case for the algorithm gcd?

    • A.

      X < y

    • B.

      Y == 0

    • C.

      X == 0

    • D.

      Y > x

    Correct Answer
    B. Y == 0
    Explanation
    The base case for the algorithm gcd is when y is equal to 0. This is because when y is 0, it means that x is the greatest common divisor (gcd) of x and y. In this case, the algorithm can terminate and return the value of x as the gcd.

    Rate this question:

  • 11. 

    Applet restrictions are:

    • A.

      Necessary to prevent malicious code from attacking or spying on unsuspecting users.

    • B.

      Determined by the Web browser.

    • C.

      Optional in Java 7.

    • D.

      Enabled only if the applet is running on a Web server.

    Correct Answer
    A. Necessary to prevent malicious code from attacking or spying on unsuspecting users.
    Explanation
    Applet restrictions are necessary to prevent malicious code from attacking or spying on unsuspecting users. These restrictions are put in place to ensure the security of the user's system and data. They are determined by the web browser and are enabled only if the applet is running on a web server. In Java 7, these restrictions are optional, but it is still highly recommended to have them in place to protect the user's privacy and security.

    Rate this question:

  • 12. 

    Which of the following is not a restriction placed on applets?

    • A.

      Applets cannot create files on the user's system.

    • B.

      Applets cannot execute operating system procedures on the user's system.

    • C.

      Applets cannot display a window.

    • D.

      Applets cannot retrieve the user's identity.

    Correct Answer
    C. Applets cannot display a window.
    Explanation
    Applets are small applications that run within a web browser. They are designed to be restricted in certain ways to ensure security. The given answer states that applets cannot display a window, which is true. Applets are not allowed to create their own windows or pop-up windows on the user's system. This restriction is in place to prevent applets from interrupting or interfering with the user's browsing experience or potentially displaying malicious content.

    Rate this question:

  • 13. 

    In an HTML document, the tags:

    • A.

      Instruct the Web browser how to format the text

    • B.

      Instruct the Web browser where to place images.

    • C.

      Instruct the Web browser what to do when the user clicks on a link

    • D.

      All of these

    Correct Answer
    D. All of these
    Explanation
    The tags in an HTML document have various functions. They can be used to format the text, place images in the document, and define actions when the user clicks on a link. Therefore, the correct answer is "All of these" as all of these functions can be achieved using HTML tags.

    Rate this question:

  • 14. 

    Which of the following will load the applet, TestApplet?

    • A.

      <applet code="TestApplet.class" width="200" height="50"></applet>

    • B.

      <applet code=TestApplet.class width=200 height=50></applet>

    • C.

      <load code="TestApplet.class" width="200" height="50"> </load> 

    • D.

      <load code="TestApplet.class" w="200" h="50"> </load>

    Correct Answer
    A. <applet code="TestApplet.class" width="200" height="50"></applet>
    Explanation
    The correct answer is . This is the correct syntax for loading an applet in HTML. The "code" attribute specifies the name of the applet class file, and the "width" and "height" attributes determine the dimensions of the applet display area. The other options provided ("load" tag and incorrect attribute names) do not follow the correct syntax for loading an applet.

    Rate this question:

  • 15. 

    An applet using a Swing GUI extends which class?

    • A.

      Applet

    • B.

      JApplet

    • C.

      JSwing

    • D.

      JFrame

    Correct Answer
    B. JApplet
    Explanation
    An applet using a Swing GUI extends the JApplet class. The JApplet class is a part of the Swing framework in Java and is specifically designed for creating applets with a graphical user interface. The JApplet class provides additional functionality and features compared to the standard Applet class, making it more suitable for creating applets with a Swing GUI. The JSwing and JFrame classes are not correct choices as they are not specifically designed for creating applets.

    Rate this question:

  • 16. 

    When the applet viewer opens an HTML document with more than one applet tag:

    • A.

      It terminates immediately

    • B.

      It displays the first applet, and then terminates

    • C.

      It displays each applet in a separate window

    • D.

      It displays each applet in order in the same window

    Correct Answer
    C. It displays each applet in a separate window
    Explanation
    When the applet viewer opens an HTML document with more than one applet tag, it displays each applet in a separate window. This means that each applet will be opened in its own individual window, allowing the user to interact with each applet separately.

    Rate this question:

  • 17. 

    Which of the following is not a valid AWT class?

    • A.

      Panel

    • B.

      Applet

    • C.

      TextArea

    • D.

      JMenu

    Correct Answer
    D. JMenu
    Explanation
    The AWT (Abstract Window Toolkit) is a set of classes and methods in Java used for creating graphical user interfaces (GUIs). The classes in AWT are used to create various GUI components. Panel, Applet, and TextArea are all valid AWT classes used for creating different GUI components. However, JMenu is not a valid AWT class. JMenu is actually a class in the Swing package, which is an extension of AWT and provides more advanced GUI components. Therefore, JMenu is not a valid AWT class.

    Rate this question:

  • 18. 

    HTML describes the content and layout of a Web page, and creates links to other files and Web pages, but does not have sophisticated abilities such as performing math calculations and interacting with the user.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    HTML is a markup language used to structure the content and layout of a web page. It is responsible for creating links to other files and web pages. However, HTML does not have advanced capabilities like performing mathematical calculations or interacting with the user. Therefore, the statement that HTML does not have sophisticated abilities is true.

    Rate this question:

  • 19. 

    An applet does not have to be on a Web server in order to be executed.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    An applet is a small program that is designed to be executed within a web browser. While it is common for applets to be hosted on a web server and accessed through a web page, it is not a requirement. Applets can also be executed locally on a user's computer without the need for a web server. Therefore, the statement that an applet does not have to be on a web server in order to be executed is true.

    Rate this question:

  • 20. 

    The browser creates an instance of the applet class automatically.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    When a web page containing an applet is loaded, the browser automatically creates an instance of the applet class. This means that the applet class is instantiated without any explicit code or action from the programmer. This automatic creation allows the applet to start running and be displayed within the web page. Therefore, the statement "The browser creates an instance of the applet class automatically" is true.

    Rate this question:

  • 21. 

    The DBMS works directly with the data and sends the results of operations:

    • A.

      Back to the application.

    • B.

      Along the encrypted data path.

    • C.

      To the unified data component.

    • D.

      Back to the Web server.

    Correct Answer
    A. Back to the application.
    Explanation
    The correct answer is "Back to the application" because the DBMS (Database Management System) is responsible for managing and manipulating data within a database. After performing operations on the data, such as queries or updates, the DBMS sends the results back to the application that requested the operation. This allows the application to process and display the data to the user or perform further actions based on the results.

    Rate this question:

  • 22. 

    The data that is stored in a table is organized in:

    • A.

      Rows.

    • B.

      Folders.

    • C.

      Pages.

    • D.

      Files.

    Correct Answer
    A. Rows.
    Explanation
    The data stored in a table is organized in rows. In a database table, each row represents a single record or instance of data. Each row consists of multiple columns, which define the different attributes or properties of the data. Rows are used to store individual data entries and are organized in a tabular format, making it easy to retrieve and manipulate specific data based on various criteria. Folders, pages, and files are not typically used to organize data in a table.

    Rate this question:

  • 23. 

    If you try to store duplicate data in a primary key column:

    • A.

      The column is duplicated.

    • B.

      An error will occur.

    • C.

      The duplicate data will have concurrency issues.

    • D.

      The primary key column will not display the duplicate data.

    Correct Answer
    B. An error will occur.
    Explanation
    If you try to store duplicate data in a primary key column, an error will occur. This is because a primary key is a unique identifier for each record in a table, and it must be unique. If duplicate data is attempted to be stored in the primary key column, it violates the uniqueness constraint and the database management system will throw an error to prevent the duplication.

    Rate this question:

  • 24. 

    Which of one the following SQL data types would be the best choice for storing financial data?

    • A.

      INT

    • B.

      REAL

    • C.

      DOUBLE

    • D.

      VARCHAR

    Correct Answer
    C. DOUBLE
    Explanation
    The DOUBLE data type would be the best choice for storing financial data because it allows for the storage of decimal numbers with a high degree of precision. Financial data often involves calculations with decimal values, such as currency amounts or interest rates, and the DOUBLE data type can accurately represent and perform calculations with these values. INT, REAL, and VARCHAR are not ideal choices for financial data as they may not provide the necessary precision or data range required for accurate calculations and storage.

    Rate this question:

  • 25. 

    Which of the following shows how a single quote is represented as part of a string in SQL?

    • A.

      _'

    • B.

      " ' "

    • C.

      / '

    • D.

      ' '

    Correct Answer
    D. ' '
    Explanation
    In SQL, a single quote is represented as part of a string by using two consecutive single quotes. This is known as escaping the single quote character. So, the correct representation of a single quote as part of a string in SQL is ' '.

    Rate this question:

  • 26. 

    What SQL operator can be used to perform a search for a substring?

    • A.

      STR

    • B.

      LIKE

    • C.

      WHERE

    • D.

      SUB

    Correct Answer
    B. LIKE
    Explanation
    The LIKE operator in SQL is used to perform pattern matching searches within a string. It allows for searching for a specific substring or pattern within a larger string. This operator is commonly used in conjunction with the '%' wildcard character to represent any number of characters. Therefore, the LIKE operator is the correct choice for performing a search for a substring in SQL.

    Rate this question:

  • 27. 

    What SQL operator can be used to disqualify search criteria in a WHERE clause?

    • A.

      AND

    • B.

      NOT

    • C.

      EXCLUDE

    • D.

      NOR

    Correct Answer
    B. NOT
    Explanation
    The SQL operator "NOT" can be used to disqualify search criteria in a WHERE clause. It allows for the exclusion of certain conditions or values from the search results. By using "NOT" before a condition, it negates the condition and returns the opposite result. This operator is useful when you want to exclude specific records that meet certain criteria from your query results.

    Rate this question:

  • 28. 

    Which Statement interface method should be used to execute a SELECT statement?

    • A.

      ExecuteSQL

    • B.

      ExecuteStatement

    • C.

      ExecuteUpdate

    • D.

      ExecuteQuery

    Correct Answer
    D. ExecuteQuery
    Explanation
    The correct method to execute a SELECT statement in the Statement interface is executeQuery. This method is specifically designed to execute SQL queries and retrieve the result set generated by the query. It returns a ResultSet object that contains the data retrieved from the database. The other options mentioned, executeSQL, executeStatement, and executeUpdate, are not valid methods in the Statement interface and do not serve the purpose of executing a SELECT statement.

    Rate this question:

  • 29. 

    Which Statement interface method should be used to execute an INSERT statement?

    • A.

      ExecuteUpdate

    • B.

      ExecuteStatement

    • C.

      ExecuteQuery

    • D.

      ExecuteSQL

    Correct Answer
    A. ExecuteUpdate
    Explanation
    The correct answer is "executeUpdate" because this method is specifically designed to execute INSERT statements in the Statement interface. It is used to execute SQL statements that do not return any result, such as INSERT, UPDATE, or DELETE statements. This method returns an integer value indicating the number of rows affected by the statement, which is useful for checking the success of the INSERT operation.

    Rate this question:

  • 30. 

    In SQL, this statement is used to change the contents of an existing row in a table:

    • A.

      SET ROW

    • B.

      CHANGE

    • C.

      UPDATE

    • D.

      REFRESH

    Correct Answer
    C. UPDATE
    Explanation
    The UPDATE statement in SQL is used to modify the contents of an existing row in a table. It allows you to change the values of one or more columns in a specific row based on certain conditions, such as using a WHERE clause to specify which row(s) to update. This statement is commonly used in database management systems to update records and keep the data up to date.

    Rate this question:

  • 31. 

    What is the default concurrency level of a ResultSet object?

    • A.

      Public

    • B.

      Updatable

    • C.

      Private

    • D.

      Read‑only

    Correct Answer
    D. Read‑only
    Explanation
    The default concurrency level of a ResultSet object is "Read-only". This means that by default, a ResultSet object is not updatable and cannot be modified. It is used to retrieve data from a database and allows only read operations on the data. Other options such as "Public", "Updatable", and "Private" do not accurately describe the default concurrency level of a ResultSet object.

    Rate this question:

  • 32. 

    By default, ResultSet objects allows you to move the cursor:

    • A.

      Backward only

    • B.

      Vertically.

    • C.

      Forward only.

    • D.

      Horizontally.

    Correct Answer
    C. Forward only.
    Explanation
    The correct answer is "Forward only" because ResultSet objects in Java allow you to move the cursor only in a forward direction. This means that you can iterate through the ResultSet in a sequential manner from the first row to the last row, but you cannot move the cursor backward or jump to a specific row directly. This behavior is the default setting for ResultSet objects unless you explicitly specify a different type of scrolling behavior.

    Rate this question:

  • 33. 

    What Java class is a Swing component that displays data in a two‑dimensional table?

    • A.

      JTable

    • B.

      JFrame

    • C.

      JPanel

    • D.

      JTable2D

    Correct Answer
    A. JTable
    Explanation
    JTable is the correct answer because it is a Java class that is specifically designed to display data in a two-dimensional table format. It is a part of the Swing component library and provides various features for customizing the appearance and behavior of the table. JTable allows users to view and manipulate tabular data efficiently, making it a suitable choice for displaying data in a table format in Java applications.

    Rate this question:

  • 34. 

    A column in one table that references a primary key in another table is known as what?

    • A.

      Secondary key

    • B.

      Foreign key

    • C.

      Referenƭal key

    • D.

      Meta key

    Correct Answer
    B. Foreign key
    Explanation
    A column in one table that references a primary key in another table is known as a foreign key. This is because it establishes a relationship between the two tables, where the foreign key in one table refers to the primary key in another table. The foreign key ensures referential integrity, meaning that it enforces the consistency and validity of data between the related tables.

    Rate this question:

  • 35. 

    In an entity relationship diagram, the primary keys are denoted with:

    • A.

      (PK)

    • B.

      (1)

    • C.

      (KEY)

    • D.

      (PRIME)

    Correct Answer
    A. (PK)
    Explanation
    In an entity relationship diagram, the primary keys are denoted with (PK). This notation is commonly used to indicate the attribute or set of attributes that uniquely identify each entity in a database table. The use of (PK) helps to distinguish the primary key from other attributes and provides clarity in the diagram.

    Rate this question:

  • 36. 

    A qualified column name takes the following form:

    • A.

      ColumnName.TableName

    • B.

      TableName.ColumnName

    • C.

      RowName.TableName

    • D.

      DatabaseURL.ColumnName

    Correct Answer
    B. TableName.ColumnName
    Explanation
    A qualified column name refers to a specific column in a database table. It consists of the table name followed by a dot and the column name. This format helps to uniquely identify the column within the database and avoid any ambiguity. In the given options, the answer "TableName.ColumnName" correctly represents a qualified column name.

    Rate this question:

  • 37. 

    Appending the azribute ;create=true to the database URL:

    • A.

      Creates a new database.

    • B.

      Creates a new table.

    • C.

      Creates a new row.

    • D.

      Creates a new column..

    Correct Answer
    A. Creates a new database.
    Explanation
    By appending the attribute ";create=true" to the database URL, it indicates that a new database should be created. This means that a completely new and separate database will be created, which can be used to store and manage data. The other options, such as creating a new table, row, or column, are specific to an existing database and are not applicable in this context.

    Rate this question:

  • 38. 

    What term refers to data that describes other data?

    • A.

      Pseudo‑data

    • B.

      Micro data

    • C.

      Abstract data

    • D.

      Meta data

    Correct Answer
    D. Meta data
    Explanation
    Meta data refers to data that describes other data. It provides information about the characteristics and properties of the data, such as its structure, format, and meaning. Meta data helps in understanding and managing the data, making it easier to organize, search, and analyze. It can include information like data types, field names, data sources, data relationships, and data definitions. By providing context and understanding to the data, meta data enhances its usability and ensures its accuracy and consistency.

    Rate this question:

  • 39. 

    In a transaction, all updates to database must be successfully executed.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    In a transaction, all updates to the database must be successfully executed in order to maintain data integrity and consistency. This means that if any part of the transaction fails, all changes made within that transaction must be rolled back to ensure that the database remains in a valid state. Therefore, the statement "all updates to the database must be successfully executed" is true.

    Rate this question:

  • 40. 

    The term "commit" refers to undoing changes to a database.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The term "commit" actually refers to saving or finalizing changes to a database, not undoing them. When changes are made to a database, they are typically held in a temporary state until the user explicitly commits them, at which point they become permanent and cannot be easily undone. Therefore, the correct answer is False.

    Rate this question:

Viet Ho |Software development |
Viet, a versatile software developer, proficient in the development stack, excels in front-end with Svelte, TypeScript, and JavaScript. He's skilled in CSS, CSS libraries, Spring framework, Java, Golang, and MySQL. He thrives in Agile teamwork.
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.