I gave a presentation showing how to make mock exam questions. We used Java 9 JShell as the example. The idea was to pick a feature nobody knew much about. We started by picking key points from this blog. Then we made questions. This post is the results. (Edited for formatting, to alphabetize answers, after confirming, etc). Good job all!
Question 1
What does REPL stand for?
- Random Enterprise Process Logic
- Rapid Enterprise Process Line
- Rapid Execution of Programming Logic
- Read Evaluate Print Loop
- Read Evaluate Print Line
- Read Execute Print Loop
Question 2
When typing into JShell interactively, it uses ______.
- Nashorn
- JRE
- JS
- JVM
- REPL
- RPEL
- Streams
Question 3
Which of the following compiles when typed into JShell? (Choose all that apply)
- Class.forName(“String.class”)
- Class.forName(“String.class”);
- Thread.sleep(1000)
- Thread.sleep(1000);
- System.out.println(“hello”)
- System.out.println(“hello”);
Question 4
Which of the following compiles when typed into JShell? (Choose all that apply)
- void method() { throw new Exception(); }
- void method() { throw new RuntimeException(); }
- void method() throw Exception { throw new Exception(); }
- void method() throw Exception { throws new Exception(); }
- void method() throws Exception { throw new Exception(); }
- void method() throw Exception { throws new Exception(); }
Question 5
Which of the following compiles when typed into JShell? (Choose all that apply)
- System.out.println(“Hello Java”)
- System.out.println(“Hello Java”);
- public void method() { throw new Exception(); }
- public void method() { throw new Exception(); };
- public void method() {System.out.println(“Hello Java”)}
- public void method() {System.out.println(“Hello Java”);}
- public void method() {System.out.println(“Hello Java”);};
Question 6
What are valid statement terminators in JShell? (Choose all that apply)
- ;
- :
- \n
- None (just press enter)
- None of the above
Question 7
Which of the following lines will compile and display a value if it’s the first line you type after launching JShell? (Choose all that apply)
- 5 + 6
- a + b
- System.out.println(“Hello”);
- System.out.println(“Hello”)
- out.println(“Hello”)
- out.println(“Hello”);
- { System.out.println(7) }
- { System.out.println(7); }
- 6 + 6; 10
- None of the above
Question 8
Which of the following is valid code in JShell? (Choose all that apply)
- system.out.println(“hello world”);
- system.out.println(hello world);
- Println(“hello world”);
- “hello word”
- hello world
- Answer: 5+3
- 5f+3
- new String()
Question 9
What is the output of the code below if executed in JShell?(Check all that apply)
Integer a = 5;
Integer c = a + 10;
Integer a = 7
a
- Compiler Error
- Runtime error
- 7
- Error: Duplicate variable declaration
- None of the above
Question 10
Which of the following commands invokes the help command in Jshell? Choose all that apply.
- /h
- /help
- /?
- ?
- f1
- ctrl-f1
- help
Question 11
How would you invoke help on a particular Jshell command? Choose all that apply.
- /help=command
- /help:command
- /help command
- /he command
- /h command
Question 12
double area (double radius) {
return 3.14 * square(radius);
}
area(2)
What is the correct output?
- 6.28
- 6
- 7
- Attempted to call area(double) which cannot be invoked
- Attempted to call square which cannot be invoked
Answers
- Choice 4 – Read Evaluate Print Loop
- Choice 5 – REPL
- All 6 choices are correct. The first two throw an exception, but do compile. (This question had public in the user group lab. I wrote this question and removed it after)
- Choices 2 and 5. The semicolon is only optional at the end of the statement; not within a block
- Choices 1, 2, 6 and 7. The last two give a warning about public not being allowed, but work. The others fail because of an exception or missing semicolon within a method.
- Choices 1 and 4. Semicolon terminates a statement or you can omit the terminator
- Choices 1, 3, 4, 8 and 9. The last one is tricky. It gets executed as two statements.
- Choices 4, 7 and 8. JShell is case sensitive; just like Java
- Choice 3. (In the user group lab, there was another choice about a warning for a duplicate variable. I couldn’t reproduce the warning so removed that choice to avoid ambiguity.)
- Choices 2 and 3. Isn’t memorization fun?
- Choices 3 and 4. More memorizing
- Choice 4. Creating the method works, but gives a warning that square(double) must be declared. Then calling area gives “attempted to call method area(double) which cannot be invoked until method square(double) is declared”