Syntax & common stuff Flashcards

1
Q

stary switch - syntax + chovani (break, default (3))

A

switch (x) {
case 1: case 2: logic(); logic();
case 3: logic(); break();
default: logic();
}
- po matchnute vetvi se aplikuji vsechny! pokud neni break
- default se pouzije, pokud se nematchne; neni povinna; nemusi byt posledni

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

switch novy (bez navratu) - syntax + chovani (break)

A

switch(x) {
case 1,2 -> logic();
case 3 -> { logic(); logic(); }
default -> logic();
}
break se nepise, je automaticky za kazdou vetvi

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

switch expression - syntax

A

int a = switch(x) {
case 1, 2: 10;
case 3: { logic(); yield logic(); }
default: yield 20;
}

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

while - syntax (2)

A

while (test) { action(); }
do { action(); } while(test)

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

for syntax:
vice promennych
vzdy true
foreach
foreach z matice

A

for (int i = 0, j=1; i<5 && j<10; i++, j++) {}
for (;;) {}
for (String str: list) { sout(str); }
for (char[] row: matrix) {}

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

label, break, continue

A

MyLabel:
break; - ukonci loop
break MyLabel; - vyskoci z celeho obsahu label
continue; - pokracuje dalsim cyklem
continue MyLabel; - skoci na label

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

Jak se vola interpreter
Co neni dovoleno (6)

A

jshell z cmd
nepovoleno: package, static, final, break, continue, return

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

jshell - otevri file.txt, skonci

A

/open file.txt
/exit

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

Co musi obsahovat casy switche

A

Musi pokryvat vsechny moznosti, nebo mit default

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

Jaka podminka plati pro razeni typu v casech
Priklad CharSequence, String

A

Nesmi byt superclass pred jeji subclass
case CharSequence c
case String s
je spatne, protoze String je potomek CharSequence

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

String.isEmpty()

A

prazdny string nebo whitespaces only

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

StringBuilder vs StringBuffer

A

StringBuffer je thread save, StringBuilder ne
StringBuilder je rychlejsi, pokud potrebuju 1 vlakno

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

Co se stane?
switch (x) {
case Character c : action();
case String s : action();
default : action();
}

A

Compilation error
Protoze telo druheho casu ma s i c
Chyba napr. i pro Character+Long
Lze vyresit breakama

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

void method() {
int x;
sout(x);
}

co se stane?

A

compilation error
lokalni promenna se musi pred pouzitim inicializovat

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

Smi cases obsahovat enum?

A

Jejich values (int) ano, ale samotny enum ne

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