1 Flashcards
For the equals()-method, why can’t it always either return true or false?
- equals() always returns false for null
2. equals() always returns true for the object identity
Concerning equals() and hashCode(), name the two rules of the contract!
- if equals == true: hashcode must be equal
2. if equals == false: hashcode can be equal
Is the following legal? public class Outer { public static class Inner { } public static void main(String[] args) { Inner inner = new Outer().new Inner(); } }
No it is not. This results in a compiler error!
An welchen 2 Plätzen können Generics Definitionen stattfinden?
- Direkt nach dem Klassennamen
2. Direkt vor dem return Type
What is the natural ordering concerning Numbers and Strings in Java?
Lowest first:
Firstly 0-9: 0, 3, 67, 232
Then uppercase A-Z: AAB, ABB, ZDS
Then lowercase a-z: aab, abb, zds
When adding a non-Comparable Class-Instance to a sorted data structure, which has not been provided a Comparator, does this lead to:
- A compiler error
- An Exception
- Unexpected behaviour
This leads to an Exception at Runtime.
It isn’t being checked at compile-time, since both comparable and non-comparable Instances can be added to a sorted data structure.
What does the following situation lead to?
Stream s = Arrays.asList(“Hello”, “World”).stream();
s.forEach(System.out::println);
s.forEach(System.out::println);
An Exception at runtime, since the stream is used twice.
This can’t be checked by the compiler.
Is the following code legal?
Arrays.asList(“Hello”,”World”)
.filter(!String::isEmpty)
.forEach(System.out::println);
No, method references cant be combined with operators!
What TemporalUnit-Enum type can be passed to the Instant-Classes plus() method?
Everything smaller than (including) DAYS (DAYS, HALF_DAYS, HOURS, MINUTES…)
What TemporalUnit-Enum type can be passed to the LocalDateTime-Classes plus() method?
Everything smaller than (including) HALF_DAYS (HOURS, MINUTES, SECONDS…)
What TemporalUnit-Enum type can be passed to the LocalDate-Classes plus() method?
Everything larger than (including) DAYS (WEEKS, MONTHS, YEARS)
Explain the behaviour of Path.relativize() when passing it a relative path, while the reference path is absolute.
This throws an IllegalArgumentException!
What happens when you pass an absolute Path to the Path.resolve()-method?
It returns the absolute path directly.
What needs to be done for a change made by an updateable ResultSet to actually take effect?
The ResultSets updateRow()-method has to be called.
Concerning the InputStreams marking feature, which method actually throws an Exception if marking is used even though it is not supported?
The reset()-method throws the Exception.
Is ObjectIntConsumer a functional Interface?
No ObjectIntConsumer is not a functional Interface.