Exam Flashcards

1
Q

How many public classes in a .java file, and what are conditions on it and the file name.

A

1, and name must match with file name

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

When can compilation of Java code be omitted

A

When entire program is in one file

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

What is the output from compiling a java type definition?

A

Each type definition in a .java file is compiled to its own .class file whether public or not

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

What are the conditions for single file program

A
  • All definitions in one file,
  • First class much define main method
  • No compiled .class file for contents
  • Can’t access other compiled classes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Statement, Expression which returns a value?

A

Expression

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

What are all the syntax’s for comments

A

// Text
/* Text */
“””Text”””

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

What is the order of primitive widening conversions? How does char fit into this?

A

byte, short, int, long, float, double

char can be widened to int but not byte, short

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

What is the range of byte type

A

-128, 127

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

How is long 2L printed

A

2

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

How is float 2F printed?

A

2.0

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

In operator precedence where does equality come?

A

After relative >=, but before bitwise and &. Mid table

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

What is XOR ^ truth table

A

T^T = F
T^F = T
F^T = T
F^F = F

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

Name all 9 cases where var type is not permitted

A

Instance variable
Static variable
Method Parameters
Without initialisation or initialised to null
Compound declaration
Array initialisation like this a = { 1, 2, 3 }
As array element type
No self reference in initialisation
Return type

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

Give example of compound assignment

A

String s, t = “def”
(FYI, s is not initialised)

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

List all the valid array initialisations

A

int[][] a = new int[10][10]
int[] a [] = new int[3][3]
int a[][] = new int[3][3]
int[] a = new int[]{1,2,3}
int[] a = {1,2,3}

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

What are the 6 +/- methods on AtomicInteger

A

.addAndGet
.getAndAdd
.decrementAndGet
.getAndDecrement
.incrementAndGet
.getAndIncrement

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

What are the characteristics of the Runnable interface and Callable interface

A

Runnable takes no inputs and doesn’t return anything and throws no Exceptions. Callable takes no inputs but can return a value and can throw Exception
Both can throw unchecked exceptions

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

Are private static methods allowed in Interfaces?

A

Yes

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

What are the integer primitives and is this valid

integerPrimitiveType t = 0;

A

byte, short, char, int and yes the assignment is valid as they are integer primitives.

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

What is the result of:
Path p1 = Paths.get(“c:\a\b\c”);
p1.getName(1);

A

b

Drive letter is not included in path.

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

What is getRoot(path) on both windows and linux file systems

A

Windows -> c:\ (drive letter)
Linux -> /

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

Is this valid

Integer i = 1;
double a = i

A

Yes

Unboxing followed by widening conversion is allowed

https://docs.oracle.com/javase/specs/jls/se11/html/jls-5.html

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

Does Object class implement Comparable?

A

No

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

Collections.sort(array, null)

Does this compile and if so how does it sort

A

Yes and natural sorting

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

What are the types in the below

Object[] o = { 100, 100.0, “100” }

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

What is module-info.java compiled into

A

module-info.class

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

What is the result of and why?

int[] ia1 = { 0, 1, 2, 6};
int[] ia2 = { 0, 1 };

    System.out.println(Arrays.compare(ia1, ia2));
A

2

If one array is a prefix of the other than the result will not just be -1, 0, 1

It will take into account the difference in the number of elements

Non null value is considered lexicographically larger than null value.

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

Record instance variables are implicitly what?

A

private and final

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

What runtime exception can be thrown with

Console c = System.console();

A

It can throw NullPointerException if console is not support and null is return, the next access of c will throw.

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

Which is time based and which date based
Period
Duration

A

Duration - Time
Period - Date

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

What are the interfaces for

Car::getModel()

car::getModel()

where Car is the object type, car is an instance of Car

A

Function and Supplier respectively

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

Can boolean be used in switch statement/expression?

What are the allowed types for switch?

A

No

byte, short, char, int and their wrapper classes. Then enum and string

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

What is the StringBuilder method to set capacity?

A

.ensureCapacity(int)

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

What is the lambda for stream.mapToInt()

A

X->x

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

Choosing from modules and packages, which are required and which are exported?

A

Modules are required and packages exported

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

int a, b;

a = b = 2;

Is this valid?

A

Yes

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

What format is LocalDate printed in?

A

2023-12-30

ISO_DATE format

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

What are the rules for functional interfaces

A

One abstract method
Default methods are allowed
Static Methods are allowed
Private Methods are allowed

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

