Junior Associate Blog Post Answers

How to study for the Java Foundations Junior Associate exam links to practice exam questions. This page provides the answers to those questions. It’s a separate page so you don’t accidentally see the answers while reading the questions.

Questions on Random and Math

  1. B: The Math class has static methods. The Random class needs to be instantiated. This is memorizing, but you have to memorize it.
  2. A, B: This method returns double values from 0 to 1 including 0 and not including 1. C and D are incorrect because they are too high.
  3. A,C: This method returns int values from 0 to 4 including 0 and 4. B is incorrect because is not an int. D is incorrect because it is too high.
  4. C: Using a random seed in the constructor provides the same sequence of “random” values each time.

Questions on Real World Applications of Java

  1. B,C: Servlets and JSF are both core web technologies. EJBs are used for the back end. SMTP is related to email.
  2. B: JMS is used for messaging without needing to wait for a reply.
  3. B,C: JDBC and JPA are the two core database technologies in Java.
  4. A: Applets run in a browser. JSF, JSP and Servlets are web technologies, but all run on a server

Questions on Formatting Strings

  1. D: The “2$” portion of “%2$d” denotes the second argument to be formatted, which is the 5. Therefore, 5 is output twice and the 10 does not appear in the result. The output is 5 is bigger than 5 and the answer is D.
  2. B,D: The argument index is 1 based. %d means digit/decimal and goes with int.
  3. F: This question is checking to see if you notice that %d is for int values and we’ve used it as a double. A runtime exception is thrown because we are passing a floating point number.
  4. D: Trick question! The format strings use % and not $. Since no actual replacements are present, the output is just the literal text and Choice D is correct. If the format string was %n, %s, the answer would be Choice F because the wrong arguments are passed in.
  5. D: The format strings are using with printf or format. The code calls println which expects a single String.

Questions on Using Iterators

  1. A: This is your standard iterator idiom
  2. C: Since Iterator doesn’t use generics, it requires a cast to convert from Object to String
  3. A: Since List doesn’t use generics, Iterator gives a warning since it does use generics. The code still compiles though when using the standard iterator idiom.

Questions on CompareTo

  1. A,E: Uppercase letters sort before lowercase ones making the first string smaller and compareTo() return a negative number. The Strings are not an exact match so equals() returns false.
  2. C,E: Blanks sort before uppercase letters making the second string smaller  and compareTo() return a positive number. The Strings are not an exact match so equals() returns false.
  3. B,D: The strings are the same so compareTo() returns 0 and equals() returns true.
  4. F: The method is compareTo(), not compare() so the code doesn’t compile.
  5. C,E: Numbers letters sort before letters making the first string larger and compareTo() return a positive number. The Strings are not an exact match so equals() returns false.

 

6 thoughts on “Junior Associate Blog Post Answers

  1. String first = “MOO”;
    String second = “1”;
    System.out.println(first.compareTo(second));
    System.out.println(first.equals(second));
    I think an answer is wrong on question number 5 on compareTo – it will be positive not negative

  2. Math and Random. Question 1. I think a code wrong rendered:
    double num1 = _____________();</pre>
    intnum2 = ____________.nextInt();

  3. Math and Random. Question 1.
    double num1 = _____________();
    int num2 = ____________.nextInt();

    Answer: B: Math, new Random()

    double num1 = Math(); ? I think it should be:
    double num1 = Math.random();

Leave a Reply

Your email address will not be published. Required fields are marked *