(→Tipos primitivos) |
|||
Line 9: | Line 9: | ||
Os tipos primitivos são os que figuram na seguinte tabela. | Os tipos primitivos são os que figuram na seguinte tabela. | ||
− | {| style="border-style: solid; border-width: 2px; width: 90%;" | + | {| style="border-style: solid; border-width: 2px; width: 90%;" cellspacing=3 |
! width="20%" | Tipo | ! width="20%" | Tipo | ||
! width="20%" | Dimensão (bits) | ! width="20%" | Dimensão (bits) | ||
Line 15: | Line 15: | ||
! width="20%" | Máximo | ! width="20%" | Máximo | ||
|- | |- | ||
− | | boolean | + | ! bgcolor="wheat" | boolean |
− | | - | + | ! bgcolor="wheat" | - |
− | | - | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | - |
− | | - | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | - |
|- | |- | ||
− | | char | + | ! bgcolor="wheat" | char |
− | | 16 | + | ! bgcolor="wheat" | 16 |
− | | Unicode 0 | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | Unicode 0 |
− | | Unicode 2<sup>16</sup>-1 | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | Unicode 2<sup>16</sup>-1 |
|- | |- | ||
− | | byte | + | ! bgcolor="wheat" | byte |
− | | 8 | + | ! bgcolor="wheat" | 8 |
− | | -128 | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | -128 |
− | | +127 | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | +127 |
|- | |- | ||
− | | short | + | ! bgcolor="wheat" | short |
− | | 16 | + | ! bgcolor="wheat" | 16 |
− | | -2<sup>15</sup> | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | -2<sup>15</sup> |
− | | +2<sup>15</sup>-1 | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | +2<sup>15</sup>-1 |
|- | |- | ||
− | | int | + | ! bgcolor="wheat" | int |
− | | 32 | + | ! bgcolor="wheat" | 32 |
− | | -2<sup>31</sup> | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | -2<sup>31</sup> |
− | | +2<sup>31</sup>-1 | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | +2<sup>31</sup>-1 |
|- | |- | ||
− | | long | + | ! bgcolor="wheat" | long |
− | | 64 | + | ! bgcolor="wheat" | 64 |
− | | -2<sup>63</sup> | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | -2<sup>63</sup> |
− | | +2<sup>63</sup>-1 | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | +2<sup>63</sup>-1 |
|- | |- | ||
− | | float | + | ! bgcolor="wheat" | float |
− | | 32 | + | ! bgcolor="wheat" | 32 |
− | | IEEE 754 | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | [[wikipedia:IEEE floating-point standard|IEEE 754]] [http://www.l2f.inesc-id.pt/~david/ist/docencia/IEEE%20standard%20for%20binary%20floating-point%20arithmetic%20(IEEE%20754).pdf] |
− | | IEEE 754 | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | [[wikipedia:IEEE floating-point standard|IEEE 754]] |
|- | |- | ||
− | | double | + | ! bgcolor="wheat" | double |
− | | 64 | + | ! bgcolor="wheat" | 64 |
− | | IEEE 754 | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | [[wikipedia:IEEE floating-point standard|IEEE 754]] |
− | | IEEE 754 | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | [[wikipedia:IEEE floating-point standard|IEEE 754]] |
|- | |- | ||
− | | void | + | ! bgcolor="wheat" | void |
− | | - | + | ! bgcolor="wheat" | - |
− | | - | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | - |
− | | - | + | ! style="padding-left: 10px;" bgcolor="wheat" align="left" | - |
|} | |} | ||
− | |||
=== ''Wrappers'' === | === ''Wrappers'' === |
Embora fosse concebÃvel definir classes para todos os tipos de dados a utilizar por um programa em Java, inclusivamente para os tipos básicos, tal conduziria a ineficiência durante a execução.
Para obviar ao problema, no Java utiliza-se um sistema de tipos hÃbrido: são definidos tipos básicos para cobrir entidades atómicas. Estes tipos semelhantes aos do C e do C++ (embora com algumas restrições, como, por exemplo, as dimensões) permitem tratar eficientemenmte entidades como inteiros ou caracteres.
No entanto, para permitir alguma uniformidade no tratamento dos tipos, a linguagem também define as classes correspondentes aos tipos primitivos e, a partir da versão 1.5, permite a auto-conversão de tipos primitivos para essas classes. As classes correspondentes aos tipos primitivos são designadas wrappers ("envoltórios") e o processo de conversão implÃcita é designado por auto-boxing ("auto-empacotamento").
Os tipos primitivos são os que figuram na seguinte tabela.
Tipo | Dimensão (bits) | MÃnimo | Máximo |
---|---|---|---|
boolean | - | - | - |
char | 16 | Unicode 0 | Unicode 216-1 |
byte | 8 | -128 | +127 |
short | 16 | -215 | +215-1 |
int | 32 | -231 | +231-1 |
long | 64 | -263 | +263-1 |
float | 32 | IEEE 754 [1] | IEEE 754 |
double | 64 | IEEE 754 | IEEE 754 |
void | - | - | - |
As classes correspondentes aos tipos primitivos figuram na seguinte tabela.