|
1 | 1 | :java-package: src/org/j6toj8/languageenhancements |
2 | 2 | :section-java-package: ../../../{java-package} |
3 | 3 |
|
4 | | -=== Objetos Strings |
| 4 | +=== String objects |
5 | 5 |
|
6 | | -.Objetivo |
| 6 | +.Objective |
7 | 7 | ---- |
8 | 8 | Develop code that uses String objects in the switch statement, binary literals, and numeric literals, including underscores in literals. |
9 | | -- |
10 | | -Desenvolver código que utilize objetos String em instruções Switch, binários literais, e numéricos literais, incluindo underscore (_) em literais. |
11 | 9 | ---- |
12 | 10 |
|
13 | | -==== String em instruções Switch |
| 11 | +==== String in the switch statement |
14 | 12 |
|
15 | | -É esperado que o candidato saiba compreender e analisar o uso de Strings em instruções `switch`, como no seguinte exemplo. |
| 13 | +The candidate is expected to understand and analyze the use of Strings in `switch` statements, as in the following example. |
16 | 14 |
|
17 | 15 | [source,java,indent=0] |
18 | 16 | .{java-package}/stringinswitch/StringInSwitch_Complete.java |
19 | 17 | ---- |
20 | 18 | include::{section-java-package}/stringinswitch/StringInSwitch_Complete.java[tag=code] |
21 | 19 | ---- |
22 | 20 |
|
23 | | -Apesar da certificação ter foco nas atualizações trazidas pelo Java 7 e 8, é esperado que o candidato entenda também conceitos de versões anteriores do Java. Por isso, serão apresentadas algumas regras que talvez você já conheça sobre `switch`, mas utilizando `String` no `switch`. |
| 21 | +Although certification focuses on updates brought by Java 7 and 8, the candidate is expected to understand concepts from previous versions of Java as well. Therefore, some rules you may already know about `switch` will be presented but using `String` on the `switch`. |
24 | 22 |
|
25 | | -. Todo `case` deve ser único, não pode se repetir. |
| 23 | +. Every `case` must be unique, cannot be repeated. |
26 | 24 |
|
27 | | -. O `default` pode aparecer em qualquer posição no `switch`. |
| 25 | +. The `default` can appear anywhere on the `switch`. |
28 | 26 | + |
29 | 27 | .{java-package}/stringinswitch/StringInSwitch_Default.java |
30 | 28 | [source,java,indent=0] |
31 | 29 | ---- |
32 | 30 | include::{section-java-package}/stringinswitch/StringInSwitch_Default.java[tag=code] |
33 | 31 | ---- |
34 | 32 |
|
35 | | -. Tipos suportados em `switch`. |
36 | | -* int e Integer |
37 | | -* byte e Byte |
38 | | -* short e Short |
39 | | -* char e Character |
| 33 | +. Supported types in `switch`. |
| 34 | +* int and Integer |
| 35 | +* byte and Byte |
| 36 | +* short and Short |
| 37 | +* char and Character |
40 | 38 | * String |
41 | | -* valores de Enums |
| 39 | +* Enums values |
42 | 40 |
|
43 | | -. Tipos não suportados em `switch`. |
| 41 | +. Types not supported in `switch`. |
44 | 42 | + |
45 | 43 | .{java-package}/stringinswitch/StringInSwitch_Type.java |
46 | 44 | [source,java,indent=0] |
47 | 45 | ---- |
48 | 46 | include::{section-java-package}/stringinswitch/StringInSwitch_Type.java[tag=code] |
49 | 47 | ---- |
50 | 48 |
|
51 | | -. A execução se inicia em um `case` e somente para ao encontrar um `break`. |
| 49 | +. Execution starts in a `case` and only stops when it encounters a `break`. |
52 | 50 | + |
53 | 51 | .{java-package}/stringinswitch/StringInSwitch_Break.java |
54 | 52 | [source,java,indent=0] |
55 | 53 | ---- |
56 | 54 | include::{section-java-package}/stringinswitch/StringInSwitch_Break.java[tag=code] |
57 | 55 | ---- |
58 | 56 | + |
59 | | -.saída no console |
| 57 | +.console output |
60 | 58 | [source,console] |
61 | 59 | ---- |
62 | | -Janeiro |
63 | | -Não é um mês |
64 | | -Fevereiro |
| 60 | +January |
| 61 | +Not a month |
| 62 | +February |
65 | 63 | ---- |
66 | 64 | + |
67 | | -Nesse caso a execução inicia no `case "jan"`, passar pelo `default` e pelo `case "fev"` até parar no `break`, por isso as 3 strings aparecem no console. |
| 65 | +In this case, execution starts in `case "jan "`, goes through `default` and `case "Feb"` until it stops at `break`. So the 3 strings will appear in the console. |
68 | 66 |
|
69 | | -. Um `switch` vazio é válido, mesmo que não tenha utilidade. |
| 67 | +. An empty `switch` is valid even if it has no use. |
70 | 68 | + |
71 | 69 | .{java-package}/stringinswitch/StringInSwitch_Empty.java |
72 | 70 | [source,java,indent=0] |
73 | 71 | ---- |
74 | 72 | include::{section-java-package}/stringinswitch/StringInSwitch_Empty.java[tag=code] |
75 | 73 | ---- |
76 | 74 |
|
77 | | -. Todos os valores de `case` precisam ser constantes, ou seja, variáveis finais em tempo de compilação. Se o valor do `case` puder mudar em tempo de execução, o código não compila. |
| 75 | +. All `case` values must be constant, i.e., final variables at compile time. If the value of `case` can change at runtime, the code does not compile. |
78 | 76 | + |
79 | 77 | .{java-package}/stringinswitch/StringInSwitch_ConstantOnly.java |
80 | 78 | [source,java,indent=0] |
81 | 79 | ---- |
82 | 80 | include::{section-java-package}/stringinswitch/StringInSwitch_ConstantOnly.java[tag=code] |
83 | 81 | ---- |
84 | 82 |
|
85 | | -Pronto, essas são as regras de `switch`. Você provavelmente já conheçe algumas referentes à versões anteriores do Java, mas agora você as viu em `switch` que utilizam Strings. Isso não era possível antes do Java 7. |
| 83 | +These are the switch rules. You probably already know some about previous versions of Java, but now you have seen them in `switch` that use Strings. This was not possible before Java 7. |
86 | 84 |
|
87 | 85 | ==== Literais Binários e Numéricos, incluindo underscore( _ ) |
88 | 86 |
|
|
0 commit comments