Access your current level in Java

  • The result of the quiz will determine the level to begin.
  • The Quiz contains 12 questions. All questions are mandatory.
  • You will be able to reattempt the quiz after 6 months.

Access your current level in Java

  1. In jShell, you have typed a partial function name, which is:
    usdToEUR(
    Which key should you press to autocomplete it?

  2. You execute following code:
    import java.util.Scanner;
    public class Main {
    public static void main(String[] args) {
    System.out.print(“Enter the temperature in Fahrenheit:”);
    Scanner tempInput = new Scanner(System.in);
    int temperature = tempInput.nextInt();
    tempInput.close();
    if (temperature >= 84) {
    System.out.println(“It's a hot day!”);
    } else {
    System.out.println(“Remember to stay hydrated!”);
    }
    System.out.println(“Have a nice day!”);
    }
    }

    When prompted, you enter the value as 75. Which of the following statements are printed?

  3. Consider the following code:
    public class Main {
    public static void main(String[] args) {
    boolean x = true;
    System.out.println(“x != false : ” + (x != false));
    }
    }

    What is the output?

  4. You are performing a multiplication on the float values:
    public class Main {
    public static void main(String[] args) {
    float num1 = 20F, num2 = 10F, result;
    result = num1 * num2;
    System.out.println(result);
    }
    }

    What is the output of the given code?

  5. You enter the following code in JShell:
    jshell> double usdToEUR(double usdValue) {
    . . .> return EUR_USD * usdValue;
    . . .> }

    What is likely to happen?

  6. You have written your first Java program, which is as follows:
    public class Main {
    public static void main(String[] args) {
    int number;
    System.out.println(number);
    }
    }
    You had declared a variable, but when you run the code, an error is generated:
    Main.java:15: error: variable number might not have been initialized
    What could be the possible cause?

  7. Review the following Java code:
    public class HandlingExceptions {
    public static void main(String[] args) {
    double[] prices = {5.90, 18.99, 64.0, 99.00, 79.50};
    int index = 5;
    System.out.println(“Start of the program”);
    try {
    System.out.printf(“nThe price at index %d is %fn”, index, prices[index]);
    } catch (Exception e) {
    System.out.println(“An Exception occurred”);
    }
    }
    }
    What is the outcome of this code?

  8. Which method does HashSet use on every object to compare two objects?

  9. Review the following Java code:
    package com.skillsoft.collections;
    public class Main {
    public static void main(String[] args) {
    String[] companies = {};
    String[] otherCompanies = new String[0];
    companies[0] = “Skillsoft”;
    System.out.println(otherCompanies.length);
    }
    }
    What is the output when you run this code?

  10. Review the following Java code:
    public static PreparedStatement getInsertVehiclePS(Connection conn) {
    try {
    return conn.prepareStatement(“insert into delvehicles values(?, ?, ?, ?)”);
    } catch (SQLException sqlex) {
    sqlex.printStackTrace();
    }
    return null;
    }
    What do the question marks in the return statement indicate?

  11. Review the following Java code:
    import org.json.JSONTokener;
    public class Main {
    public static void main(String[] args) {
    JSONTokener token = new JSONTokener(“I solemnly swear that I am up to no good”);
    while (token.more()) {
    System.out.println(token.next(5)); //line 10
    }
    }
    }
    What is the outcome of passing 5 to the next method being applied to the JSONTokener object on line 10?

  12. You want to combine the information present in the delpartners table and deliveries table to view which partner has been involved in which delivery. To be able to achieve this, what should you do?