With an SQL query that returns columns ID, NAME, AGE as ResultsSet. What are the ways of getting AGE value for row as an int?

A

rs.getInt(2)
rs.getInt(“AGE”)

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

What is the condition for a variable to be used in a lambda

A

It needs to be effectively final

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

What type of variables are initialised to default values and which are not? What are their default values?

A

Static and instance variables are initialised to default values

Boolean - False
Char - ‘\u 0000’
Numerical Primitive - 0 or 0.0
Reference - Null

Local variables are not initialised to default values

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

What can be put in to

Public static void main() and won’t change behavior.

What will change it?

A

Final

Changing access type, removing static and return type.

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

Is this valid?

abstract interface Interface {}

A

Yes, interfaces are implicitly abstract but there is no issue adding keyword explicitly

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

What does Paths.get(“c:\..\temp\test.txt”).normalize().toUri() evaluate to?

A

file:///c:/temp/test.txt

.. on root is just root

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

What do these String methods to:

.isBlank()
.isEmpty()
.strip()

A

.isBlank() - True if empty or only comprised of whitespace

.isEmpty() - True only if length is zero

.strip() - Strip removes leading and trailing whitespace

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

What happens when .remove(index) is called on an empty list?

A

IndexOutOfBoundsException

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

What is the method determination for
- Hidden methods
- Overridden methods
- Overloaded methods

A
  • Hidden: Reference
  • Overridden: Actual object type at runtime
  • Overloaded: Actual object type at runtime
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

What is the method determination order for inputs?

A

Promotion, Cast, Boxing, Varargs

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

What does \s regex stand for?

A

A single whitespace

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

Can abstract classes have constructors?

A

Yes

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

What is the return type of Stream.count()

A

long

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

How is the Duration 12H 30M 12.45S printed?

What are the units for durations always?

A

PT12H30M12.45S

Hours, Minutes and Seconds with decimal

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

What exception is thrown when a file does not exist, give the fully qualified name.

A

java.nio.file.NoSuchFileException

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

When a sub class defined instance variable the same as super class is it overridden, overloaded or hidden?

How is the instance variable determined?

A

Hidden by the type of reference variable not actual type of object.

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

Will this compile and why?

switch(day){
case MONDAY:
TUESDAY:
WEDNESDAY:
THURSDAY:
FRIDAY: System.out.println(“working”);
case SATURDAY:
SUNDAY:
System.out.println(“off”);
}

A

Yes, the lines without case are just labels on the printing of “working”

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

What class and generic types does Properties class extend?

A

HashMap<Object, Object>

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

What is wrong with this definition?

Consumer x = (String msg)->{ System.out.println(msg); };

A

Consumer<> Is not typed and therefore implicitly typed to Object. This is not compatible with String msg and therefore won’t compile.

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

Does Stream.findFirst() take any parameters, and if so what?

A

No

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

How do you describe a module with java cmd

A

java -p/–module-path moduleFolder -d/–describe-module moduleName

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

How do you describe a module with jar cmd

A

jar -f/–file jarFile.jar -d/–describe-module moduleName

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

How do you list the java system modules

A

java –list-modules

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

How do you list the java system modules and the modules in a particular directory

A

java -p . –list-modules

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

Is this a valid record definition?

record Student(int id, String… subjects)

A

Yes

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

Are Records allowed static fields?

A

Yes

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

Can Records implement interfaces?

A

Yes

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

Can Records define other instance methods?

A

Yes

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

Which one of these can Records define?
- Extra instance fields
- Static fields
- Static methods
- Private method

A

No
Yes
Yes
Yes

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

What does \ mean in regex terms

A

Negate carriage return

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

What is the result of 10.0/0.0

A

Double.POSITIVE_INFINITY

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

How do you load a service?

A

ServiceLoader.load(service.class)

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

What are the elements of ServiceLoader.stream() and how are they accessed

A

<ServiceLoader.Provider<S>></S>

Provider.get()

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

Is this valid?

public int method() {
throw Exception();
}

A

Yes not need to return value if throwing exception

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

Which cmd line tool is –jdk-internals valid for and what does it do?

A

jdeps - It finds class level deps on JDK internal APIs which are inaccessible.

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

How is determination of an instance field named the same in both parent and child class?

How can the instance field in parent be accessed?

A

Based on reference type

By casting the reference type to the type of parent class.

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

How is determination of static field named the same in both parent and child class?

A

Based on reference type

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

What is the natural ordering for Enum types?

A

The order in which they are defined

77
Q

Can a record define a compact constructor and a canonical constructor?

