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.
- B: The Math class has static methods. The Random class needs to be instantiated. This is memorizing, but you have to memorize it.
- 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.
- 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.
- C: Using a random seed in the constructor provides the same sequence of “random” values each time.
Questions on Real World Applications of Java
- B,C: Servlets and JSF are both core web technologies. EJBs are used for the back end. SMTP is related to email.
- B: JMS is used for messaging without needing to wait for a reply.
- B,C: JDBC and JPA are the two core database technologies in Java.
- A: Applets run in a browser. JSF, JSP and Servlets are web technologies, but all run on a server
Questions on Formatting Strings
- 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.
- B,D: The argument index is 1 based. %d means digit/decimal and goes with int.
- 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.
- 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.
- D: The format strings are using with printf or format. The code calls println which expects a single String.
- A: This is your standard iterator idiom
- C: Since Iterator doesn’t use generics, it requires a cast to convert from Object to String
- 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.
- 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.
- 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.
- B,D: The strings are the same so compareTo() returns 0 and equals() returns true.
- F: The method is compareTo(), not compare() so the code doesn’t compile.
- 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.
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
Julian: Correct; thanks for noticing. (I didn’t proofread that well.)
Math and Random. Question 1. I think a code wrong rendered:
double num1 = _____________();</pre>
intnum2 = ____________.nextInt();
Agreed. Fixed.
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();
Ah of course! The random HTML distracted me from the real problem there. Thank you.