Tipos de datos y excepciones en Java
Jim White
Java Developer

| primitivo | Clase contenedora |
|---|---|
| byte | Byte |
| short | Short |
| int | Integer |
| long | Long |
| float | Float |
| double | Double |
| boolean | Boolean |
| char | Character |

Integer guarda un único valor primitivo int
import (veremos imports más adelante)Wrapper-type variable = primitive-value;Integer age = 12;
Double cost = 150250.55;
Float interest = 5.5f;
Character grade = 'A';
Boolean isActive = true;
null)Integer age = null;
Integer age = 12;
System.out.println(age); // Muestra 12
int x = age.intValue(); // a x se le asigna 12
double z = age.doubleValue(); // z es 12.0
String y = age.toString(); // a y se le asigna "12"
Integer teenAge = 16;
int smaller = age.compareTo(teenAge); // smaller es -1 porque 12 < 16
int x = Integer.sum(8,12); // x es 20
int y = Integer.remainderUnsigned(102, 10); // y es 2
int z = Integer.parseInt("123"); // z es 123;
boolean ans = Boolean.parseBoolean("false"); // ans es false
Ejemplos de campos estáticos en clases contenedoras
System.out.println(Integer.MAX_VALUE); // Valor máximo que puede tener un int
System.out.println(Integer.MIN_VALUE); // Valor mínimo que puede tener un int
2147483647
-2147483648
System.out.println(Boolean.TRUE); // Corresponde al valor primitivo true
System.out.println(Boolean.FALSE); // Corresponde al valor primitivo false
true
false
Ejemplos de campos estáticos en clases contenedoras
System.out.println(Character.SPACE_SEPARATOR); // Unicode del espacio normal como ' '
System.out.println(Character.LINE_SEPARATOR); // Unicode del salto de línea como '\n'
12
13
| Método de contenedora | Devuelve |
|---|---|
| Boolean.logicalAnd(boolean a, boolean b) | boolean |
| Boolean.logicalOr(boolean a, boolean b) | boolean |
| Boolean.parseBoolean(String s) | boolean |
| Character.getNumericValue(char ch) | valor int Unicode del char |
| Character.isDigit(char ch) | boolean |
| Character.isLowerCase(char ch) | boolean |
| Character.isWhitespace(char ch) | boolean |
| Double.parseDouble(String s) | double |
| Double.longValue() | el valor Double, redondeado hacia abajo, como Long |
int score = Integer.parseInt("8");
nullint herAge; // age es 0 por defecto
Integer hisAge = null;
if (hisAge != null) {
// haz algo cuando hisAge no esté establecido
}
Tipos de datos y excepciones en Java