A

No

78
Q

When an exception is printed, what is the output

A

Name of Exception type and message

79
Q

How do you get full stack trace from exception

A

Exception.printStackTrace()

80
Q

How do you get the number of elements on a Set collection

A

Set.size()

81
Q

What is special about ArrayDeque and what are its methods?

A

It can be used as a stack and a queue

Queue methods - add, remove, offer, poll

Stack methods - push, pop

82
Q

A pattern matching variable can/cannot shadow which variable types

A

Can’t shadow local, can shadow instance

83
Q

Where can labels be used and where can they not be used

A

They can be used on any code block or block level statement e.g for. But not declarations

84
Q

How do you access instance variable of outer class from within nested type?

A

OuterClass.this.variable

85
Q

How do you access outer instance variable from static member type?

A

You can’t access outer instance variables from static context

86
Q

How do you initialise instance of inner class

A

It needs to be associated with instance of our class

new OuterClass().new InnerClass()

87
Q

What are the top level types

A

Class, enum, record, interface

88
Q

What are the three types of nested type?

A

Static Member Type
Inner Classes
Static Local Type

89
Q

What are the types of Static Member Types?

A

Class, enum, interface, record

90
Q

What are the types of inner class?

A

Non-static member type
Anonymous Class
Local Class

91
Q

What are the types of static local types?

A

Interface, enum, record

92
Q

What access types can static member types have?

A

Public, protected, package and private

Apart from interface where members are implicitly static and public.

93
Q

How is the type defined for an nested type (NestedType) inside an OuterType

A

OuterType.NestedType

94
Q

How is a static member type initialised?

A

new OuterType.StaticMemberType()

Directly on the outer type

95
Q

What type of variables can static member types access in containing type?

A

Only static as they type is static

96
Q

Can static member types define instance variables?

A

True

97
Q

What nested types are implicitly static?

A

Enum, Record and Interface. Hence why we can only have inner classes

98
Q

How do you access an instance variable of parent class from within child class which is hidden?

A

super.a

99
Q

When an inner class extends another class that has a variable that matches variable from enclosing type which takes precedence when referenced by simple name

A

Inherited variable

100
Q

What access modifiers can a local class have?

A

None, as it can’t be accessed from outside block. Only if it extends another class and is referenced super type

101
Q

What access modifiers are allowed for members of a local class? And how can they be accessed in enclosing class?

A

They can have any and are accessible in enclosing context regardless of access set

102
Q

What does the put methods of HashMap return?

A

If the value exists in the hash map already this value is returned after updating the value in map. If it doesn’t then null is returned.

103
Q

What is the input type for Stream.peek()

A

Consumer

104
Q

What is the output of

System.out.println(null)

and

String s = null;
System.out.println(s)

A

Compilation error

and

null

105
Q

What is the output of

System.out.println(true)

and

System.out.println(“” + true)

A

true

and

true

106
Q

What is the database type for string

A

Types.VARCHAR

107
Q

How do you set an sql parameter to null

A

statement.setNull(3, Types.VARCHAR)

108
Q

What is the rule about ambiguous members when implementing multiple interfaces

A

Having multiple ambiguous members inherited is fine, referencing them in an ambiguous way will cause CTE.

109
Q

What does ArrayList.subList() do?

A

It returns a view of the arraylist, backed by the original list, changing elements in one will reflect in the other.

110
Q

What are the jmod commands

A

create
extract
describe
list

111
Q

And enums constructor is what?

A

Implicitly private

112
Q

What does Arrays.mismatch() do?

A

Return the first index where two arrays differ

113
Q

What is the abstract method for Comparable interface

A

compareTo(Object o)

114
Q

What is the abstract method for Comparator interface

A

compare(Object o, Object 0)

115
Q

What are the two formats of List.toArray()?

A

Object[] toArray()

and

<T> T[] toArray(T[] t), elements from list will be put in array of type T, if elements fit they will go in that array otherwise new array will be created.
</T>

116
Q

Give the module, package format of module-info.java

A

module module_name {
requires module0
requires module4
requires transitive module3
exports package to module1, module2
opens package
provides interface with class
use type
}

117
Q

What are the rules for overriding/overloading generic methods

A

Erasure occurs on the method inputs, so if this is the same between methods that do not properly override each other then CTE.

For overriding methods the return types have to be covariant with the same Generic Type.

118
Q

What is the format string for full text time zone?

A

zzzz

119
Q

Are instance variables in sub classes initialised before super constructor is called?

