274.
275.
}
Here, the doSomething() is a private
interface method that is
used within the default methods method1() and method2().
What is JShell?
Answer:
Jshell is basically a command line tool. It allows you to write and
run Java code without creating a class file.
It can be launched by
typing jshell on the command prompt. Once Jshell opens up,
you can type in any Java code
and JShell will display the
output of the code. So, for example if you type the following:
System.out.println(“Hello World”);
JShell will print the text
“Hello World”.
JShell adds REPL support to Java.
REPL stands for Read
Evaluate Print Loop Many languages like Python also provide
REPL capabilities.
What is the output of the following code snippet?
Optional
myDoubleOptional = Optional.of(10.0);
Optional defaultOptional = Optional.of(50.0);
double value = myDoubleOptional.or(()–>
defaultOptional).get();
System.out.println(value);
Answer:
Java 9 has added a new method on the Optional class called
or(). This accepts as parameter a Supplier instance that
produces an Optional. It returns an Optional. So, if the Optional