SlideShare ist ein Scribd-Unternehmen logo
1 von 32
SCJP –  Sección 2: Control de Flujo, Exceptions y Assertions José Miguel Selman G.  (jose.selman@gmail.com)‏
SCJP –  Objetivos exámen ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],* Extraído desde:  http://www.sun.com/training/catalog/courses/CX-310-055.xml
Introducción ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
if-else ,[object Object],[object Object],[object Object],if (expresión booleana) { // la expresión es verdadera, ==> dentro de la sentencia if } else { // la expresión es falsa, ==> dentro de la sentencia else } if (x > 3)  System.out.println(“x es mayor a 3”); else  System.out.println(“x es menos o igual a 3”);
else if ,[object Object],if (x >= 1 && x < 3) { // x es 1 o 2 } else if ( x >= 3 && x < 5 ) { // x es 3 o 4 } else if ( x >= 5 && x < 7 ) { // x es 5 o 6 } else { // x es mayor que 7 }
Expresiones válidas ,[object Object],[object Object],[object Object],[object Object],[object Object],Ojo con: ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
switch switch (expresión) { case constante1: // Código case constante2: // Código default: // Código } ,[object Object],int largo = “abc”.length();  switch (largo) { case 1: System.out.println(“1”);   break; case 2: System.out.println(“2”);   break; default: System.out.println(“default”); }
[object Object],[object Object],int largo = 1;  switch (largo) { case 1: System.out.println(“1”); case 2: System.out.println(“2”); default: System.out.println(“default”); } int largo = 1;  switch (largo) { case 1:  case 2: System.out.println(“1 o 2”);   break; default: System.out.println(“default”); }
Fall-Through y default int i = 11; switch(i) { case 1: System.out.println(“1”); default: System.out.println(“default”); case 2: System.out.println(“2”); case 3: System.out.println(“3”); } ,[object Object],[object Object]
switch ,[object Object],[object Object],[object Object]
while while(expresión booleana) { // hacer algo } ,[object Object],[object Object],int x = 10; while(x > 10) { System.out.println(“dentro del loop”); } System.out.println(“fuera del loop”); ,[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
do-while do { // Código } while (expresión booleana); ,[object Object],int x = 10; do {   System.out.println(“dentro del loop”); } while(x > 10);  System.out.println(“fuera del loop”); ,[object Object],[object Object]
for ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],for ( Inicialización ;  Condición ;  Iteración ) { // instrucciones }  ,[object Object],for ( int i=0; i<10; i++) { } for (int i=10, j=3; y>3; y++) { } for (int x=0; x < 10 && y-- > 2 | x == 3; x++)
for‏ ,[object Object],[object Object],[object Object],for (declaración: expresión) { // instrucciones }  Por ejemplo:  String[] numeros = {“uno”, “dos”, “tres”, “cuatro”, “cinco”}; for(String s: numeros) { System.out.println(s); }
break y continue ,[object Object],[object Object],[object Object],for(int i=1; i<10; i++) { if ( i == 5 || i == 7 ) { continue; }  System.out.println(i); } ,[object Object]
Labels ,[object Object],[object Object],[object Object],[object Object],boolean condicion = true; externo: for(int i=0; i<10; i++) { while(condicion) { System.out.println(“Hola”); break externo; } System.out.println(“Esto no se imprimirá”); } System.out.println(“Chao”); ,[object Object]
Exceptions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
try { // Intentamos abrir un archivo para lectura } catch(NoTenemosLosPermisosSuficientes e) { // Mostrar mensaje de error al usuario } ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Stack de Ejecución main() metodo1() main() metodo1() metodo2() main() main() metodo1() main() La ejecución se inicia con el método main main llama a metodo1 metodo1 llama a metodo2 metodo2 retorna metodo1 retorno y main llama a metodo3 metodo3() main() metodo3 retorna
Exception ducking ,[object Object],[object Object],[object Object],public  int cuentaLineasArchivo(String filename) throws IOException { BufferedReader br; int lineas = 0; try { br = new BufferedReader(new FileReader(filename)); while (br.readLine() != null) {  lineas++; } } finally { if (br != null)  br.close();  } return lineas; }
[object Object],public  int cuentaLineasArchivo(String filename) throws IOException { BufferedReader br; int lineas = 0; try { br = new BufferedReader(new FileReader(filename)); while (br.readLine() != null) {  lineas++; } } catch(IOException ioe) { ioe.printStackTrace(); // o extraer el mensaje usando ioe.getMessage(); throw ioe; } finally { if (br != null)  br.close();  } return lineas; }
Tipos de Exceptions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Jerarquía de Excepciones java.lang.Object java.lang.Throwable java.lang.Error java.lang.Exception java.lang.RuntimeException Fuente: Sun Certified Programmer for Java 5 Study Guide, Kathy Sierra & Bert Bates, McGraw Hill … … …
Atrapar excepciones ,[object Object],[object Object],try { // ... } catch(NumerFormatException e) { // ... } catch(Exception e) { // ...  } try { // ... } catch(Exception e) { // ... } catch(NumerFormatException e) { // ...  } Correcto Incorrecto
Excepciones y Errores comunes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Algunas Comunes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Algunas Comunes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Assertions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Habilitación Assertions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Usos correctos de Assertions ,[object Object],[object Object],[object Object],[object Object]
Recursos ,[object Object],[object Object],[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

Sentencia de control
Sentencia de controlSentencia de control
Sentencia de controlStalyn Cruz
 
Tema 3 sentencias de control de java por gio
Tema 3   sentencias de control de java por gioTema 3   sentencias de control de java por gio
Tema 3 sentencias de control de java por gioRobert Wolf
 
Certificación java 6 cap 5
Certificación java 6 cap 5Certificación java 6 cap 5
Certificación java 6 cap 5srBichoRaro
 
DAW-Estructuras de control
DAW-Estructuras de controlDAW-Estructuras de control
DAW-Estructuras de controlvay82
 
Estructuras de Control - Ivan Walkes Mc.
Estructuras de Control - Ivan Walkes Mc.Estructuras de Control - Ivan Walkes Mc.
Estructuras de Control - Ivan Walkes Mc.Ivan A. Walkes Mc.
 
Estructuras de control C++
Estructuras de control C++Estructuras de control C++
Estructuras de control C++LOANNELMARIN
 
Instrucciones de control de salto
Instrucciones de control de saltoInstrucciones de control de salto
Instrucciones de control de saltoAbrirllave
 
Estructuras algoritnicas de control
Estructuras algoritnicas de controlEstructuras algoritnicas de control
Estructuras algoritnicas de controlMiguel Martinez
 
Estructuras repetitivas
Estructuras repetitivasEstructuras repetitivas
Estructuras repetitivasyance1
 
Estructuras de control
Estructuras de controlEstructuras de control
Estructuras de controlparada137
 
TEMA Nº 8: CONTROL DE EJECUCIÓN Y MANTENIMIENTO DE SESIÓN
TEMA Nº 8: CONTROL DE EJECUCIÓN Y MANTENIMIENTO DE SESIÓNTEMA Nº 8: CONTROL DE EJECUCIÓN Y MANTENIMIENTO DE SESIÓN
TEMA Nº 8: CONTROL DE EJECUCIÓN Y MANTENIMIENTO DE SESIÓNAnyeni Garay
 
Estructuras de control
Estructuras de  controlEstructuras de  control
Estructuras de controlmellcv
 
Estructura de control repetitiva
Estructura de control repetitivaEstructura de control repetitiva
Estructura de control repetitivavillandri pachco
 
Estructura de un programa
Estructura de un programaEstructura de un programa
Estructura de un programaFelipe Romano
 

Was ist angesagt? (19)

Sentencia de control
Sentencia de controlSentencia de control
Sentencia de control
 
Tema 3 sentencias de control de java por gio
Tema 3   sentencias de control de java por gioTema 3   sentencias de control de java por gio
Tema 3 sentencias de control de java por gio
 
Sentencias de control
Sentencias de controlSentencias de control
Sentencias de control
 
Certificación java 6 cap 5
Certificación java 6 cap 5Certificación java 6 cap 5
Certificación java 6 cap 5
 
15 Curso de POO en java - estructuras repetitivas
15 Curso de POO en java - estructuras repetitivas15 Curso de POO en java - estructuras repetitivas
15 Curso de POO en java - estructuras repetitivas
 
DAW-Estructuras de control
DAW-Estructuras de controlDAW-Estructuras de control
DAW-Estructuras de control
 
Manual
ManualManual
Manual
 
Estructuras de Control - Ivan Walkes Mc.
Estructuras de Control - Ivan Walkes Mc.Estructuras de Control - Ivan Walkes Mc.
Estructuras de Control - Ivan Walkes Mc.
 
Estructuras de control C++
Estructuras de control C++Estructuras de control C++
Estructuras de control C++
 
Instrucciones de control de salto
Instrucciones de control de saltoInstrucciones de control de salto
Instrucciones de control de salto
 
Estructuras algoritnicas de control
Estructuras algoritnicas de controlEstructuras algoritnicas de control
Estructuras algoritnicas de control
 
Estructuras repetitivas
Estructuras repetitivasEstructuras repetitivas
Estructuras repetitivas
 
Estructuras de control
Estructuras de controlEstructuras de control
Estructuras de control
 
Estructuras de control
Estructuras de controlEstructuras de control
Estructuras de control
 
TEMA Nº 8: CONTROL DE EJECUCIÓN Y MANTENIMIENTO DE SESIÓN
TEMA Nº 8: CONTROL DE EJECUCIÓN Y MANTENIMIENTO DE SESIÓNTEMA Nº 8: CONTROL DE EJECUCIÓN Y MANTENIMIENTO DE SESIÓN
TEMA Nº 8: CONTROL DE EJECUCIÓN Y MANTENIMIENTO DE SESIÓN
 
Diagramas De Flujo
Diagramas De FlujoDiagramas De Flujo
Diagramas De Flujo
 
Estructuras de control
Estructuras de  controlEstructuras de  control
Estructuras de control
 
Estructura de control repetitiva
Estructura de control repetitivaEstructura de control repetitiva
Estructura de control repetitiva
 
Estructura de un programa
Estructura de un programaEstructura de un programa
Estructura de un programa
 

Andere mochten auch

Rochelle Blackman Slivka
Rochelle Blackman SlivkaRochelle Blackman Slivka
Rochelle Blackman SlivkaRagenDrew
 
EY-introducing-EYs-advisory-services
EY-introducing-EYs-advisory-servicesEY-introducing-EYs-advisory-services
EY-introducing-EYs-advisory-servicesStephen Stone
 
สุขภาพที่ดีเริ่มต้นที่
สุขภาพที่ดีเริ่มต้นที่สุขภาพที่ดีเริ่มต้นที่
สุขภาพที่ดีเริ่มต้นที่guestcfd317
 
Url Shortening Services
Url Shortening ServicesUrl Shortening Services
Url Shortening ServicesAltan Khendup
 
Performance Load Cache
Performance Load CachePerformance Load Cache
Performance Load CacheAltan Khendup
 
Lambda Architecture The Hive
Lambda Architecture The HiveLambda Architecture The Hive
Lambda Architecture The HiveAltan Khendup
 

Andere mochten auch (8)

Rochelle Blackman Slivka
Rochelle Blackman SlivkaRochelle Blackman Slivka
Rochelle Blackman Slivka
 
EY-introducing-EYs-advisory-services
EY-introducing-EYs-advisory-servicesEY-introducing-EYs-advisory-services
EY-introducing-EYs-advisory-services
 
สุขภาพที่ดีเริ่มต้นที่
สุขภาพที่ดีเริ่มต้นที่สุขภาพที่ดีเริ่มต้นที่
สุขภาพที่ดีเริ่มต้นที่
 
Url Shortening Services
Url Shortening ServicesUrl Shortening Services
Url Shortening Services
 
Performance Load Cache
Performance Load CachePerformance Load Cache
Performance Load Cache
 
1234
12341234
1234
 
Lambda Architecture The Hive
Lambda Architecture The HiveLambda Architecture The Hive
Lambda Architecture The Hive
 
Presentation1
Presentation1Presentation1
Presentation1
 

Ähnlich wie Scjp Jug Section 2 Flow Control

SCJP, Clase 5: Control de Flujo
SCJP, Clase 5: Control de FlujoSCJP, Clase 5: Control de Flujo
SCJP, Clase 5: Control de Flujoflekoso
 
Guia demanejodeexcepcionesaserciones
Guia demanejodeexcepcionesasercionesGuia demanejodeexcepcionesaserciones
Guia demanejodeexcepcionesasercionesjbersosa
 
Iv unidad estructuras de control
Iv unidad estructuras de controlIv unidad estructuras de control
Iv unidad estructuras de controlmariaisabelg
 
Mas sobre excepciones
Mas sobre excepcionesMas sobre excepciones
Mas sobre excepcionesjbersosa
 
Lenguaje de programacion java, conceptos
Lenguaje de programacion java, conceptosLenguaje de programacion java, conceptos
Lenguaje de programacion java, conceptosmellcv
 
Clase lenguaje c
Clase lenguaje c Clase lenguaje c
Clase lenguaje c Mar15marian
 
Clase lenguaje c xxxxxx
Clase lenguaje c xxxxxxClase lenguaje c xxxxxx
Clase lenguaje c xxxxxxMar15marian
 
Clase lenguaje c xxxxxx
Clase lenguaje c xxxxxxClase lenguaje c xxxxxx
Clase lenguaje c xxxxxxMar15marian
 
Php04 estructuras control
Php04 estructuras controlPhp04 estructuras control
Php04 estructuras controlJulio Pari
 
Estructuras condicionales
Estructuras condicionalesEstructuras condicionales
Estructuras condicionalesSTEVENZAFIRO
 

Ähnlich wie Scjp Jug Section 2 Flow Control (20)

Programación básica
Programación básicaProgramación básica
Programación básica
 
SCJP, Clase 5: Control de Flujo
SCJP, Clase 5: Control de FlujoSCJP, Clase 5: Control de Flujo
SCJP, Clase 5: Control de Flujo
 
Guia demanejodeexcepcionesaserciones
Guia demanejodeexcepcionesasercionesGuia demanejodeexcepcionesaserciones
Guia demanejodeexcepcionesaserciones
 
Arreglos Expresiones y Control de Flujo
Arreglos Expresiones y Control de FlujoArreglos Expresiones y Control de Flujo
Arreglos Expresiones y Control de Flujo
 
Iv unidad estructuras de control
Iv unidad estructuras de controlIv unidad estructuras de control
Iv unidad estructuras de control
 
Mas sobre excepciones
Mas sobre excepcionesMas sobre excepciones
Mas sobre excepciones
 
Repaso c
Repaso cRepaso c
Repaso c
 
lp1t3.pdf
lp1t3.pdflp1t3.pdf
lp1t3.pdf
 
Lenguaje de programacion java, conceptos
Lenguaje de programacion java, conceptosLenguaje de programacion java, conceptos
Lenguaje de programacion java, conceptos
 
P1
P1P1
P1
 
Estructuras de Control
Estructuras de ControlEstructuras de Control
Estructuras de Control
 
Clase lenguaje c
Clase lenguaje c Clase lenguaje c
Clase lenguaje c
 
Clase lenguaje c xxxxxx
Clase lenguaje c xxxxxxClase lenguaje c xxxxxx
Clase lenguaje c xxxxxx
 
Clase lenguaje c xxxxxx
Clase lenguaje c xxxxxxClase lenguaje c xxxxxx
Clase lenguaje c xxxxxx
 
Lenguaje c
Lenguaje cLenguaje c
Lenguaje c
 
Ejercicios3
Ejercicios3Ejercicios3
Ejercicios3
 
Java básico
Java  básicoJava  básico
Java básico
 
Php04 estructuras control
Php04 estructuras controlPhp04 estructuras control
Php04 estructuras control
 
Try catch
Try catchTry catch
Try catch
 
Estructuras condicionales
Estructuras condicionalesEstructuras condicionales
Estructuras condicionales
 

Kürzlich hochgeladen

EPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial UninoveEPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial UninoveFagnerLisboa3
 
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...silviayucra2
 
Trabajo Mas Completo De Excel en clase tecnología
Trabajo Mas Completo De Excel en clase tecnologíaTrabajo Mas Completo De Excel en clase tecnología
Trabajo Mas Completo De Excel en clase tecnologíassuserf18419
 
Global Azure Lima 2024 - Integración de Datos con Microsoft Fabric
Global Azure Lima 2024 - Integración de Datos con Microsoft FabricGlobal Azure Lima 2024 - Integración de Datos con Microsoft Fabric
Global Azure Lima 2024 - Integración de Datos con Microsoft FabricKeyla Dolores Méndez
 
Presentación guía sencilla en Microsoft Excel.pptx
Presentación guía sencilla en Microsoft Excel.pptxPresentación guía sencilla en Microsoft Excel.pptx
Presentación guía sencilla en Microsoft Excel.pptxLolaBunny11
 
guía de registro de slideshare por Brayan Joseph
guía de registro de slideshare por Brayan Josephguía de registro de slideshare por Brayan Joseph
guía de registro de slideshare por Brayan JosephBRAYANJOSEPHPEREZGOM
 
International Women's Day Sucre 2024 (IWD)
International Women's Day Sucre 2024 (IWD)International Women's Day Sucre 2024 (IWD)
International Women's Day Sucre 2024 (IWD)GDGSucre
 
Desarrollo Web Moderno con Svelte 2024.pdf
Desarrollo Web Moderno con Svelte 2024.pdfDesarrollo Web Moderno con Svelte 2024.pdf
Desarrollo Web Moderno con Svelte 2024.pdfJulian Lamprea
 
pruebas unitarias unitarias en java con JUNIT
pruebas unitarias unitarias en java con JUNITpruebas unitarias unitarias en java con JUNIT
pruebas unitarias unitarias en java con JUNITMaricarmen Sánchez Ruiz
 
Proyecto integrador. Las TIC en la sociedad S4.pptx
Proyecto integrador. Las TIC en la sociedad S4.pptxProyecto integrador. Las TIC en la sociedad S4.pptx
Proyecto integrador. Las TIC en la sociedad S4.pptx241521559
 

Kürzlich hochgeladen (10)

EPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial UninoveEPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial Uninove
 
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
 
Trabajo Mas Completo De Excel en clase tecnología
Trabajo Mas Completo De Excel en clase tecnologíaTrabajo Mas Completo De Excel en clase tecnología
Trabajo Mas Completo De Excel en clase tecnología
 
Global Azure Lima 2024 - Integración de Datos con Microsoft Fabric
Global Azure Lima 2024 - Integración de Datos con Microsoft FabricGlobal Azure Lima 2024 - Integración de Datos con Microsoft Fabric
Global Azure Lima 2024 - Integración de Datos con Microsoft Fabric
 
Presentación guía sencilla en Microsoft Excel.pptx
Presentación guía sencilla en Microsoft Excel.pptxPresentación guía sencilla en Microsoft Excel.pptx
Presentación guía sencilla en Microsoft Excel.pptx
 
guía de registro de slideshare por Brayan Joseph
guía de registro de slideshare por Brayan Josephguía de registro de slideshare por Brayan Joseph
guía de registro de slideshare por Brayan Joseph
 
International Women's Day Sucre 2024 (IWD)
International Women's Day Sucre 2024 (IWD)International Women's Day Sucre 2024 (IWD)
International Women's Day Sucre 2024 (IWD)
 
Desarrollo Web Moderno con Svelte 2024.pdf
Desarrollo Web Moderno con Svelte 2024.pdfDesarrollo Web Moderno con Svelte 2024.pdf
Desarrollo Web Moderno con Svelte 2024.pdf
 
pruebas unitarias unitarias en java con JUNIT
pruebas unitarias unitarias en java con JUNITpruebas unitarias unitarias en java con JUNIT
pruebas unitarias unitarias en java con JUNIT
 
Proyecto integrador. Las TIC en la sociedad S4.pptx
Proyecto integrador. Las TIC en la sociedad S4.pptxProyecto integrador. Las TIC en la sociedad S4.pptx
Proyecto integrador. Las TIC en la sociedad S4.pptx
 

Scjp Jug Section 2 Flow Control

  • 1. SCJP – Sección 2: Control de Flujo, Exceptions y Assertions José Miguel Selman G. (jose.selman@gmail.com)‏
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20. Stack de Ejecución main() metodo1() main() metodo1() metodo2() main() main() metodo1() main() La ejecución se inicia con el método main main llama a metodo1 metodo1 llama a metodo2 metodo2 retorna metodo1 retorno y main llama a metodo3 metodo3() main() metodo3 retorna
  • 21.
  • 22.
  • 23.
  • 24. Jerarquía de Excepciones java.lang.Object java.lang.Throwable java.lang.Error java.lang.Exception java.lang.RuntimeException Fuente: Sun Certified Programmer for Java 5 Study Guide, Kathy Sierra & Bert Bates, McGraw Hill … … …
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.