Skip to content

Commit

Permalink
feat(lang-enh): 🎸 String in the switch statement, translated
Browse files Browse the repository at this point in the history
Refers: #4
  • Loading branch information
rcmoutinho committed Sep 10, 2019
1 parent 3d91f17 commit 5a6ef35
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,54 +82,54 @@ include::{section-java-package}/stringinswitch/StringInSwitch_ConstantOnly.java[

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.

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

É esperado que o candidato saiba compreender e analisar o uso de literais binários e numéricos, como no seguinte exemplo.
The candidate is expected to understand and analyze the use of binary and numeric literals, as in the following example.

[source,java,indent=0]
.{java-package}/literals/Literals_Complete.java
----
include::{section-java-package}/literals/Literals_Complete.java[tag=code]
----

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

. No Java, _Literal_ é qualquer número escrito diretamente no código, como todos do exemplo acima.
. In Java, _Literal_ is any number written directly in code, like the previous example.

. 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`.
. 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`.
+
.{java-package}/literals/Literals_Suffix.java
[source,java,indent=0]
----
include::{section-java-package}/literals/Literals_Suffix.java[tag=code]
----

. Por padrão, o Java interpreta literais como sendo decimais. Existem prefixos que mudam o sistema numérico do literal.
. By default, Java interprets literals to be decimal. There are prefixes that change the numerical system of the literal.
+
.{java-package}/literals/Literals_Prefix.java
[source,java,indent=0]
----
include::{section-java-package}/literals/Literals_Prefix.java[tag=code]
----

. 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.
. 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.
+
.{java-package}/literals/Literals_Underscore.java
[source,java,indent=0]
----
include::{section-java-package}/literals/Literals_Underscore.java[tag=code]
----

.Referências
.References
****
.Strings em Switch
* Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 598). Wiley. Edição do Kindle.
.String in the switch statement
* Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 598). Wiley. Kindle Edition.
* https://docs.oracle.com/javase/8/docs/technotes/guides/language/strings-switch.html[Strings in switch Statements.] Java Documentation.
* https://dzone.com/articles/new-java-7-feature-string[New Java 7 Feature: String in Switch support.] DZone.
.Literais
* Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 597). Wiley. Edição do Kindle.
.Literals
* Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 597). Wiley. Kindle Edition.
* https://pt.wikibooks.org/wiki/Java/Literais[Java/Literais.] Wikibooks.
****
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ public static void main(String[] args) {

// tag::code[]
int i1 = 1; // int
int i2 = 1_000_000; // int com underscore
int i2 = 1_000_000; // int with underscore
int i3 = 0567; // octadecimal
int i4 = 0xFA1; // hexadecimal
int i5 = 0b0101; // binário
int i5 = 0b0101; // binary

long l1 = 1L; // long com L
long l2 = 1l; // long com l
long l3 = 12_345_6_7890_123456_789L; // long com underscore
long l4 = 0xFA1L; // long hexadecimal
long l1 = 1L; // long with L
long l2 = 1l; // long with l
long l3 = 12_345_6_7890_123456_789L; // long with underscore
long l4 = 0xFA1L; // hexadecimal long

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

float f1 = 1.00F; // float
// end::code[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ public class Literals_Prefix {
public static void main(String[] args) {

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

long l1 = 0xABCL; // long também pode ser hexadecimal - começa com 0x e termina com L
long l1 = 0xABCL; // long can also be hexadecimal - starts with 0x and ends with L
// end::code[]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ public class Literals_Suffix {
public static void main(String[] args) {

// tag::code[]
int i1 = 1; // por padrão é int
long l1 = 1L; // com um L no final, é um long
int i1 = 1; // by default is int
long l1 = 1L; // with an L in the end, it's a long
double d1 = 1.0;
double d2 = 1.0D; // com ou sem D no final, se tiver casa decimal é um double por padrão
float f1 = 1.0F; // com um F no final, é um float
double d2 = 1.0D; // with or without a D in the end, if you have a decimal place is a double by default
float f1 = 1.0F; // with an F at the end, it's a float
// end::code[]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ public class Literals_Underscore {
public static void main(String[] args) {

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

long l1 = 12_345_6_7890_123456_789L; // long with underscore
long l2 = 12_345_6_789_L; // NOT COMPILING - cannot be next to a type marker

double d1 = 100_000.01; // double with underscore
double d2 = 10_.01; // NOT COMPILING - underscore must be between numbers
double d3 = 10._01; // NOT COMPILING - underscore must be between numbers
// end::code[]
}
}

0 comments on commit 5a6ef35

Please sign in to comment.