What if the instance variable is marked final?

A

No it is not, but it is if marked final

120
Q

If you have an overloaded method that has a variant that takes, Object, Number, Integer and Long, and you call it with primitive type double, which method is called?

A

The one with Number input as the double is first Boxed and then Number is the most specific input type.

121
Q

If you have a list and call .subList(1,1), how many elements will be returned?

A

Zero

122
Q

Is ClassNotFoundException a checked or unchecked exception

A

It is a checked exception

123
Q

What is the output?

char a = ‘a’, b = 98;
int a1 = a;
int b1 = (int) b;
System.out.println((char)a1+(char)b1);

A

195

124
Q

Is the below string interned?

String s = “Hello”

A

Yes

125
Q

Is there incidental whitespace in this text block?

String s2 = “””
Hello World”””;

A

Yes

126
Q

Which of these is a subtype of List<? super Integer>

List<? extends Integer>
List<? super Number>
List<? extends Number>
ArrayList<? extends Integer>
ArrayList<Number>
ArrayList<Integer></Integer></Number>

A

List<? super Number>
ArrayList<Number>
ArrayList<Integer></Integer></Number>

127
Q

Is List<Integer> a subtype of List<Number></Number></Integer>

A

No

128
Q

How do you create an empty Optional

A

Optional.ofNullable(null)

129
Q
A
130
Q

What does compareAndSet do on the AtomicInteger classs

A

compareAndSet(expected, newValue) compares current with expected and if they are the same then updates to newValue.

131
Q

Is this valid?

float f = 0x0123;

A

Yes

132
Q

What does Collections.unmodifiableList() do?

A

It creates unmodifiable view of original collection but the change the underlying collection will change the view

133
Q

What does isSameFile(p1, p2) do?

A

It checks to see if both paths are the same in the file system, following symlinks. If the paths are equal then it will return True without checking if the files exist.

134
Q

How do you declare the type to use in generic method on a type C

A

C.<Type>method()</Type>

135
Q

What is the access modifier for a constructor automatically inserted?

A

The same as the access of the class that it was inserted for.

136
Q

What is the acronym for operator precedence?

A

AUpoUpreCMASRBCAA
Access
Unary Post
Unary Pre
Cast/Constructor
Multi
Additive
Shift
Relational
Bitwise
Conditional
Arrow
Assignment

137
Q

What does Path.toAbsolutePath() do

A

Creates an absolute path, if already abs then returns that, otherwise creates absolute depending on implementation

138
Q

What does Path.toRealPath() do?

A

Gets the real path to existing file in system, throws if doesn’t exist. Converts to abs path first

Does not follow Symlinks

139
Q

What does Path.normalize() do?

A

It will condense the path to its most basic form removing redundant elements

140
Q

What does Path.resolve(otherPath) do?

A

If otherPath is abs it returns that, otherwise it adds otherPath on to the end of current path

141
Q

What does Path.resolveSibling(otherPath) do?

A

Calls resolve on parent

142
Q

What does Path.relativize(otherPath) do?

A

It will determine the path from current path to otherPath. Both need to be relative or absolute

143
Q

How does Path.equals(otherPath) compare paths?

A

It only compares the strings and it doesn’t normalise them first.

144
Q

What are the 4 way to create Path objects?

A

Path.of(String p, String …)
Path.of(URI)
FileSystem.getPath(String p, String …)
Paths.get(String p, String …)

145
Q

How do you convert a Path to legacy File type?

A

Path.toFile()

146
Q

Does Files.exists(Path) follow symlinks?

A

Yes

147
Q

What is the Symlink constant?

A

LinkOptions.NOFOLLOW_LINKS

148
Q

What does Files.isSameFile(Path, Path)

A

It compares the path strings only, normalising and following symlinks

149
Q

How does Files.delete(Path) and Files.deleteIfExists(Path)

A

delete will throw if the file does not exist and has void return type, while deleteIfExists will return boolean.

150
Q

How does Files.delete(Path) and Files.deleteIfExists(Path) behave with directories?

A

Deletes them if they are empty

151
Q

How does Files.delete(Path) and Files.deleteIfExists(Path) behave with symlinks?

A

Delete the symlink not the target

152
Q

What the are the Files.copy signatures?

A

copy(InputStream, Path)
copy(Path, OutputStream)
copy(Path, Path)

153
Q

How does Files.copy behave if the destination Path exists already

A

It throws a FileAlreadyExistsException and if REPLACE_EXISTING has not been specified

154
Q

