Publicado el 14 de Enero del 2017
891 visualizaciones desde el 14 de Enero del 2017
360,7 KB
152 paginas
INDICE
Indice
1. Primer programa en Java
1.1. Cuestiones sobre nomenclatura . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2. Compilacion y ejecucion del programa con CLDC . . . . . . . . . . . . . . . .
2. Tipos de datos, variables y matrices
2.1. Tipos simples
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2. Literales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3. Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4. Conversion de tipos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5. Vectores y matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5.1. Vectores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5.2. Matrices multidimensionales . . . . . . . . . . . . . . . . . . . . . . . .
2.5.3. Sintaxis alternativa para la declaracion de matrices
. . . . . . . . . . .
2.6. Punteros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3. Operadores
3.1. Tabla de precedencia de operadores: . . . . . . . . . . . . . . . . . . . . . . . .
4. Sentencias de control
4.1. Sentencias de seleccion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2. Sentencias de iteracion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3. Tratamiento de excepciones . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4. Sentencias de salto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.1. break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.2. continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.3.
return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5. Clases
5.1. Fundamentos
5.2. Declaracion de objetos
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.1.1. Forma general de una clase . . . . . . . . . . . . . . . . . . . . . . . . .
5.1.2. Una clase sencilla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.2.1. Operador new . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.3. Asignacion de variables referencia a objeto . . . . . . . . . . . . . . . . . . . .
5.4. Metodos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
5.5. Constructores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . .
5.6. this . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.7. Recogida de basura . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.8. Ejemplo de clase (Clase Stack): P7/TestStack.java . . . . . . . . . . . . . . . .
5.5.1. Constructores con parametros
5.4.1. Metodos con parametros
6. Metodos y clases
6.1.1. Sobrecarga con conversion automatica de tipo
6.1.2. Sobrecarga de constructores
6.1. Sobrecarga de metodos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
6.2. Objetos como parametros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.3. Paso de argumentos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.4. Control de acceso . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.5. Especicador static . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.6. Especicador nal con variables . . . . . . . . . . . . . . . . . . . . . . . . . .
6.7. Clase String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.8. Argumentos de la lnea 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
INDICE
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 ejecucion de constructores . . . . . . . . . . . . . . . . . . . . . . . .
7.4. Sobreescritura de metodos (Overriding) . . . . . . . . . . . . . . . . . . . . . .
7.5. Seleccion de metodo dinamica . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.5.1. Aplicacion de sobreescritura de metodos . . . . . . . . . . . . . . . . . .
7.6. Clases abstractas
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.7. Utilizacion de nal con la herencia . . . . . . . . . . . . . . . . . . . . . . . . .
8. Paquetes e Interfaces
8.1. Paquetes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.1.1. Denicion de un paquete . . . . . . . . . . . . . . . . . . . . . . . . . .
8.1.2. La variable de entorno CLASSPATH . . . . . . . . . . . . . . . . . . . .
8.1.3. Ejemplo de paquete: P25/MyPack . . . . . . . . . . . . . . . . . . . .
8.2. Proteccion de acceso . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.2.1. Tipos de acceso a miembros de una clase . . . . . . . . . . . . . . . . .
8.2.2. Tipos de acceso para una clase . . . . . . . . . . . . . . . . . . . . . . .
8.3. Importar paquetes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.4. Interfaces
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.4.1. Denicion de una interfaz . . . . . . . . . . . . . . . . . . . . . . . . . .
8.4.2.
. . . . . . . . . . . . . . . . . . . . . .
8.4.3. Acceso a implementaciones a traves de referencias de la interfaz . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
8.4.4.
Implementacion parcial
. . . . . . . . . . . . . . . . . . . . . . . . . . .
8.4.5. Variables en interfaces
8.4.6. Las interfaces se pueden extender
. . . . . . . . . . . . . . . . . . . . .
Implementacion de una interfaz
9. Gestion de excepciones
9.1. Fundamentos
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.2. Tipos de excepcion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.3. Excepciones no capturadas . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.4. try y catch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.4.1. Descripcion de una excepcion . . . . . . . . . . . . . . . . . . . . . . . .
9.5. Clausula catch multiple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.6. Sentencias try anidadas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.7. Lanzar excepciones explcitamente: throw . . . . . . . . . . . . . . . . . . . . .
9.8. Sentencia throws
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.9. Sentencia nally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
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.Programacion Multihilo (Multihebra)
10.1. Hebras en CLDC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.2. El hilo principal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.3. Creacion de un hilo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.3.1. Implementacion del interfaz Runnable . . . . . . . . . . . . . . . . . . .
10.3.2. Extension de la clase Thread . . . . . . . . . . . . . . . . . . . . . . . .
10.3.3. Eleccion de una de las dos opciones . . . . . . . . . . . . . . . . . . . .
10.4. Creacion de multiples hilos . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.5. Utilizacion de isAlive() y join() . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.6. Prioridades de los hilos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.7. Sincronizacion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . .
10.7.1. Uso de metodos sincronizados
10.7.2. Sentencia synchronized . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.8. Comunicacion entre hilos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
82
82
83
84
84
86
87
88
90
93
95
95
98
99
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
10.8.1. Interbloqueos
INDICE
0-2
10.9. Suspender, reanudar y terminar hilos
. . . . . . . . . . . . . . . . . . . . . . . 107
11.Connected Limited Device Conguration: CLDC
110
11.1. >Que son las conguraciones en J2ME? . . . . . . . . . . . . . . . . . . . . . . 110
11.2. La conguracion CLDC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
11.2.1. La maquina virtual Java de CLDC . . . . . . . . . . . . . . . . . . . . . 110
11.3. La librera 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. Introduccion . . . . . .
Comentarios de: transjava (0)
No hay comentarios