Chapter 6 Flashcards
What is the syntax of the switch statement?
switch ( expression) { case value1: statement-list1; case value2: statement-list2; ... }
What happens if you don’t put break at the end of a switch statement-list?
Without break; every statement-list after it inside the switch will be executed.
What does the default statement in a switch?
Default indicates a statement-list to be executed in the circumstance in which no other cases was true.
What primitive value cannot be used as a condition in a switch statement?
A floating point value.
What is the syntax of a conditional operator? How does it work?
condition ? expression1 : expression2;
If the condition is fulfilled, the first expression is executed, otherwise the second one is.
What is the difference between a conditional operator and a conditional statement?
A conditional operator is a ternary operator that evaluates a condition and returns one of two possible values (true or false).
A conditional statement is a category of statements that allow conditions to be evaluated and the appropriate statements executed as a result.
What is the syntax of a do statement? What’s the difference with using a while?
do { statement-list; ] while (condition);
Compared to a while, the do statement executes the statement-list at least one and will then execute it for each time the condition is true.
What is the syntax of a for statement?
for (initialization; condition; increment)
statement;
The initialization is executed only once before the start of the loop, the condition is evaluated every time, and increment happens at the end of the loop.
Although having the same functionality, in what circumstance would for be preferred to a while and vice versa?
A for is used when the number of loops is known, on the other a while loop is built in cases in which the length of a loop, aka the number of loops that it will do is unknown.
Can the header of a for statement be shortened?
Yes, every formal parameter of for can be left blank.
What are the common methods used for graphic transformations in JavaFX?
Translation:
setTranslateX(100);
setTranslateY(…);
Scaling:
setScaleX(0.7);
setScaleY(0.5);
Rotation:
setRotate(40); will be clockwise
setRotate(-40); will be anticlockwise.
Shearing: is done by creating a Shear object. Ex: imgView.getTransforms() .add(new Shear(0.4, 0.2));