Java Flashcards

1
Q

An applet

A

a small program that is intended not to be run on its own, but rather to be embedded inside another application.

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

How to convert JSON string into List of Java object?

A

mapper.readValue(jsonString, new TypeReference<>(){});

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

for each Map

A

for(Map.Entry entry: map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
}

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

Create class without new in Java

A
Class ref = Class.forName("CIBuildStatusInfo");
CIBuildStatusInfo obj = (CIBuildStatusInfo) ref.newInstance();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

BiFunction / Supplier / Consumer ???

A
// два параметра, возвращает результат
BiFunction {
  R apply(T t, U u);
}
// два параметра, не возвращает результат
BiConsumer  {
  void  accept(T t, U u)
}
// один параметр, возвращает результат
Function {
  R apply(T t);
}
// один параметр, не возвращает результат
Consumer {
  void accept(T t);
}
// Без параметров, возвращает результат
Supplier {
  T get();
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

возвращает результат немедленно. Если результат еще не записан, возвращает значение параметра valueIfAbsent. [threads][method]

A

T getNow(T valueIfAbsent)

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

runAsync / supplyAsync - difference ?

A

static <u> CompletableFuture<u> supplyAsync(Supplier<u> supplier)</u></u></u>

static CompletableFuture runAsync(Runnable runnable)
</u></u></u>

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

Основной метод. Имеет на входе два фьючерса, результаты которых накапливаются и затем передаются в реакцию, являющейся функцией от двух параметров.

A

<u> CompletableFuture thenCombine(CompletionStage other, BiFunction fn)
</u>

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

Перехват ошибок исполнения

A

CompletableFuture exceptionally(Function fn)

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

В этом методе реакция вызывается всегда, независимо от того, заваершился ли данный фьючерс нормально или аварийно. Если фьючерс завершился нормально с результатом r, то в реакцию будут переданы параметры (r, null), если аварийно с исключением ex, то в реакцию будут переданы параметры (null, ex). Результат реакции может быть другого типа, нежели результат данного фьючерса.

A

<u> CompletableFuture<u> handle(BiFunction fn)</u></u>

</u></u>

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

how to create ExecutorService and ScheduledExecutorService ???

A
ScheduledExecutorService executorService = Executors
  .newSingleThreadScheduledExecutor();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Difference between: scheduleAtFixedRate and scheduleWithFixedDelay ?

A

FixedRate - will be executed after time delay even if previous task has not been finished yet
FixedDelay - wait till previous task will be finished, wait delay time and start new one

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

@Schedule(cron=”* * * * *”) - tell a bit more about it?

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

restTemplate ??? how to make requests

A

restTemplate.getForObject(url, List.class);

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

Скільки існує станів потоків?

A

6: NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED

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

How to create thread and run it?

A
new Thread(new C()).start();
C should implement Runnable
17
Q

How to give name of thread? (as parameter) we have new MyCustomThread() that implement Runnable

A

new Thread(new MyCustomThread(), “name”).start()

18
Q

Що таке мьютекс?

A

взаимное исключение, примитив синхронизации, обеспечивающий защиту определенного обьєкта в потоке от доступа других потоков

19
Q

What is synchronized and how it is used?

A

So, if we use synchronized in method, it means that only one thread can get access to the method at the same time. When we use without it, every thread has access to it

20
Q

Що таке семафор?

A

примитив синхронизации работи процесов и потоков в основе которого лежит счетчик

21
Q

What is Callable?

A

Callable - it is a better version of Runnable. Appears in Java 5.
Callable c = () -> {… should return V}

22
Q

Tell about interface Future

A
has 5 methods
boolean cancel(boolean mayInterruptIfRunning);
boolean isCancelled();
boolean isDone();
V get();
V get(long timeout, TimeUnit unit);
23
Q

What shouldn’t we forget to do while working with ExecutorService?

A

executorService.shutdown();

24
Q

Callable and we don’t want to return anything

A

Callable c = () -> {

return null;
}

25
Q

What is TreadPool?

A

пул тотоков, представляет собой группу робочих потоков которие виолняют задачи. If there is no available thread, our task stands in queue and wait till a thread will be available.

26
Q

Types of Executors???

A

SingleThreadExecutor
FixedThreadPool(n)
CachedThreadPool
ScheduledExecutor

Cached - 60 seconds and dead

27
Q

Framework Fork / Join

A

it is a framework for solving problems with using parallel approach “divide and conquer”

28
Q

ComletableFuture vs Future

A

Future не можна закінчити вручну
Неможливо виконувати багато Future один за одним
Неможливо об’єднувати декілька Future
There is no exception handling

29
Q

java.util.function

A
Consumer return void
Function return R
Supplier return T
BiFunction return R
BiConsumer
30
Q

Exception handling in ComletalbeFuture

A

handle, whenComplete, exceptionally / exceptionallyCompose

31
Q
List list = new ArrayList();
default value?
A

Object

32
Q

usual names for generic types in java?

A

The most commonly used type parameter names are:
E — Element
K — Key
N — Number
T — Type
V — Value
S, U, V etc. — second, third, and fourth types

33
Q

List - why is it wrong?

A

we can’t use primitive types in generics

34
Q

how to create a method with generic parameter without generic class declaration in Java?

A

public int getCount(List elements) {
return elements.size();
}

35
Q

what is wildcard in Java?

A

wildcard character (?) is used to indicate unknown type

36
Q

What is cascade=CascadeType.ALL in Spring JPA?

A

it means all changes that were applied to one table, reflect on another (for relations oneToMany and manyToOne)