Certification Exam My Exam Experience

Four questions confused me

my oca experience-four questions confused me
Written by Mushfiq Mammadov

Note: I know that it is not legal to share actual exam questions. Therefore all examples have been changed in the following post and similar codes have been used.


1) In two questions I couldn’t decide between two answer options.

The first question was related to Wrapper. The question was like following example:

    public static void main(String[] args) {
        int i1 = Integer.parseInt(args[0]);
        boolean b1 = Boolean.parseBoolean(args[0]);
        System.out.println(i1 + " " + b1);
        int i2 = Integer.valueOf(args[0]);
        boolean b2 = Boolean.valueOf(args[0]);
        System.out.println(i2 + " " + b2);

Everything was clear about parseXXX() methods because they returned primitive value. But I got confused with the valueOf() method, because it returned Reference. I thought it might cause compilation fail if there was no intValue() at the end: Integer.valueOf(args[0]).intValue();
But then I changed my mind. I thought there was no need to call intValue() because we can initialize Integer.valueOf(args[0]) to primitive type due to unboxing. After exam I immediately checked it and found that I had answered it correctly.

The second question was regarding Lambda. Generally I had learned Lambda well, I usually answered most of lambda questions correctly in mock exams. And I learned some new facts regarding Lambda from Enthuware which I didn’t know before. The lambda question asked in the actual exam was a bit different and I had never seen such type of question before in SYBEX and Enthuware. ~15-20 minutes after exam you get feedback showing the respective topics of the questions that you answered incorrectly. In my feedback three topics were shown and one of them was about lambda. Since in the actual exam I got only one question about lambda, I understood that was one of my mistakes. That question was similar to the following sample:

  String names[] = {"Roel", "Jeanne", "Paul", "Mushfiq"};
  List<String> list = new ArrayList(Arrays.asList(names));
  if(list.removeIf( (String s) -> { return s.contains("s"); } )){
      System.out.println(s + " removes");

When I saw asList() and removeIf() together the first thing that came to my mind was that this code throws UnsupportedOperationException. Because we create “fixed size list” with Arrays.asList() we can’t change the size of this list. But before choosing that option I checked lambda syntax because I had learned from my studies that most of lambda questions were related to syntax. removeIf() method takes parameter in type of Predicate interface and:
• the parameter type was shown explicitly (String) so it had to be parentheses and ok;
• there had to be arrow and ok;
• there had to be semicolon and braces because of return statement and it had to return boolean value and ok.
After making sure that everything was correct with syntax I chose “throws UnsupportedOperationException” as answer. But I changed my mind when I looked through all questions again at the end. I remembered I read somewhere that the list isn’t considered “fixed size” if we create Arrays.asList() inside new ArrayList(). Therefore I came to conclusion that this code didn’t throw exception and I chose the option “Mushfiq removes”. But after actual exam I tested this code in IDE and saw that there was a tricky point. I checked only line 7 as syntax, but complication fail occured on line 8. The variable declared in parameter list cannot be used outside lambda body.

2) There were two complex questions with a weird structure:

The first question was regarding import. Similar as the following:
There is a project called A. Project A contains B and C packages:

package B;
public class ClassB {}

package C;
public class ClassC {}

The question is that which imports are required to use ClassC inside ClassB? Choose two valid syntax options (approximately):

A. String name = ClassC.getName();
B. import A;
C. import C.ClassC;
D. import B.ClassB;
E. String name = C.ClassC.getName();

Required import is only option C. But I had to choose two options so I chose option D because option D is valid syntax, but is not required. It was weird that there was no information about getName() method. At that moment I remembered Roel`s words (sorry if I remember wrong): “If something doesn’t exist in question you shouldn’t guess it”. Therefore I chose option C and D. But I don’t remember that question exactly, I might be wrong.

The second question was regarding this() and super(). This question was similar to the 44th question of Enthuware Standard Test 5, but it had a very complex structure. The size of question was bigger than that of screen, so you had to use scroll to see the end of question..

According to the feedback I know that one of my incorrect answers was regarding lambda. The other four incorrect answers are still interesting for me

About the author

Mushfiq Mammadov

Leave a Comment


This site uses Akismet to reduce spam. Learn how your comment data is processed.