Skip to content

Commit 3d91f17

Browse files
committed
feat(lang-enh): 🎸 String Objects, translated
Refers: #4
1 parent b901036 commit 3d91f17

File tree

7 files changed

+66
-68
lines changed

7 files changed

+66
-68
lines changed

book/02-language-enhancement/sections/01-string-in-switch-and-literals.asc

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,86 @@
11
:java-package: src/org/j6toj8/languageenhancements
22
:section-java-package: ../../../{java-package}
33

4-
=== Objetos Strings
4+
=== String objects
55

6-
.Objetivo
6+
.Objective
77
----
88
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.
119
----
1210

13-
==== String em instruções Switch
11+
==== String in the switch statement
1412

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.
1614

1715
[source,java,indent=0]
1816
.{java-package}/stringinswitch/StringInSwitch_Complete.java
1917
----
2018
include::{section-java-package}/stringinswitch/StringInSwitch_Complete.java[tag=code]
2119
----
2220

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`.
2422

25-
. Todo `case` deve ser único, não pode se repetir.
23+
. Every `case` must be unique, cannot be repeated.
2624

27-
. O `default` pode aparecer em qualquer posição no `switch`.
25+
. The `default` can appear anywhere on the `switch`.
2826
+
2927
.{java-package}/stringinswitch/StringInSwitch_Default.java
3028
[source,java,indent=0]
3129
----
3230
include::{section-java-package}/stringinswitch/StringInSwitch_Default.java[tag=code]
3331
----
3432

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
4038
* String
41-
* valores de Enums
39+
* Enums values
4240

43-
. Tipos não suportados em `switch`.
41+
. Types not supported in `switch`.
4442
+
4543
.{java-package}/stringinswitch/StringInSwitch_Type.java
4644
[source,java,indent=0]
4745
----
4846
include::{section-java-package}/stringinswitch/StringInSwitch_Type.java[tag=code]
4947
----
5048

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`.
5250
+
5351
.{java-package}/stringinswitch/StringInSwitch_Break.java
5452
[source,java,indent=0]
5553
----
5654
include::{section-java-package}/stringinswitch/StringInSwitch_Break.java[tag=code]
5755
----
5856
+
59-
.saída no console
57+
.console output
6058
[source,console]
6159
----
62-
Janeiro
63-
Não é um mês
64-
Fevereiro
60+
January
61+
Not a month
62+
February
6563
----
6664
+
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.
6866

69-
. Um `switch` vazio é válido, mesmo que não tenha utilidade.
67+
. An empty `switch` is valid even if it has no use.
7068
+
7169
.{java-package}/stringinswitch/StringInSwitch_Empty.java
7270
[source,java,indent=0]
7371
----
7472
include::{section-java-package}/stringinswitch/StringInSwitch_Empty.java[tag=code]
7573
----
7674

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.
7876
+
7977
.{java-package}/stringinswitch/StringInSwitch_ConstantOnly.java
8078
[source,java,indent=0]
8179
----
8280
include::{section-java-package}/stringinswitch/StringInSwitch_ConstantOnly.java[tag=code]
8381
----
8482

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.
8684

8785
==== Literais Binários e Numéricos, incluindo underscore( _ )
8886

