Skip to content

Commit 5a6ef35

Browse files
committed
feat(lang-enh): 🎸 String in the switch statement, translated
Refers: #4
1 parent 3d91f17 commit 5a6ef35

File tree

5 files changed

+43
-43
lines changed

5 files changed

+43
-43
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,54 +82,54 @@ include::{section-java-package}/stringinswitch/StringInSwitch_ConstantOnly.java[
8282

8383
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.
8484

85-
==== Literais Binários e Numéricos, incluindo underscore( _ )
85+
==== Binary and numeric literals, including underscores in literals
8686

87-
É 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.
8888

8989
[source,java,indent=0]
9090
.{java-package}/literals/Literals_Complete.java
9191
----
9292
include::{section-java-package}/literals/Literals_Complete.java[tag=code]
9393
----
9494

95-
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.
9696

97-
. 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.
9898

99-
. 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`.
100100
+
101101
.{java-package}/literals/Literals_Suffix.java
102102
[source,java,indent=0]
103103
----
104104
include::{section-java-package}/literals/Literals_Suffix.java[tag=code]
105105
----
106106

107-
. 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.
108108
+
109109
.{java-package}/literals/Literals_Prefix.java
110110
[source,java,indent=0]
111111
----
112112
include::{section-java-package}/literals/Literals_Prefix.java[tag=code]
113113
----
114114

115-
. 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.
116116
+
117117
.{java-package}/literals/Literals_Underscore.java
118118
[source,java,indent=0]
119119
----
120120
include::{section-java-package}/literals/Literals_Underscore.java[tag=code]
121121
----
122122

123-
.Referências
123+
.References
124124
****
125125
126-
.Strings em Switch
127-
* 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.
128128
* https://docs.oracle.com/javase/8/docs/technotes/guides/language/strings-switch.html[Strings in switch Statements.] Java Documentation.
129129
* https://dzone.com/articles/new-java-7-feature-string[New Java 7 Feature: String in Switch support.] DZone.
130130
131-
.Literais
132-
* 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.
133133
* https://pt.wikibooks.org/wiki/Java/Literais[Java/Literais.] Wikibooks.
134134
135135
****

‎src/org/j6toj8/languageenhancements/literals/Literals_Complete.java‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ public static void main(String[] args) {
66

77
// tag::code[]
88
int i1 = 1; // int
9-
int i2 = 1_000_000; // int com underscore
9+
int i2 = 1_000_000; // int with underscore
1010
int i3 = 0567; // octadecimal
1111
int i4 = 0xFA1; // hexadecimal
12-
int i5 = 0b0101; // binário
12+
int i5 = 0b0101; // binary
1313

14-
long l1 = 1L; // long com L
15-
long l2 = 1l; // long com l
16-
long l3 = 12_345_6_7890_123456_789L; // long com underscore
17-
long l4 = 0xFA1L; // long hexadecimal
14+
long l1 = 1L; // long with L
15+
long l2 = 1l; // long with l
16+
long l3 = 12_345_6_7890_123456_789L; // long with underscore
17+
long l4 = 0xFA1L; // hexadecimal long
1818

1919
double d1 = 1.00; // double
20-
double d2 = 100_000.01; // double com underscore
21-
double d3 = 1D; // double com D
22-
double d4 = 3.1E2; // notação científica = 3.1 * 10^2 = 3.1 * 100 = 310.0
20+
double d2 = 100_000.01; // double with underscore
21+
double d3 = 1D; // double with D
22+
double d4 = 3.1E2; // cientific notation = 3.1 * 10^2 = 3.1 * 100 = 310.0
2323

2424
float f1 = 1.00F; // float
2525
// end::code[]

‎src/org/j6toj8/languageenhancements/literals/Literals_Prefix.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ public class Literals_Prefix {
55
public static void main(String[] args) {
66

77
// tag::code[]
8-
int i1 = 0567; // octadecimal - base 8 - começa com 0
9-
int i2 = 0xFA1; // hexadecimal - base 16 - começa com 0x
10-
int i3 = 0b0101; // binário - base 2 - começa com 0b
8+
int i1 = 0567; // octadecimal - base 8 - starts with 0
9+
int i2 = 0xFA1; // hexadecimal - base 16 - starts with 0x
10+
int i3 = 0b0101; // binary - base 2 - starts with 0b
1111

12-
long l1 = 0xABCL; // long também pode ser hexadecimal - começa com 0x e termina com L
12+
long l1 = 0xABCL; // long can also be hexadecimal - starts with 0x and ends with L
1313
// end::code[]
1414
}
1515
}

‎src/org/j6toj8/languageenhancements/literals/Literals_Suffix.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ public class Literals_Suffix {
55
public static void main(String[] args) {
66

77
// tag::code[]
8-
int i1 = 1; // por padrão é int
9-
long l1 = 1L; // com um L no final, é um long
8+
int i1 = 1; // by default is int
9+
long l1 = 1L; // with an L in the end, it's a long
1010
double d1 = 1.0;
11-
double d2 = 1.0D; // com ou sem D no final, se tiver casa decimal é um double por padrão
12-
float f1 = 1.0F; // com um F no final, é um float
11+
double d2 = 1.0D; // with or without a D in the end, if you have a decimal place is a double by default
12+
float f1 = 1.0F; // with an F at the end, it's a float
1313
// end::code[]
1414
}
1515
}

‎src/org/j6toj8/languageenhancements/literals/Literals_Underscore.java‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ public class Literals_Underscore {
55
public static void main(String[] args) {
66

77
// tag::code[]
8-
int i1 = 1_000_000; // int com underscore - é o mesmo que escrever 1000000
9-
int i2 = 10_00_00_0; // o underscore pode estar em qualquer posição entre 2 números
10-
int i3 = _1000; // NÃO COMPILA - o underscore não pode estar no início
11-
int i4 = 1000_; // NÃO COMPILA - o underscore não pode estar no final
12-
int i5 = 1___000; // COMPILA - vários underscore é permitido, desde que estejam entre 2 números
13-
int i6 = 0x_100; // NÃO COMPILA - entre marcador de base não é permitido
14-
int i7 = 0xF_F; // COMPILA - apesar de serem letras, representam valores numéricos dessa base
15-
16-
long l1 = 12_345_6_7890_123456_789L; // long com underscore
17-
long l2 = 12_345_6_789_L; // NÃO COMPILA - não pode ficar ao lado de um marcador de tipo
18-
19-
double d1 = 100_000.01; // double com underscore
20-
double d2 = 10_.01; // NÃO COMPILA - o underscore deve estar entre números
21-
double d3 = 10._01; // NÃO COMPILA - o underscore deve estar entre números
8+
int i1 = 1_000_000; // int with underscore - is the same as writing 1000000
9+
int i2 = 10_00_00_0; // underscore can be anywhere between 2 numbers
10+
int i3 = _1000; // NOT COMPILING - underscore can't be at the beginning
11+
int 14 = 1000_; // NOT COMPILING - underscore can't be at the end
12+
int i5 = 1___000; // COMPILES - Multiple underscore is allowed as long as they are between 2 numbers
13+
int i6 = 0x_100; // NOT COMPILING - between base marker is not allowed
14+
int i7 = 0xF_F; // COMPILES - Although they are letters, they represent numerical values of this base
15+
16+
long l1 = 12_345_6_7890_123456_789L; // long with underscore
17+
long l2 = 12_345_6_789_L; // NOT COMPILING - cannot be next to a type marker
18+
19+
double d1 = 100_000.01; // double with underscore
20+
double d2 = 10_.01; // NOT COMPILING - underscore must be between numbers
21+
double d3 = 10._01; // NOT COMPILING - underscore must be between numbers
2222
// end::code[]
2323
}
2424
}

0 commit comments

Comments
 (0)