How does Files.move(Path, Path) behave

A

It throws a FileAlreadyExistsException and if REPLACE_EXISTING has not been specified

If target is symlink that it is moved and not the target

155
Q

How does Files.createDirectory(Path) behave?

A

It will throw exception if the destination already exists, it will only create the target and throw exception if parent of path does not exist

156
Q

How does Files.createDirectories(Path) behave?

A

It will create all non-existent parent directories of path first, and won’t throw an exception if one exists.

157
Q

What are the signatures of the Files.find() and .walk() methods?

What is the return type of these methods?

A

find(Path, depth, Bifunction, FileVisitOptions )
walk(Path, FileVisitOptions)
walk(Path, depth, FileVisitOptions)

158
Q

What is the return type of the Files.find() and .walk() methods?

A

Stream<Path></Path>

159
Q

Do Files.find() and .walk() methods follow links by default?

A

No

160
Q

What does Files.mismatch(Path, Path) do?

A

It will find the position of the first mismatching byte between two files.It will find the position of the first mismatching byte between two files.

161
Q

What is the behaviour of tryLock()

A

It will try to acquire the lock or move on, or try for the specified amount of time

tryLock(long, TimeUnit)

162
Q

What is the return type of Executors.newScheduledThreadPool(int)

A

ScheduledExecutorService

163
Q

What are the behaviours of

ScheduledExecutorService.scheduleWithFixedDelay()

and

ScheduledExecutorService.scheduleWithFixedRate()

A

Fixed delay will run the lambda again after given period, fixed rate will run the lambda again after the given period after it has completed.

The only exist for Runnables

164
Q

What the ExecutorService.execute() and ExecutorService.submit() return types

A

execute() returns void, while submit() returns Future

165
Q

Is return null equivalent to return; for a void method

A

No?

This would not work for Runnable lambda for instance

166
Q

What ordering will .forEachOrdered(Consumer) process in?

A

In the stored order of the original stream.

167
Q

How does Stream.findFirst() behave?

A

It will find the first stored element in stream even if it is parallel

168
Q

How does Stream.findAny() behave?

A

It will return first element read by thread, regardless of sorting or ordering

169
Q

What are the Streams.reduce signatures?

A

reduce(BinaryOperator<T>)
reduce(T Identity, BinaryOperator<T>)
reduce(U Identity, BiFunction<U,T>, BinaryOperator<T>)</T></T></T>

170
Q

What states are relevant for calling .interrupt() on a thread?

A

WAITING and TIMED_WAITING

171
Q

What does volatile keyword ensure?

A

Memory consistency but not threadsafety

172
Q

What variables can be used in lambda and what are the conditions?

A

They can use static, instance and local variables, but local variables must be final or effectively final.

173
Q

How does ScheduledExecutorService work with Callables

A

schedule(Callable, delay, TimeUnit)

174
Q

What are the ExectorService methods for Callables?

A

submit(Callable)
invokeAll(Collection<Callable<T>>)
invokeAny(Collection<Callable<T>>)
with timeouts.</T></T>

175
Q

Math class methods
.sum
.average
.pow

A
176
Q

Can an input stream’s .mark() functionality be re-used? E.g. .reset() called multiple times?

A

Yes

177
Q

Can a Record class extend another class?
Can it implement an interface?

A

No it can’t extend but it can implement and interface

178
Q

Does String.split() include trailing empty strings?

A

No

179
Q

How do you initialise DateTimeFormatter?

A

DateTimeFormatter df = DateTimeFormatter.ofPattern(“yyyy”);

DateTimeFormatter df = DateTimeFormatter.ISO_DATE;

DateTimeFormatter df = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);

180
Q

How do you get the default locale?

A

Locale.getDefault()

181
Q

What needs to be remembered with resources created in try-with-resource blocks?

A

They are implicitly final and can’t be re-assigned.

182
Q

What does the ArrayList.add() return?

A

It returns a boolean if the list is altered

183
Q

What are the return types for
Float.parseFloat()
Float.floatValue()
Float.valueOf()

A

Float.parseFloat(String) - float
Float.floatValue() - float
Float.valueOf(String) - Float
Float.valueOf(float) - Float

184
Q

What exception does the wrapper parse* methods throw?

A

NumberFormatException (Unchecked Exception)

185
Q

Can you override/hide a static method with instance method and vice versa?

A

No

186
Q

What is the input of Stream.averageInt

A

ToIntFuntion

187
Q

How do you add a new row with ResultSet

A

.insertRow()

188
Q
A