Last Flashcards
What primitive types can be written as binary?
byte
short
integer
long
Where can’t the underscore in digits be placed?
- At the beginning or end of a number
- Next to a decimal point
- Prior to an F or L suffix
- In positions where an string of digits is expected (for example splitting 0X for hexadecimal in 0_X);
Given the following classes:
interface Account{
public default String getId(){ return “0000”; }
}
interface PremiumAccount extends Account{
public String getId();
}
And a class implementing PremiumAccoun, should it implement getId()?
Yes.
getId is redeclared as abstract and should be implemented by the implementing class.
Given a try-with-resource construction with two resources. The try throws an Exception and one of the two resources throws an IOException when closed. What will be Exception that is propagated to the method calling?
It will propagate the Exception.
IOException will be added as a suppressed exception to the Exception.
Which of the following are reduction methods on the Stream interface? filter reduce sum max add
reduce, max
Reduction means going from a Stream of objects to a single object. Filter could still result in multiple results, sum is not available on the Stream interface and add is not a method on the Stream interface.
What is the result?
Path p1 = Paths.get(“c:\personal\.\photos\..\readme.txt”); Path p2 = p1.normalize();
c:\personal\readme.txt
. will always be redundant
.. will eliminate the preceding path (photos in this case)
Describe the Supplier functional interface
Supplier R get();
Supplier sup = () -> “test”;
Describe the Function functional interface
Function R apply(T t);
Function fu = (x) -> x.toString();
String y = fu.apply(1);
Describe the Predicate functional interface
Predicate boolean test(T t);
Predicate pre = (x) -> x.equals(“hello”);
Boolean b = pre.test(“hello”);
Describe the Consumer functional interface
Consumer void accept(T t);
Consumer con = (x) -> System.out.println(x);
con.accept(“hello”);
Describe the UnaryOperator functional interface
UnaryOperator (extends Function) T apply(T t);
UnaryOperator op = (x) -> “hello “ + x;
op.apply(“world”);
What is the result of the p2, p3 and p4:
Path p1 = Paths.get(“c:\temp\test.txt”);
Path p2 = p1.resolve(Paths.get(“report.pdf”));
Path p3 = p1.resolve(Paths.get(“c:\report.pdf”));
Path p4 = p1.resolve(Paths.get(“”));
p1. c:\temp\test.txt\report.pdf
p2. c:\report.pdf
p3. c:\temp\test.txt
- If the argument is a relative path (i.e. if it doesn’t start with a root), the argument is simply appended to the path to produce the result.
- If the argument starts wiith a root it will simply return the argument.
- If the argument is an empty path it will return this path (p1).
What are the rules for the path.relativize(Path path) method?
- If this path and the given path do not have a root component
- If this path and the given path have a root component then the it’s implementation dependent if a path can be constructed
- If this path and the given path are equal, an empty path is returned.
The returned path can be appended to the this path and result in the given path.
Given that daylight Savings Time ends on Nov 1 at 2 AM in US/Eastern time zone. (As a result, 2 AM becomes 1 AM.), what will be the result of x?
LocalDateTime ld1 = LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 0);
ZonedDateTime zd1 = ZonedDateTime.of(ld1, ZoneId.of(“US/Eastern”));
LocalDateTime ld2 = LocalDateTime.of(2015, Month.NOVEMBER, 1, 1, 0);
ZonedDateTime zd2 = ZonedDateTime.of(ld2, ZoneId.of(“US/Eastern”));
long x = ChronoUnit.HOURS.between(zd1, zd2);
-2
Given a map with keys of type String and value of type String. When a value exists with key a and value “hello”. How can I merge a value into key a?
map.merge(“a”, “world”, (x, y) -> String::concat);
map.merge takes a BiFunction as the third argument. When using a class method reference the first argument will be used as the caller for the method, the other arguments are used as parameters for the method reference.