Java 8 9 and 11 Interview Questions 1687538195
Java 8 9 and 11 Interview Questions 1687538195
Java 8:
➢ It can extend other interfaces which do not have any abstract method and
only have the default, static, another class is overridden
➢ Given a list of integers, find out all the even numbers exist in the
list using Stream functions?
List<Integer>myList
=Arrays.asList(10,15,8,49,25,98,32);myList.stream().filter(n ->n%2==
0).forEach(System.out::println);
➢ Given a list of integers, find out all the numbers starting with 1 using
Java 8^J9 and 11 Page 4
➢ Given a list of integers, find out all the numbers starting with 1 using
Stream functions?
List<Integer>myList
=Arrays.asList(10,15,8,49,25,98,32);myList.stream().map(s ->s +"")//
Convert integer to String.filter(s ->
s.startsWith("1")).forEach(System.out::println);
➢ Given a list of integers, find the total number of elements present in the
list using Stream functions?
List<Integer>myList
=Arrays.asList(10,15,8,49,25,98,98,32,15);longcount
=myList.stream().count();System.out.println(count);
List<Integer>myList =Arrays.asList(10,15,8,49,25,98,98,32,15);intmax
=myList.stream().max(Integer::compare).get();System.out.println(ma
x);
Java 9
➢ What is Jshell ?
Jshell is Repl tool
➢ Why Java 9 doesn't have rt.jar ?
Because from Java 9 onwards java follows modular approach
➢ What is the difference between module and Jar ?
Module contains extra file called module-info.java
➢ What principle does Jshell follow ?
REPL: Read, Evaulate, Print, Loop
➢ What are the advantages of Jshell ?
Developer firendly
➢ What is snippet in Jshell ?
Any valid java statement, variable declarion or method, or interface
or class
➢ What is the command to know all the snippets in Jshell
/list -all
➢ What is scratch variable ?
It is something which is create by Jshell
➢ What is the command to see all the methods in Jshell ?
/methods
➢ How to delete the method or variable in Jshell ?
/drop snippetId
➢ What is inactive snippet ?
/list - Active snippets
/list -all - inactive
➢ How to list all active and inactive snippets ?
➢ What is the command to see all the interfaces and classes present in
Jshell ?
/types
Java 11
➢ Can you execute a program without compilation ?
Yes from java 11, we can execute the program using the below
command and it does the compilation internally
Java className.java (Example: java Test.java)
➢ What is the difference between trim() and strip() method in Java 11
strip() method uses Character.isWhitespace() method to check if the
character is a whitespace. This method uses Unicode code points
whereas trim() method identifies any character having codepoint
value less than or equal to ‘U+0020’ as a whitespace character
➢ What are the changes to predicate in Java 11 ?