1 Flashcards

1
Q

For the equals()-method, why can’t it always either return true or false?

A
  1. equals() always returns false for null

2. equals() always returns true for the object identity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Concerning equals() and hashCode(), name the two rules of the contract!

A
  1. if equals == true: hashcode must be equal

2. if equals == false: hashcode can be equal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
Is the following legal?
public class Outer {
   public static class Inner { }
   public static void main(String[] args) {
      Inner inner = new Outer().new Inner();
   }
}
A

No it is not. This results in a compiler error!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

An welchen 2 Plätzen können Generics Definitionen stattfinden?

A
  1. Direkt nach dem Klassennamen

2. Direkt vor dem return Type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the natural ordering concerning Numbers and Strings in Java?

A

Lowest first:
Firstly 0-9: 0, 3, 67, 232
Then uppercase A-Z: AAB, ABB, ZDS
Then lowercase a-z: aab, abb, zds

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When adding a non-Comparable Class-Instance to a sorted data structure, which has not been provided a Comparator, does this lead to:

  1. A compiler error
  2. An Exception
  3. Unexpected behaviour
A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the following situation lead to?
Stream s = Arrays.asList(“Hello”, “World”).stream();
s.forEach(System.out::println);
s.forEach(System.out::println);

A

An Exception at runtime, since the stream is used twice.

This can’t be checked by the compiler.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is the following code legal?
Arrays.asList(“Hello”,”World”)
.filter(!String::isEmpty)
.forEach(System.out::println);

A

No, method references cant be combined with operators!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What TemporalUnit-Enum type can be passed to the Instant-Classes plus() method?

A

Everything smaller than (including) DAYS (DAYS, HALF_DAYS, HOURS, MINUTES…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What TemporalUnit-Enum type can be passed to the LocalDateTime-Classes plus() method?

A

Everything smaller than (including) HALF_DAYS (HOURS, MINUTES, SECONDS…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What TemporalUnit-Enum type can be passed to the LocalDate-Classes plus() method?

A

Everything larger than (including) DAYS (WEEKS, MONTHS, YEARS)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Explain the behaviour of Path.relativize() when passing it a relative path, while the reference path is absolute.

A

This throws an IllegalArgumentException!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What happens when you pass an absolute Path to the Path.resolve()-method?

A

It returns the absolute path directly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What needs to be done for a change made by an updateable ResultSet to actually take effect?

A

The ResultSets updateRow()-method has to be called.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Concerning the InputStreams marking feature, which method actually throws an Exception if marking is used even though it is not supported?

A

The reset()-method throws the Exception.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Is ObjectIntConsumer a functional Interface?

A

No ObjectIntConsumer is not a functional Interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Is ToLongBiFunction a functional Interface?

A

Yes ToLongBiFunction is a functional Interface.

18
Q

Describe the process when a ResourceBundle for a given Locale is requested, but the Locale is not present while a different default Locale is set.

A

It first checks out if a ResourceBundle for the given Locale is present.
Then it defaults back to the Systems default Locale.
Only if the Systems default Locale has no associated ResourceBundle, does it go back to the root ResourceBundle.

19
Q

Does java.util.Stream have an isEmpty()-Method?

A

No, since the size of the stream is not known until runtime!

20
Q

Is “Collection coll = new ArrayList();” legal?

A

Yes, it is legal since ArrayList conforms to Collection>.

21
Q

Is “Collection coll = new ArrayList();” legal?

A

Yes, it is legal since ArrayList conforms to Collection.

22
Q

Can interfaces be marked final?

A

No

23
Q

Is NotSerializableException a checked or an unchecked Exception?

A

It is a checked Exception.

24
Q

Is SQLException a checked or an unchecked Exception?

A

It is a checked Exception.

25
Q

Is ParseException a checked or an unchecked Exception?

A

It is a checked Exception.

26
Q

What happens if you do not provide a merger to the Collectors.toMap()-Method?

A

If there is a duplicate key an IllegalStateException is thrown!

27
Q

Name an alternative way to retrieving ChronoUnit.DAYS.between(date1, date2);

A

date1.until(date2, ChronoUnit.DAYS);

28
Q

Can you compare int and char values with “==”?

A

Yes, you can.

29
Q

Will “Runnable r = () -> 1;” compile?

A

No, it won’t since it can’t have a return value!

30
Q
Will the following compile?
Runnable r = () -> myMethodWithReturn();
String myMethodWithReturn() {
return "Hello World";
}
A

Yep, even though the method returns something it is legal! This is simply because Java is a bad programming language and anybody who says otherwise does not know what they are talking about.

31
Q

Name something notable about the parallel reduction of a stream.

A

The Identity is applied to each element of the Stream!

32
Q

In which way does a TreeMap order it’s elements?

A

It orders them by the keys, rather than the values!

33
Q

Does Files.delete throw any checked Exceptions?

A

No, it only throws an unchecked Exception!

34
Q

Name four important method of the Writer class!

A
  • append
  • close
  • flush
  • write (also takes in a char-Array)
35
Q

What type does the parameter of the String.equalsIgnoreCase()-Method have?

A

String

36
Q

Are InputStream and Reader classes or Interfaces?

A

They are abstract classes!

37
Q

How would you read the creation time of a File when you have access to a BasicFileAttributesView?

A

You first have to call readAttributes on the instance of BasicFileAttributesView, then you can call creationTime() on the returned BasicFileAttributes.

38
Q
Does the following compile?
public int myMethod() {
short s = 1;
return s;
}
A

Yes, since method return types enable autoboxing.

39
Q

Is the following legal?
long l = 1L;
double d = l;

A

Yes, since long can be converted to double without loss of precision.

40
Q

Is the following legal?
double d = 1.0;
long l = d;

A

No, since loss of precision would occur!