Actualizado el 23 de Abril del 2018 (Publicado el 14 de Enero del 2017)
1.307 visualizaciones desde el 14 de Enero del 2017
487,2 KB
152 paginas
ÍNDICE
Índice
1. Primer programa en Java
1.1. Cuestiones sobre nomenclatura . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2. Compilación y ejecución del programa con CLDC . . . . . . . . . . . . . . . .
2. Tipos de datos, variables y matrices
2.1. Tipos simples
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2. Literales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3. Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4. Conversión de tipos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5. Vectores y matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5.1. Vectores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5.2. Matrices multidimensionales . . . . . . . . . . . . . . . . . . . . . . . .
2.5.3. Sintaxis alternativa para la declaración de matrices
. . . . . . . . . . .
2.6. Punteros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3. Operadores
3.1. Tabla de precedencia de operadores: . . . . . . . . . . . . . . . . . . . . . . . .
4. Sentencias de control
4.1. Sentencias de selección . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2. Sentencias de iteración . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3. Tratamiento de excepciones . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4. Sentencias de salto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.1. break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.2. continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.3.
5. Clases
5.1. Fundamentos
5.2. Declaración de objetos
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.1.1. Forma general de una clase . . . . . . . . . . . . . . . . . . . . . . . . .
5.1.2. Una clase sencilla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.2.1. Operador new . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.3. Asignación de variables referencia a objeto . . . . . . . . . . . . . . . . . . . .
5.4. Métodos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
5.5. Constructores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . .
5.6. this . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.7. Recogida de basura . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.8. Ejemplo de clase (Clase Stack) . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.5.1. Constructores con parámetros
5.4.1. Métodos con parámetros
6. Métodos y clases
6.1.1. Sobrecarga con conversión automática de tipo
6.1.2. Sobrecarga de constructores
6.1. Sobrecarga de métodos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
6.2. Objetos como parámetros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.3. Paso de argumentos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.4. Control de acceso . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.5. Especificador static . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.6. Especificador final con variables . . . . . . . . . . . . . . . . . . . . . . . . . .
6.7. Clase String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.8. Argumentos de la línea de ordenes . . . . . . . . . . . . . . . . . . . . . . . . .
0-0
1
1
1
4
4
5
6
6
8
8
8
9
9
9
10
11
11
11
12
12
12
13
13
14
14
14
14
15
15
17
17
19
20
21
22
22
23
25
25
27
28
30
32
33
34
35
36
36
ÍNDICE
0-1
7. Herencia
7.1. Fundamentos
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
38
38
7.1.1. Una variable de la superclase puede referenciar a un objeto de la subclase 40
41
43
44
45
46
48
50
7.2. Uso de super . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.3. Orden de ejecución de constructores . . . . . . . . . . . . . . . . . . . . . . . .
7.4. Sobreescritura de métodos (Overriding) . . . . . . . . . . . . . . . . . . . . . .
7.5. Selección de método dinámica . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.5.1. Aplicación de sobreescritura de métodos . . . . . . . . . . . . . . . . . .
7.6. Clases abstractas
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.7. Utilización de final con la herencia . . . . . . . . . . . . . . . . . . . . . . . . .
8. Paquetes e Interfaces
8.1. Paquetes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.1.1. Definición de un paquete . . . . . . . . . . . . . . . . . . . . . . . . . .
8.1.2. La variable de entorno CLASSPATH . . . . . . . . . . . . . . . . . . . .
8.1.3. Ejemplo de paquete: P25/MyPack . . . . . . . . . . . . . . . . . . . .
8.2. Protección de acceso . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.2.1. Tipos de acceso a miembros de una clase . . . . . . . . . . . . . . . . .
8.2.2. Tipos de acceso para una clase . . . . . . . . . . . . . . . . . . . . . . .
Importar paquetes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Interfaces
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.4.1. Definición de una interfaz . . . . . . . . . . . . . . . . . . . . . . . . . .
8.4.2.
. . . . . . . . . . . . . . . . . . . . . .
8.4.3. Acceso a implementaciones a través de referencias de la interfaz . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
8.4.4.
Implementación parcial
. . . . . . . . . . . . . . . . . . . . . . . . . . .
8.4.5. Variables en interfaces
8.4.6. Las interfaces se pueden extender
. . . . . . . . . . . . . . . . . . . . .
Implementación de una interfaz
8.3.
8.4.
9. Gestión de excepciones
9.1. Fundamentos
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.2. Tipos de excepción . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.3. Excepciones no capturadas . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.4. try y catch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.4.1. Descripción de una excepción . . . . . . . . . . . . . . . . . . . . . . . .
9.5. Cláusula catch múltiple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.6. Sentencias try anidadas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.7. Lanzar excepciones explícitamente: throw . . . . . . . . . . . . . . . . . . . . .
9.8. Sentencia throws
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.9. Sentencia finally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.10. Subclases de excepciones propias . . . . . . . . . . . . . . . . . . . . . . . . . .
51
51
51
51
53
54
54
54
57
59
59
60
61
61
62
63
65
65
66
68
70
71
71
74
76
77
79
80
10.Programación Multihilo (Multihebra)
10.1. Hebras en CLDC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.2. El hilo principal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.3. Creación de un hilo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.3.1. Implementación del interfaz Runnable . . . . . . . . . . . . . . . . . . .
10.3.2. Extensión de la clase Thread . . . . . . . . . . . . . . . . . . . . . . . .
10.3.3. Elección de una de las dos opciones . . . . . . . . . . . . . . . . . . . .
10.4. Creación de múltiples hilos . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.5. Utilización de isAlive() y join() . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.6. Prioridades de los hilos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.7. Sincronización . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . .
10.7.1. Uso de métodos sincronizados
10.7.2. Sentencia synchronized . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.8. Comunicación entre hilos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
82
82
83
84
84
86
87
88
90
93
95
95
98
99
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
10.8.1. Interbloqueos
ÍNDICE
0-2
10.9. Suspender, reanudar y terminar hilos
. . . . . . . . . . . . . . . . . . . . . . . 107
11.Connected Limited Device Configuration: CLDC
110
11.1. ¿Qué son las configuraciones en J2ME? . . . . . . . . . . . . . . . . . . . . . . 110
11.2. La configuración CLDC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
11.2.1. La máquina virtual Java de CLDC . . . . . . . . . . . . . . . . . . . . . 110
11.3. La librería de clases de CLDC . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
11.3.1. Paquete java.lang . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
11.3.2. Paquete java.util
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
11.4. Entrada/salida en Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
11.4.1. Introducción . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
11.4.2. Clases de CLDC para E/S de datos: Paquete java.io . . . . . . . . . . . 132
11.4.3. Clases para flujos de bytes . . . . . . . . . . . . . . . . . . . . . . . . . 134
11.4.4. Clases para flujos de caracteres . . . . . . . . . . . . . . . . . . . . . . . 145
. . . . . . . . . . . . . . . . . . . . . . . . . . . 148
11.5. Paquete javax.microedition.io
1 PRIMER PROGRAMA EN JAVA
1
1. Primer programa en Java
P1/HolaMundo.java
/* Es
Comentarios de: transjava (0)
No hay comentarios