src/org/j6toj8/languageenhancements/stringinswitch/StringInSwitch_Break.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ public class StringInSwitch_Break {
55
// tag::code[]
66
public static void main(String[] args) {
77

8-
String mes = "jan";
8+
String month = "jan";
99

10-
switch (mes) {
10+
switch (month) {
1111
case "jan":
12-
System.out.println("Janeiro");
12+
System.out.println("January");
1313
default:
14-
System.out.println("Não é um mês");
15-
case "fev":
16-
System.out.println("Fevereiro");
14+
System.out.println("Not a month");
15+
case "feb":
16+
System.out.println("February");
1717
break;
1818
case "mar":
19-
System.out.println("Março");
19+
System.out.println("March");
2020
break;
2121
}
2222
}

src/org/j6toj8/languageenhancements/stringinswitch/StringInSwitch_Complete.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ public class StringInSwitch_Complete {
55
// tag::code[]
66
public static void main(String[] args) {
77

8-
String mes = "jan";
8+
String month = "jan";
99

10-
switch (mes) {
10+
switch (month) {
1111
case "jan":
12-
System.out.println("Janeiro");
12+
System.out.println("January");
1313
break;
14-
case "fev":
15-
System.out.println("Fevereiro");
14+
case "feb":
15+
System.out.println("February");
1616
break;
1717
case "mar":
18-
System.out.println("Março");
18+
System.out.println("March");
1919
break;
2020
default:
2121
break;

src/org/j6toj8/languageenhancements/stringinswitch/StringInSwitch_ConstantOnly.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@
33
public class StringInSwitch_ConstantOnly {
44

55
// tag::code[]
6-
private static final String FEV = "fev";
6+
private static final String FEB = "feb";
77
private static String jan = "jan";
88

9-
public static void getNomeMes(final String mai) {
9+
public static void getMonthName(final String may) {
1010

11-
String mes = "jan";
11+
String month = "jan";
1212

1313
final String mar = "mar";
14-
String abr = "abr";
14+
String apr = "apr";
1515

16-
switch (mes) {
17-
case jan: // NÃO COMPILA - jan é um atributo comum, pode mudar em tempo de execução
18-
System.out.println("Janeiro");
16+
switch (month) {
17+
case jan: // WON'T COMPILE - jan is a common attribute, can change at runtime
18+
System.out.println("January");
1919
break;
20-
case FEV: // COMPILA - FEV é uma constante em tempo de compilação, seu valor nunca muda
21-
System.out.println("Fevereiro");
20+
case FEB: // COMPILES - FEB is a compilation time constant, its value never changes
21+
System.out.println("February");
2222
break;
23-
case mar: // COMPILA - mar é uma constante em tempo de compilação, seu valor nunca muda
24-
System.out.println("Março");
23+
case mar: // COMPILES - mar is a constant at compilation time, its value never changes
24+
System.out.println("March");
2525
break;
26-
case abr: // NÃO COMPILA - abr é uma variável comum, pode mudar em tempo de execução
27-
System.out.println("Março");
26+
case apr: // WON'T COMPILE - apr is a common variable, can change at runtime
27+
System.out.println("April");
2828
break;
29-
case mai: // NÃO COMPILA - mai é final, mas não é constante, pode mudar em tempo de execução
30-
System.out.println("Março");
29+
case may: // WON'T COMPILE - may is final but not constant, may change at runtime
30+
System.out.println("May");
3131
break;
3232
}
3333
}

src/org/j6toj8/languageenhancements/stringinswitch/StringInSwitch_Default.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ public class StringInSwitch_Default {
44

55
// tag::code[]
66
public static void main(String[] args) {
7-
8-
String mes = "jan";
9-
10-
switch (mes) {
7+
8+
String month = "jan";
9+
10+
switch (month) {
1111
case "jan":
12-
System.out.println("Janeiro");
12+
System.out.println("January");
1313
break;
14-
default: // COMPILA - O default pode estar em qualquer posição
14+
default: // COMPILES - `Default` can be in any position
1515
break;
16-
case "jan": // NÃO COMPILA - Já existe o case "jan"
17-
System.out.println("Janeiro2");
16+
case "jan": // WON'T COMPILE - There is already case "jan"
17+
System.out.println("January2");
1818
break;
1919
case "mar":
20-
System.out.println("Março");
20+
System.out.println("March");
2121
break;
2222
}
2323
}

src/org/j6toj8/languageenhancements/stringinswitch/StringInSwitch_Empty.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ public class StringInSwitch_Empty {
55
// tag::code[]
66
public static void main(String[] args) {
77

8-
String mes = "jan";
9-
switch (mes) {} // COMPILA - switch pode estar vazio, mesmo que seja inútil
8+
String month = "jan";
9+
switch (month) {} // COMPILES - switch may be empty even if it's useless
1010
}
1111
// end::code[]
1212
}

src/org/j6toj8/languageenhancements/stringinswitch/StringInSwitch_Type.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ public class StringInSwitch_Type {
55
// tag::code[]
66
public static void main(String[] args) {
77

8-
Long mes = 1L;
8+
Long month = 1L;
99

10-
switch (mes) { // NÃO COMPILA - Long não é um tipo suportado
10+
switch (month) { // WON'T COMPILE - Long is not a supported type.
1111
case 1L:
12-
System.out.println("Janeiro");
12+
System.out.println("January");
1313
break;
1414
case 2L:
15-
System.out.println("Fevereiro");
15+
System.out.println("February");
1616
break;
1717
default:
1818
break;

0 commit comments

Comments
 (0)