Numerics&Operators Flashcards

1
Q

Cela cisla - defaultni typ
kolik je min, pokud znam max

A

0 … int
0l … long

-(max)-1
napr. pro 127 je to -128

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

byte - pamet, max

A

1 byte
127

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

short - pamet, max

A

2 bytes
32 767

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

int - pamet, max

A

4 bytes
2 147 000 000 2 miliardy

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

long - pamet, max

A

8 bytes
9 223 000 000 000 000 000 (9.223 * 10^3*6) 9 trilionu

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

Desetinna cisla - defaultni typ
Dva typy zapisu

A

0 … double
0f … float

123.456
1.23456E2

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

float - pamet

A

4 bytes

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

double - pamet

A

8 bytes

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

signed integer - jak je ulozen

A

dvojkovy doplnek:
pro zaporne cislo odecti 1 a prevrat vsechny bity

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

Automaticke castovani

A

Lze jen z mensiho typu na vetsi
Napr. int to long, float to long

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

char - pamet, default, rozsah

A

2 bytes
\U0000
0 - 64 535

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

char - druhy zapisu (4)

A

‘X’
unicode (hex) \uXXXX
ascii (octal) \XXX
escape sequences \r \n \t \f ' " \

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

auto-boxing
auto-unboxing

A

auto-boxing: zabaleni int do Integer
auto-unboxing: rozbaleni Integer na int
caste pouziti ubira na vykonu!

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

vlastnosti wrapper classes (2)
konstanty (2)

A

jsou signed
jsou immutable

MIN_VALUE, MAX_VALUE

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

Metody wrapper classes:
tvorba z primitivu
tvorba ze stringu
rozbaleni do primitivu

A

Integer.valueOf(5);
Integer.parseInt(“5”);
integer.intValue();

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

prevedeni primitivu na String

A

String.valueOf(5);

17
Q

Typ pouzivany tam, kde je vyzadovana desetinna presnost (finance)
Cim lze tu presnost zmatlat
Co pouzit misto toho

A

BigDecimal
new BigDecimal(x)
BigDecimal.valueOf(x)

18
Q

BigDecimal - jak se dela scitani, odecitani, nasobeni, deleni, modulo
Rozbaleni do double
Konstanta pro male cislo

A

bd.add(other); subtract / multiply / divide / remainder
- primitivni operatory nefunguji!!!
bd.doubleValue()
BigDecimal.ONE

19
Q

BigDecimal - nastaveni presnosti na dve des. mista s beznym zaokrouhlovanim

A

bd.setScale(2, RoundingMode.HALF_UP)

20
Q

Deleni - operator, kdy neni celociselne

A

/
pokud je delitel (to druhe) desetinny

21
Q

Co porovnava ==

A

hodnotu na stacku
tedy pro primitivy obsah
pro objekty reference

22
Q

Automatic casting u ciselnych primitivu: poradi

A

byte > short > int > long > float > double

23
Q

Typ vysledku u primitivnich cisel

A

pro typy mensi nez int je vysledek int (short + byte = int) - cisla v rovnici se prevedou pred operaci na int
pro ostatni je podle nejvetsiho typu (int + float = float)

24
Q

Co udela operace byte 127+5

A

Compilation error, type overflow

25
Q

Logicke operatory
short-circuit
long-circuit

A

Short-circuit: && || - prava strana se nemusi vyhodnotit
Long-circuit: & | ^(xor) - vyhodnoti se vse

26
Q

jak spocitam kosinus, arckosinus, sinus, tangens

A

Math.cos(x), acos, sin, tan

27
Q

jak spocitam e^x, x^y, odmocnina x

A

Math.exp(x)
Matc.pow(x, y)
Math.sqrt(x)

28
Q

funkce pro minimum, maximum, zaokrouhleni cisla

A

Math.min()
Math.max()
Math.round()

29
Q

Jak ziskam nahodne cislo, jaky bude jeho rozsah

A

Math.random() - bude mezi 0 vcetne a 1

30
Q

Serad priority operatoru
bit shift, scitani, nasobeni, relacni (>, <), post&prefix

A

post&prefix
nasobeni
scitani
bit shift
relacni operatory

31
Q

Serad prioridy operatoru
relacni, ternarni, rovnost, prirazeni, bitove &|^, logicke &|

A

relacni
rovnost
bitove
logicke
ternarni
prirazeni

32
Q

Logicke operace nad byte

A

I or, & and, ^ xor
dam v binarnim kodu pod sebe a scitam

33
Q

Byte shift - 3 druhy, jak funguji

A

> > signed right shift - posune a doplni zleva nuly nebo jednicky podle znamenka; x&raquo_space; 3 = x / 2^3
&laquo_space;signed left shift - posune a doplni zprava nuly; x &laquo_space;3 = x * 2^3
> unsigned right shift - posune a doplni zleva nuly (-> pro zaporna cisla nefunguje dobre)

34
Q

Zkracena forma pro x = x»>5

A

x&raquo_space;>= 5

35
Q

Jakeho typu je vysledek, pokud b je typu byte?
var result = +b;

A

int