java Flashcards

1
Q

JVM vs JRE vs JDK

A

Spec vs runtime vs runtime + dev tools

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

Is java 100% oriented?

A

No - primitive types

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

Wrapper classes

A

Wrap primitives to add some API / use in collection

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

Constructor

A

A block of code to initialise an object. Same name as class, no return type

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

Singleton

A

Only one instance in JVM. Private constructor

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

ArrayList vs Vector

A

Fast, non-synchronised vs Slow and synchronised

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

equals() vs ==

A

Equality of objects from business perspective vs memory address.

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

Stack

A

LIFO, stack memory can be used by other threads, contains local, primitive and reference variables to objects in heap space, exists until the end of execution of the thread. -Xss, StackOverflow

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

Heap

A

Memory lives until the end of app: objects. classes -Xms and -Xmx OutOfMemoryError

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

What is a package in Java? Why?

A

A collection of related classes and interfaces to modularise code and avoid name clashes.

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

Why pointers are not used in Java?

A

JVM is responsible for implicit memory allocation.

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

What is JIT compiler in Java?

A

Compiler decides which parts of the code should be optimised.

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

What are access modifiers in Java?

A

Keywords to restrict access to class method, field: public, protected, default, private.

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

OOP

A

Programs are organised around objects rather than logic and functions.

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

FP

A

Programs are organised around functions, avoiding shared state, mutable data, and side-effects (changing something somewhere - changing variable’s value, writing data to disk, enable a button in UI).

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

PP

A

Procedures, also known as routines, subroutines, or functions, simply contain a series of computational steps to be carried out.

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

What are the main concepts of OOPs?

A

Inheritance, Encapsulation, Abstraction, Polymorphism.

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

Inheritance

A

A process where one class acquires the properties of another.

19
Q

Encapsulation

A

Data can be accessed only with accessors.

20
Q

Abstraction

A

Only the essential details are displayed to the user / also identifying only the required characteristics of an object ignoring the irrelevant details.

21
Q

Local vs instance variable

A

Used / scope inside a code block (controller, method) vs belongs to an object, declared on a class level.

22
Q

final

A

Variable (value can’t be changed once assigned), method (can’t be overridden), class (can’t be extended)

23
Q

break vs continue

A

Continue loop only, jumps to the next iteration

24
Q

this() vs super()

A

Instance of a current vs parent class.

25
Q

Java String pool.

A

Collection of Strings which are stored in heap memory

26
Q

Static vs non-static

A

Cannot acmes non-static vs can access static without creating a class.

27
Q

What is constructor chaining in Java?

A

Internal state remains constant after creation. side effects free, thread safe. Final to do. Examples: String, , wrappers. i = I+ 1 creates a new object.

28
Q

Collection

A
29
Q

Array vs ArrayList

A

Primitives allowed, fixed size, one type, no generics vs (different) objects, dynamic size generics

30
Q

Map

A
31
Q

Set

A

Unordered, does not allow duplicates.

32
Q

List

A
33
Q

overriding ve overloading

A

runtime polymorphism vs methods with different signature

34
Q

Runtime polymorphism / dynamic dispatch

A

Call to overriden method is resolved at runtime.

35
Q

abstract c vs intreface

A

a can extend only one class, can have instance variables, any visibility can have a constructor vs can extend many, static variables, public only

36
Q

Can you override private / static method?

A

2 x no - method hidding.

37
Q

Marker interface

A

e.g. Serializable, Cloneable- an interface with no methods.

38
Q

association vs aggregation vs composition

A

Own lifecycle / no owner.

Own lifecycle, ownership and child object can not belong to another parent object.

If parent object deletes all child object will also be deleted.

39
Q

Checked vs unchecked exceptions

A

Checked at compile-time - must be caught or rethrown.

40
Q

final, finally, and finalize

A

restrictions on class, method, and variable

try / catch

finalize - called by the Garbage Collector

41
Q

throw vs throws

A

Throw vs declare that a methods may throw an exception.

42
Q

Ways to create a thread

A

Extend Tread, implement Runable, executors - Runnable, Callable (return value), Future (get value later), scheduled executors

43
Q

How to synchronize access to mutable, shared variables

A

synchronized, locks, semaphore, atomic variables and ConcurentMap