|
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 | | -==== Literais Binários e Numéricos, incluindo underscore( _ ) |
| 85 | +==== Binary and numeric literals, including underscores in literals |
88 | 86 |
|
89 | | -É esperado que o candidato saiba compreender e analisar o uso de literais binários e numéricos, como no seguinte exemplo. |
| 87 | +The candidate is expected to understand and analyze the use of binary and numeric literals, as in the following example. |
90 | 88 |
|
91 | 89 | [source,java,indent=0] |
92 | 90 | .{java-package}/literals/Literals_Complete.java |
93 | 91 | ---- |
94 | 92 | include::{section-java-package}/literals/Literals_Complete.java[tag=code] |
95 | 93 | ---- |
96 | 94 |
|
97 | | -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 literais. |
| 95 | +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. So here are some rules you may already know about literals. |
98 | 96 |
|
99 | | -. No Java, _Literal_ é qualquer número escrito diretamente no código, como todos do exemplo acima. |
| 97 | +. In Java, _Literal_ is any number written directly in code, like the previous example. |
100 | 98 |
|
101 | | -. Por padrão, o Java interpreta literais como `int`. Ou seja, se não houver um sufixo no número para mudar seu tipo, ele é um `int`. |
| 99 | +. By default, Java interprets literals as `int`. That is, if there is no suffix in the number to change its type, it is an `int`. |
102 | 100 | + |
103 | 101 | .{java-package}/literals/Literals_Suffix.java |
104 | 102 | [source,java,indent=0] |
105 | 103 | ---- |
106 | 104 | include::{section-java-package}/literals/Literals_Suffix.java[tag=code] |
107 | 105 | ---- |
108 | 106 |
|
109 | | -. Por padrão, o Java interpreta literais como sendo decimais. Existem prefixos que mudam o sistema numérico do literal. |
| 107 | +. By default, Java interprets literals to be decimal. There are prefixes that change the numerical system of the literal. |
110 | 108 | + |
111 | 109 | .{java-package}/literals/Literals_Prefix.java |
112 | 110 | [source,java,indent=0] |
113 | 111 | ---- |
114 | 112 | include::{section-java-package}/literals/Literals_Prefix.java[tag=code] |
115 | 113 | ---- |
116 | 114 |
|
117 | | -. A partir do Java 7, é possível utilizar underscore (_) para separar visualmente um número. Isso não muda o valor do número, e serve apenas para tornar o código mais legível. |
| 115 | +. Starting with Java 7, you can use underscore (_) to visually separate a number. This does not change the value of the number, and only serves to make the code more readable. |
118 | 116 | + |
119 | 117 | .{java-package}/literals/Literals_Underscore.java |
120 | 118 | [source,java,indent=0] |
121 | 119 | ---- |
122 | 120 | include::{section-java-package}/literals/Literals_Underscore.java[tag=code] |
123 | 121 | ---- |
124 | 122 |
|
125 | | -.Referências |
| 123 | +.References |
126 | 124 | **** |
127 | 125 |
|
128 | | -.Strings em Switch |
129 | | -* Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 598). Wiley. Edição do Kindle. |
| 126 | +.String in the switch statement |
| 127 | +* Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 598). Wiley. Kindle Edition. |
130 | 128 | * https://docs.oracle.com/javase/8/docs/technotes/guides/language/strings-switch.html[Strings in switch Statements.] Java Documentation. |
131 | 129 | * https://dzone.com/articles/new-java-7-feature-string[New Java 7 Feature: String in Switch support.] DZone. |
132 | 130 |
|
133 | | -.Literais |
134 | | -* Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 597). Wiley. Edição do Kindle. |
| 131 | +.Literals |
| 132 | +* Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 597). Wiley. Kindle Edition. |
135 | 133 | * https://pt.wikibooks.org/wiki/Java/Literais[Java/Literais.] Wikibooks. |
136 | 134 |
|
137 | 135 | **** |
0 commit comments