├── .gitignore ├── Images ├── header.jpg └── pro.jpg ├── LICENSE ├── README.md └── basic ├── c00_helloworld ├── HelloWorld.java └── HelloWorldExercises.java ├── c01_beginner ├── BeginnerExercises.java ├── DataTypes.java └── VariablesAndConstants.java ├── c02_operators ├── Operators.java └── OperatorsExercises.java ├── c03_strings ├── Strings.java └── StringsExercises.java ├── c04_conditionals ├── Conditionals.java └── ConditionalsExercises.java ├── c05_structures ├── Arrays.java ├── Lists.java ├── Maps.java ├── Sets.java └── StructuresExercises.java ├── c06_loops ├── Loops.java └── LoopsExercises.java ├── c07_functions ├── Functions.java └── FunctionsExercises.java ├── c08_oop ├── Abstraction.java ├── AbstractionExercises.java ├── AccessModifiers.java ├── AccessModifiersExercises.java ├── Classes.java ├── ClassesExercises.java ├── Composition.java ├── Inheritance.java ├── InheritanceExercises.java ├── Person.java ├── Polymorphism.java └── PolymorphismExercises.java ├── c08_test_oop └── Classes.java ├── c09_exceptions ├── CustomException.java ├── Exceptions.java ├── ExceptionsExercises.java └── ThrowExample.java └── c10_extras ├── Extras.java ├── ExtrasExample.java └── ExtrasExercises.java /.gitignore: -------------------------------------------------------------------------------- 1 | /out/ 2 | *.class -------------------------------------------------------------------------------- /Images/header.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mouredev/hello-java/155bb35080d507da7c1564d8fdff2e6d2e6b68ee/Images/header.jpg -------------------------------------------------------------------------------- /Images/pro.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mouredev/hello-java/155bb35080d507da7c1564d8fdff2e6d2e6b68ee/Images/pro.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hello Java 2 | 3 | [![Java](https://img.shields.io/badge/Java-JDK_21+-red?style=for-the-badge&logo=java&logoColor=white&labelColor=101010)](https://www.oracle.com/es/java) 4 | 5 | ## Curso para aprender el lenguaje de programación Java desde cero y para principiantes 6 | 7 | ![](./Images/header.jpg) 8 | 9 | ### Proyecto realizado durante emisiones en directo desde [Twitch](https://twitch.tv/mouredev) 10 | > ##### Si consideras útil el curso, apóyalo haciendo "★ Star" en el repositorio. ¡Gracias! 11 | 12 | ## Curso desde cero 13 | ### Próximamente se subirá editado a [YouTube](https://youtube.com/@mouredev) y con extras (ejercicios, test, examen, certificado y soporte) a [mouredev pro](https://mouredev.pro) 14 | 15 | ### Clases: 16 | 17 | * Clase 1 [02/04/2025] - Introducción y Hola Mundo 18 | * [Vídeo](https://www.twitch.tv/videos/2422706574) 19 | * [Código](./basic/c00_helloworld/HelloWorld.java) 20 | 21 | * Clase 2 [09/04/2025] - Comentarios, Variables, Constantes, Tipos de datos y Operadores 22 | * [Vídeo](https://www.twitch.tv/videos/2428998601) 23 | * [Ejercicios Hola Mundo](./basic/c00_helloworld/HelloWorldExercises.java) 24 | * [Variables y constantes](./basic/c01_beginner/VariablesAndConstants.java) | [Tipos de datos](./basic/c01_beginner/DataTypes.java) | [Ejercicios](./basic/c01_beginner/BeginnerExercises.java) 25 | * [Operadores](./basic/c02_operators/Operators.java) | [Ejercicios](./basic/c02_operators/OperatorsExercises.java) 26 | 27 | * Clase 3 [17/04/2025] - Strings, Condicionales y Arrays 28 | * [Vídeo](https://www.twitch.tv/videos/2436086584) 29 | * [Strings](./basic/c03_strings/Strings.java) | [Ejercicios](./basic/c03_strings/StringsExercises.java) 30 | * [Condicionales](./basic/c04_conditionals/Conditionals.java) | [Ejercicios](./basic/c04_conditionals/ConditionalsExercises.java) 31 | * [Arrays](./basic/c05_structures/Arrays.java) 32 | 33 | * Clase 4 [31/04/2025] - Listas, Sets y Mapas 34 | * [Vídeo](https://www.twitch.tv/videos/2447254597) 35 | * [Listas](./basic/c05_structures/Lists.java) 36 | * [Sets](./basic/c05_structures/Sets.java) 37 | * [Mapas](./basic/c05_structures/Maps.java) 38 | * [Ejercicios](./basic/c05_structures/StructuresExercises.java) 39 | 40 | * Clase 5 [06/05/2025] - Bucles y funciones 41 | * [Vídeo](https://www.twitch.tv/videos/2452053839) 42 | * [Bucles](./basic/c06_loops/Loops.java) | [Ejercicios](./basic/c06_loops/LoopsExercises.java) 43 | * [Funciones](./basic/c07_functions/Functions.java) | [Ejercicios](./basic/c07_functions/FunctionsExercises.java) 44 | 45 | * Clase 6 [14/05/2025] - Clases, encapsulamiento y herencia 46 | * [Vídeo](https://www.twitch.tv/videos/2459212698) 47 | * [Clases](./basic/c08_oop/Classes.java) | [Clase Persona](./basic/c08_oop/Person.java) | [Ejercicios](./basic/c08_oop/ClassesExercises.java) 48 | * [Encapsulamiento](./basic/c08_oop/AccessModifiers.java) | [Clases (otro paquete para pruebas)](./basic/c08_test_oop/Classes.java) 49 | * [Herencia](./basic/c08_oop/Inheritance.java) 50 | 51 | * Clase 7 [21/05/2025] - Polimorfismo, abstracción y composición 52 | * [Vídeo](https://www.twitch.tv/videos/2464789369) 53 | * [Polimorfismo](./basic/c08_oop/Polymorphism.java) 54 | * [Abstracción](./basic/c08_oop/Abstraction.java) 55 | * [Composición](./basic/c08_oop/Composition.java) 56 | * Ejercicios: [Encapsulamiento](./basic/c08_oop/AccessModifiersExercises.java) | [Herencia](./basic/c08_oop/InheritanceExercises.java) | [Polimorfismo](./basic/c08_oop/PolymorphismExercises.java) | [Abstracción](./basic/c08_oop/AbstractionExercises.java) 57 | 58 | * Clase 8 [28/05/2025] - Manejo de excepciones, depuración y extras 59 | * [Vídeo](https://www.twitch.tv/videos/2471305243) 60 | * [Excepciones](./basic/c09_exceptions/Exceptions.java) | [Lanzamiento](./basic/c09_exceptions/ThrowExample.java) | [Excepciones personalizadas](./basic/c09_exceptions/CustomException.java) | [Ejercicios](./basic/c09_exceptions/ExceptionsExercises.java) 61 | * [Extras](./basic/c10_extras/Extras.java) | [Ejemplo](./basic/c10_extras/ExtrasExample.java) | [Ejercicios](./basic/c10_extras/ExtrasExercises.java) 62 | 63 | 64 | ## Enlaces de interés 65 | 66 | * Impacto: [Índice TIOBE](https://www.tiobe.com/tiobe-index/) | [GitHub](https://github.blog/news-insights/octoverse/octoverse-2024/) | [Stack Overflow](https://survey.stackoverflow.co/2024/technology#most-popular-technologies-language) 67 | * [Historia](https://es.wikipedia.org/wiki/Java_(lenguaje_de_programaci%C3%B3n)) | [Kotlin](https://kotlinlang.org/) 68 | * [Java 8](https://www.java.com/es/download/) | [Java SE](https://www.oracle.com/es/java/technologies/java-se-glance.html) | [Java EE](https://www.oracle.com/es/java/technologies/java-ee-glance.html) 69 | * [OpenJDK](https://openjdk.org/) | [Oracle JDK](https://www.oracle.com/es/java/technologies/downloads/) 70 | * Editores: [IntelliJ Community](https://www.jetbrains.com/idea/download/other.html) | [VS Code](https://code.visualstudio.com/docs/languages/java) | [NetBeans](https://netbeans.apache.org/front/main/index.html) | [Eclipse](https://eclipseide.org/) | [BlueJ](https://www.bluej.org/) | [Playground web](https://dev.java/playground/) 71 | * [Documentación oficial](https://docs.oracle.com/en/java/) 72 | * [Guía de estilo](https://google.github.io/styleguide/javaguide.html) 73 | 74 | ## Únete al campus de programación de la comunidad 75 | 76 | ![https://mouredev.pro](./Images/pro.jpg) 77 | 78 | #### Te presento [mouredev pro](https://mouredev.pro), mi proyecto más importante para ayudarte a estudiar programación y desarrollo de software de manera diferente. 79 | 80 | > **¿Buscas un extra?** Aquí encontrarás cursos editados por lecciones individuales, para avanzar a tu ritmo y guardar el progreso. También dispondrás de ejercicios y correcciones, test para validar tus conocimientos, examen y certificado público de finalización, soporte, foro de estudiantes, reunionnes grupales, cursos exclusivos y mucho más. 81 | > 82 | > Entra en **[mouredev.pro](https://mouredev.pro)** y utiliza el cupón **"PRO"** con un 10% de descuento en tu primera suscripción. 83 | 84 | ## Preguntas frecuentes 85 | 86 | #### ¿Debo tener conocimientos previos? 87 | Mi idea es que el curso sea desde cero y para principiantes. Pensado para una persona que comienza por primera vez a programar. Es un curso de fundamentos, donde nos centraremos en aprender las bases del lenguaje con Java puro. Esto no es un curso para aprender a desarrollar proyectos. Vamos a empezar desde el principio. 88 | 89 | Si la acogida de la comunidad es buena, seguiré creando cursos más avanzados. 90 | 91 | #### ¿Este curso se va a subir a YouTube? 92 | 93 | Sí, una vez finalizados, todos los cursos son editados y subidos en bloque a YouTube. 94 | 95 | #### ¿Se creará una continuación del curso? 96 | Si, una vez publicado en YouTube, el apoyo de la comunidad es bueno, crearé un nuevo curso con lecciones más avanzadas. 97 | 98 | #### ¿Existe algún lugar donde consultar dudas? 99 | He creado un canal llamado "Java" en el [servidor de Discord](https://discord.gg/mouredev) de la comunidad. Allí puedes consultar dudas y ayudar al resto de miembros. Así nos beneficiamos tod@s. 100 | 101 | #### ¿Cómo puedo practicar? 102 | En cada lección encontrarás ejercicios para poner en práctica lo aprendido. También puedes realizar los ejercicios de mi web [retosdeprogramacion.com](https://retosdeprogramacion.com). 103 | 104 | ## ![https://mouredev.com](https://raw.githubusercontent.com/mouredev/mouredev/master/mouredev_emote.png) Hola, mi nombre es Brais Moure. 105 | ### Freelance fullstack iOS & Android engineer 106 | 107 | [![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UCxPD7bsocoAMq8Dj18kmGyQ?style=social)](https://youtube.com/mouredevapps?sub_confirmation=1) 108 | [![Twitch Status](https://img.shields.io/twitch/status/mouredev?style=social)](https://twitch.com/mouredev) 109 | [![Discord](https://img.shields.io/discord/729672926432985098?style=social&label=Discord&logo=discord)](https://mouredev.com/discord) 110 | [![Twitter Follow](https://img.shields.io/twitter/follow/mouredev?style=social)](https://twitter.com/mouredev) 111 | ![GitHub Followers](https://img.shields.io/github/followers/mouredev?style=social) 112 | ![GitHub Followers](https://img.shields.io/github/stars/mouredev?style=social) 113 | 114 | Soy ingeniero de software desde 2010. Desde 2018 combino mi trabajo desarrollando Apps con la creación de contenido formativo sobre programación y tecnología en diferentes redes sociales como **[@mouredev](https://moure.dev)**. 115 | 116 | Si quieres unirte a nuestra comunidad de desarrollo, aprender programación, mejorar tus habilidades y ayudar a la continuidad del proyecto, puedes encontrarnos en: 117 | 118 | [![Twitch](https://img.shields.io/badge/Twitch-Programación_en_directo-9146FF?style=for-the-badge&logo=twitch&logoColor=white&labelColor=101010)](https://twitch.tv/mouredev) 119 | [![Discord](https://img.shields.io/badge/Discord-Servidor_de_la_comunidad-5865F2?style=for-the-badge&logo=discord&logoColor=white&labelColor=101010)](https://mouredev.com/discord) [![Pro](https://img.shields.io/badge/Cursos-mouredev.pro-FF5500?style=for-the-badge&logo=gnometerminal&logoColor=white&labelColor=101010)](https://mouredev.pro) 120 | [![Link](https://img.shields.io/badge/Links_de_interés-moure.dev-14a1f0?style=for-the-badge&logo=Linktree&logoColor=white&labelColor=101010)](https://moure.dev) [![Web](https://img.shields.io/badge/GitHub-MoureDev-087ec4?style=for-the-badge&logo=github&logoColor=white&labelColor=101010)](https://github.com/mouredev) 121 | -------------------------------------------------------------------------------- /basic/c00_helloworld/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package basic.c00_helloworld; 2 | 3 | /* 4 | Clase 1 - Introducción y Hola Mundo (02/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2422706574 6 | - 7 | Clase 2 - Comentarios, Variables, Constantes, Tipos de datos y Operadores (09/04/2025) 8 | Vídeo: https://www.twitch.tv/videos/2428998601 9 | */ 10 | 11 | // Hola Mundo 12 | 13 | public class HelloWorld { 14 | 15 | public static void main(String[] args) { 16 | System.out.println("Hola, Java!"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /basic/c00_helloworld/HelloWorldExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c00_helloworld; 2 | 3 | /* 4 | Clase 2 - Comentarios, Variables, Constantes, Tipos de datos y Operadores (09/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2428998601 6 | */ 7 | 8 | public class HelloWorldExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Imprime un mensaje que diga tu nombre en lugar de "¡Hola Mundo!". 13 | 14 | // 2. Imprime dos líneas: "Hola" y luego "Mundo" con un solo println. 15 | 16 | // 3. Añade un comentario sobre lo que hace cada línea del programa. 17 | 18 | // 4. Crea un comentario en varias líneas. 19 | 20 | // 5. Imprime tu edad, tu color favorito y tu ciudad. 21 | 22 | // 6. Explora los diferentes System.XXX.println(); más allá de "out". 23 | 24 | // 7. Utiliza varios println para imprimir una frase. 25 | 26 | // 8. Imprime un diseño ASCII (por ejemplo, una cara feliz usando símbolos). 27 | 28 | // 9. Intenta ejecutar el programa sin el método main y observa el error. 29 | 30 | //10. Intenta cambiar el nombre del archivo a uno diferente del de la clase y compílalo. ¿Qué pasa? 31 | 32 | } 33 | } -------------------------------------------------------------------------------- /basic/c01_beginner/BeginnerExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c01_beginner; 2 | 3 | /* 4 | Clase 2 - Comentarios, Variables, Constantes, Tipos de datos y Operadores (09/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2428998601 6 | */ 7 | 8 | public class BeginnerExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Declara una variable de tipo String y asígnale tu nombre. 13 | 14 | // 2. Crea una variable de tipo int y asígnale tu edad. 15 | 16 | // 3. Crea una variable double con tu altura en metros. 17 | 18 | // 4. Declara una variable de tipo boolean que indique si te gusta programar. 19 | 20 | // 5. Declara una constante con tu email. 21 | 22 | // 6. Crea una variable de tipo char y guárdale tu inicial. 23 | 24 | // 7. Declara una variable de tipo String con tu localidad, y a continuación cambia su valor y vuelve a imprimirla. 25 | 26 | // 8. Crea una variable int llamada a, otra b, e imprime la suma de ambas. 27 | 28 | // 9. Imprime el tipo de dos variables creadas anteriormente. 29 | 30 | // 10. Intenta declarar una variable sin inicializarla y luego asígnale un valor antes de imprimirla. 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /basic/c01_beginner/DataTypes.java: -------------------------------------------------------------------------------- 1 | package basic.c01_beginner; 2 | 3 | /* 4 | Clase 2 - Comentarios, Variables, Constantes, Tipos de datos y Operadores (09/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2428998601 6 | */ 7 | 8 | public class DataTypes { 9 | 10 | public static void main(String[] args) { 11 | 12 | // Tipos de datos primitivos 13 | 14 | int myInt = 37; 15 | System.out.println(myInt); 16 | 17 | double myDouble = 1.77; 18 | System.out.println(myDouble); 19 | 20 | // float, long, byte 21 | 22 | char myChar = 'a'; 23 | System.out.println(myChar); 24 | 25 | boolean myBoolean = true; 26 | myBoolean = false; 27 | System.out.println(myBoolean); 28 | 29 | String myString = "Hola, Java"; 30 | System.out.println(myString); 31 | 32 | // Tipo de dato en tiempo de compilación 33 | 34 | System.out.println(myString.getClass().getSimpleName()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /basic/c01_beginner/VariablesAndConstants.java: -------------------------------------------------------------------------------- 1 | package basic.c01_beginner; 2 | 3 | /* 4 | Clase 2 - Comentarios, Variables, Constantes, Tipos de datos y Operadores (09/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2428998601 6 | */ 7 | 8 | public class VariablesAndConstants { 9 | 10 | public static void main(String[] args) { 11 | 12 | // Variables 13 | 14 | String name = "Brais"; 15 | System.out.println(name); 16 | 17 | name = "MoureDev"; 18 | System.out.println(name); 19 | 20 | // name = 37; Error (no podemos cambiar el tipo de dato) 21 | 22 | int age = 37; 23 | System.out.println(age); 24 | 25 | var email = "mouredev@gmail.com"; 26 | System.out.println(email); 27 | 28 | var year = 2025; 29 | System.out.println(year); 30 | 31 | // Constantes 32 | 33 | final String EMAIL = "mouredev@gmail.com"; 34 | // EMAIL = "brais@gmail.com"; Es constante 35 | System.out.println(EMAIL); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /basic/c02_operators/Operators.java: -------------------------------------------------------------------------------- 1 | package basic.c02_operators; 2 | 3 | /* 4 | Clase 2 - Comentarios, Variables, Constantes, Tipos de datos y Operadores (09/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2428998601 6 | */ 7 | 8 | public class Operators { 9 | 10 | public static void main(String[] args) { 11 | 12 | // Operadores 13 | 14 | // Aritméticos 15 | 16 | var a = 5; 17 | var b = 3; 18 | 19 | System.out.println(a + b); 20 | System.out.println(a - b); 21 | System.out.println(a * b); 22 | System.out.println(a / b); 23 | System.out.println(a % b); 24 | 25 | // Asignación 26 | 27 | a = b; 28 | System.out.println(a); 29 | 30 | a = b * 2; 31 | System.out.println(a); 32 | 33 | a += 1; // a = a + 1 34 | System.out.println(a); 35 | 36 | a -= 1; 37 | System.out.println(a); 38 | a *= 2; 39 | System.out.println(a); 40 | a /= 2; 41 | System.out.println(a); 42 | a %= 2; 43 | System.out.println(a); 44 | 45 | // Comparación (Relacionales) 46 | 47 | System.out.println(a == b); 48 | System.out.println(a == 0); 49 | 50 | System.out.println(a != b); 51 | System.out.println(a > b); 52 | System.out.println(a >= b); 53 | System.out.println(a < b); 54 | System.out.println(a <= b); 55 | 56 | // Lógicos 57 | 58 | // Y (AND) 59 | System.out.println(true && true); 60 | System.out.println(true && false); 61 | System.out.println(false && true); 62 | System.out.println(false && false); 63 | 64 | System.out.println(3 > 2 && 5 == 2); 65 | 66 | // O (OR) 67 | System.out.println(true || true); 68 | System.out.println(true || false); 69 | System.out.println(false || true); 70 | System.out.println(false || false); 71 | 72 | System.out.println(3 > 2 || 5 == 2); 73 | 74 | // NO (NOT) 75 | System.out.println(!true); 76 | System.out.println(!false); 77 | 78 | System.out.println(!(3 > 2) || 5 == 2); 79 | 80 | // Unarios 81 | System.out.println(+b); 82 | System.out.println(-b); 83 | System.out.println(++b); 84 | System.out.println(b++); 85 | System.out.println(b); 86 | System.out.println(--b); 87 | System.out.println(b--); 88 | System.out.println(b); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /basic/c02_operators/OperatorsExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c02_operators; 2 | 3 | /* 4 | Clase 2 - Comentarios, Variables, Constantes, Tipos de datos y Operadores (09/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2428998601 6 | */ 7 | 8 | public class OperatorsExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Crea una variable con el resultado de cada operación aritmética. 13 | 14 | // 2. Crea una variable para cada tipo de operación de asignación. 15 | 16 | // 3. Imprime 3 comparaciones verdaderas con diferentes operadores de comparación. 17 | 18 | // 4. Imprime 3 comparaciones falsas con diferentes operadores de comparación. 19 | 20 | // 5. Utiliza el operador lógico and. 21 | 22 | // 6. Utiliza el operador lógico or. 23 | 24 | // 7. Combina ambos operadores lógicos. 25 | 26 | // 8. Añade alguna negación. 27 | 28 | // 9. Imprime 3 ejemplos de uso de operadores unarios. 29 | 30 | // 10. Combina operadores aritméticos, de comparación y lógicos. 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /basic/c03_strings/Strings.java: -------------------------------------------------------------------------------- 1 | package basic.c03_strings; 2 | 3 | /* 4 | Clase 3 - Strings, Condicionales y Arrays (17/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2436086584 6 | */ 7 | 8 | public class Strings { 9 | 10 | public static void main(String[] args) { 11 | 12 | // Cadenas de texto 13 | 14 | // Declaración 15 | 16 | String name = "Brais"; 17 | var surname = new String("Moure"); 18 | 19 | // Operaciones básicas 20 | 21 | // Concatenación 22 | System.out.println(name + " " + surname); 23 | 24 | // Longitud 25 | System.out.println(name.length()); 26 | 27 | // Obtener caracter 28 | System.out.println(name.charAt(name.length() - 1)); 29 | 30 | // Subcadena 31 | System.out.println(name.substring(2)); 32 | System.out.println(name.substring(1, 3)); 33 | 34 | // Mayúsculas y minúsculas 35 | System.out.println(name.toUpperCase()); 36 | System.out.println(name.toLowerCase()); 37 | 38 | System.out.println(name); 39 | 40 | // Comprobar si contiene 41 | System.out.println("Hola, Java".contains("Brais")); 42 | System.out.println("Hola, Java".toUpperCase().contains("AVA")); 43 | 44 | // Comparación 45 | System.out.println(name.equals("Brais")); 46 | System.out.println(name.equals("brais")); 47 | System.out.println(name.equalsIgnoreCase("brais")); 48 | 49 | // == vs. equals 50 | 51 | var a = "Brais"; 52 | var b = "Brais"; 53 | var c = new String("Brais"); 54 | 55 | System.out.println(a == b); 56 | System.out.println(a == c); 57 | System.out.println(a.equals(c)); 58 | 59 | // Trim 60 | System.out.println(" Hola, me llamo Brais ".trim()); 61 | 62 | // Replace 63 | System.out.println(" Hola, me llamo Brais ".replace("Brais", "Moure")); 64 | 65 | // Format 66 | var age = 37; 67 | System.out.println(String.format("Hola, %s. Tengo %d.", name, age)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /basic/c03_strings/StringsExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c03_strings; 2 | 3 | /* 4 | Clase 3 - Strings, Condicionales y Arrays (17/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2436086584 6 | */ 7 | 8 | public class StringsExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Concatena dos cadenas de texto. 13 | 14 | // 2. Muestra la longitud de una cadena de texto. 15 | 16 | // 3. Muestra el primer y último carácter de un string. 17 | 18 | // 4. Convierte a mayúsculas y minúsculas un string. 19 | 20 | // 5. Comprueba si una cadena de texto contiene una palabra concreta. 21 | 22 | // 6. Formatea un string con un entero. 23 | 24 | // 7. Elimina los espacios en blanco al principio y final de un string. 25 | 26 | // 8. Sustituye todos los espacios en blanco de un string por un guión (-). 27 | 28 | // 9. Comprueba si dos strings son iguales. 29 | 30 | // 10. Comprueba si dos strings tienen la misma longitud. 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /basic/c04_conditionals/Conditionals.java: -------------------------------------------------------------------------------- 1 | package basic.c04_conditionals; 2 | 3 | /* 4 | Clase 3 - Strings, Condicionales y Arrays (17/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2436086584 6 | */ 7 | 8 | public class Conditionals { 9 | 10 | public static void main(String[] args) { 11 | 12 | // Condicionales 13 | 14 | // if, else if, else 15 | 16 | var age = 18; 17 | 18 | System.out.println(age >= 18); 19 | 20 | if (age > 18) { 21 | System.out.println("El usuario es mayor de edad"); 22 | } else if (age == 18) { 23 | System.out.println("El usuario acaba de cumplir 18"); 24 | } else { 25 | System.out.println("El usuario es menor de edad"); 26 | } 27 | 28 | // switch 29 | 30 | var day = 5; 31 | 32 | switch (day) { 33 | case 1: 34 | System.out.println("Lunes"); 35 | break; 36 | case 2: 37 | System.out.println("Martes"); 38 | break; 39 | case 3: 40 | System.out.println("Miércoles"); 41 | break; 42 | default: 43 | System.out.println("No es lunes, martes o miércoles"); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /basic/c04_conditionals/ConditionalsExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c04_conditionals; 2 | 3 | /* 4 | Clase 3 - Strings, Condicionales y Arrays (17/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2436086584 6 | */ 7 | 8 | public class ConditionalsExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Establece la edad de un usuario y muestra si puede votar (mayor o igual a 18). 13 | 14 | // 2. Declara dos números y muestra cuál es mayor, o si son iguales. 15 | 16 | // 3. Dado un número, verifica si es positivo, negativo o cero. 17 | 18 | // 4. Crea un programa que diga si un número es par o impar. 19 | 20 | // 5. Verifica si un número está en el rango de 1 a 100. 21 | 22 | // 6. Declara una variable con el día de la semana (1-7) y muestra su nombre con switch. 23 | 24 | // 7. Simula un sistema de notas: muestra "Sobresaliente", "Aprobado" o "Suspenso" según la nota (0-100). 25 | 26 | // 8. Escribe un programa que determine si puedes entrar al cine: debes tener al menos 15 años o ir acompañado. 27 | 28 | // 9. Crea un programa que diga si una letra es vocal o consonante. 29 | 30 | // 10. Usa tres variables a, b, c y muestra cuál es el mayor de las tres. 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /basic/c05_structures/Arrays.java: -------------------------------------------------------------------------------- 1 | package basic.c05_structures; 2 | 3 | /* 4 | Clase 3 - Strings, Condicionales y Arrays (17/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2436086584 6 | */ 7 | 8 | public class Arrays { 9 | 10 | public static void main(String[] args) { 11 | 12 | // Declaración y creación 13 | int[] numbers = new int[3]; 14 | System.out.println(numbers); 15 | 16 | String[] names = {"Brais", "Moure", "mouredev"}; 17 | System.out.println(names); 18 | 19 | // Acceso 20 | System.out.println(numbers[0]); 21 | System.out.println(names[0]); 22 | 23 | System.out.println((new String[3])[0]); 24 | 25 | // Modificación 26 | numbers[0] = 1; 27 | numbers[1] = 10; 28 | System.out.println(numbers[0]); 29 | System.out.println(numbers[1]); 30 | 31 | // numbers[3] = 2; Error 32 | 33 | System.out.println(names[2]); 34 | names[2] = "mouredev@gmail.com"; 35 | System.out.println(names[2]); 36 | 37 | System.out.println(names.length); 38 | names[2] = null; 39 | System.out.println(names[2]); 40 | System.out.println(names.length); 41 | 42 | // numbers[2] = null; Error 43 | 44 | boolean[] booleans = new boolean[5]; 45 | System.out.println(booleans[4]); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /basic/c05_structures/Lists.java: -------------------------------------------------------------------------------- 1 | package basic.c05_structures; 2 | 3 | /* 4 | Clase 4 - Listas, Sets y Mapas (31/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2447254597 6 | */ 7 | 8 | import java.util.ArrayList; 9 | 10 | public class Lists { 11 | 12 | public static void main(String[] args) { 13 | 14 | // Declaración y creación 15 | ArrayList names = new ArrayList<>(); 16 | var numbers = new ArrayList(); 17 | 18 | // Tamaño 19 | 20 | System.out.println(names.size()); 21 | 22 | // Inserción 23 | 24 | names.add("Brais"); 25 | names.add("Moure"); 26 | names.add("MoureDev"); 27 | System.out.println(names.size()); 28 | 29 | // Acceso 30 | 31 | System.out.println(names.getFirst()); 32 | System.out.println(names.get(1)); 33 | System.out.println(names.getLast()); 34 | 35 | // Modificación 36 | 37 | names.set(2, "mouredev@gmail.com"); 38 | System.out.println(names.getLast()); 39 | 40 | // Eliminación 41 | 42 | names.remove(2); 43 | // System.out.println(names.get(2)); // Error 44 | System.out.println(names.size()); 45 | 46 | // Búsqueda 47 | 48 | System.out.println(names.contains("Brais")); 49 | System.out.println(names.contains("mouredev@gmail.com")); 50 | 51 | // Limpieza 52 | 53 | names.add("Brais"); 54 | System.out.println(names); 55 | names.clear(); 56 | System.out.println(names.size()); 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /basic/c05_structures/Maps.java: -------------------------------------------------------------------------------- 1 | package basic.c05_structures; 2 | 3 | /* 4 | Clase 4 - Listas, Sets y Mapas (31/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2447254597 6 | */ 7 | 8 | import java.util.HashMap; 9 | 10 | public class Maps { 11 | 12 | public static void main(String[] args) { 13 | 14 | // Declaración y creación 15 | HashMap names = new HashMap<>(); 16 | var numbers = new HashMap(); 17 | 18 | // Tamaño 19 | 20 | System.out.println(names.size()); 21 | 22 | // Inserción 23 | 24 | names.put("Brais", "brais@gmail.com"); 25 | names.put("Moure", "moure@gmail.com"); 26 | names.put("MoureDev", "mouredev@gmail.com"); 27 | System.out.println(names.size()); 28 | System.out.println(names); 29 | 30 | // Acceso 31 | 32 | System.out.println(names.get("Moure")); 33 | System.out.println(names.get("Dev")); 34 | 35 | // Verificación 36 | 37 | System.out.println(names.containsKey("Moure")); 38 | System.out.println(names.containsKey("Dev")); 39 | 40 | System.out.println(names.containsValue("moure@gmail.com")); 41 | 42 | // Eliminación 43 | 44 | System.out.println(names.remove("Moure")); 45 | System.out.println(names.remove("MoureDev")); 46 | System.out.println(names); 47 | 48 | // Limpieza 49 | 50 | names.clear(); 51 | System.out.println(names); 52 | 53 | // Modificación 54 | 55 | names.put("Brais", "brais@gmail.com"); 56 | System.out.println(names); 57 | 58 | names.put("Brais", "braismouredev@gmail.com"); 59 | System.out.println(names); 60 | 61 | names.replace("Moure", "mouredev@gmail.com"); // Reemplaza el valor si existe 62 | System.out.println(names); 63 | 64 | names.putIfAbsent("Moure", "mouredev@gmail.com"); // Solo lo añade si no existe 65 | System.out.println(names); 66 | 67 | // Otras operaciones 68 | 69 | System.out.println(names.isEmpty()); 70 | var values = names.values(); 71 | System.out.println(values); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /basic/c05_structures/Sets.java: -------------------------------------------------------------------------------- 1 | package basic.c05_structures; 2 | 3 | /* 4 | Clase 4 - Listas, Sets y Mapas (31/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2447254597 6 | */ 7 | 8 | import java.util.HashSet; 9 | 10 | public class Sets { 11 | 12 | public static void main(String[] args) { 13 | 14 | // Declaración y creación 15 | HashSet names = new HashSet<>(); 16 | var numbers = new HashSet(); 17 | 18 | // Tamaño 19 | 20 | System.out.println(names.size()); 21 | 22 | // Inserción 23 | 24 | names.add("Brais"); 25 | names.add("Moure"); 26 | names.add("MoureDev"); 27 | names.add("mouredev@gmail.com"); 28 | System.out.println(names.size()); 29 | System.out.println(names); 30 | 31 | numbers.add(1); 32 | numbers.add(2); 33 | numbers.add(3); 34 | 35 | // Eliminación 36 | 37 | names.remove("Brais"); 38 | System.out.println(names.size()); 39 | 40 | // Búsqueda 41 | 42 | System.out.println(names.contains("Brais")); 43 | System.out.println(names.contains("mouredev@gmail.com")); 44 | 45 | System.out.println(names); 46 | names.add("Moure"); 47 | names.add("Moure"); 48 | names.add("Moure"); 49 | System.out.println(names); 50 | 51 | // Conjuntos 52 | 53 | // names.addAll(numbers); Error 54 | 55 | var countries = new HashSet(); 56 | countries.add("España"); 57 | countries.add("México"); 58 | countries.add("Argentina"); 59 | countries.add("MoureDev"); 60 | 61 | names.addAll(countries); 62 | System.out.println(names); 63 | 64 | names.removeAll(countries); 65 | System.out.println(names); 66 | 67 | names.retainAll(countries); 68 | System.out.println(names); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /basic/c05_structures/StructuresExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c05_structures; 2 | 3 | /* 4 | Clase 4 - Listas, Sets y Mapas (31/04/2025) 5 | Vídeo: https://www.twitch.tv/videos/2447254597 6 | */ 7 | 8 | public class StructuresExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Crea un Array con 5 valores e imprime su longitud. 13 | 14 | // 2. Modifica uno de los valores del Array e imprime el valor del índice antes y después de modificarlo. 15 | 16 | // 3. Crea un ArrayList vacío. 17 | 18 | // 4. Añade 4 valores al ArrayList y elimina uno a continuación. 19 | 20 | // 5. Crea un HashSet con 2 valores diferentes. 21 | 22 | // 6. Añade un nuevo valor repetido y otro sin repetir al HashSet. 23 | 24 | // 7. Elimina uno de los elementos del HashSet. 25 | 26 | // 8. Crea un HashMap donde la clave sea un nombre y el valor el número de teléfono. Añade tres contactos. 27 | 28 | // 9. Modifica uno de los contactos y elimina otro. 29 | 30 | // 10. Dado un Array, transfórmalo en un ArrayList, a continuación en un HashSet y finalmente en un HashMap con clave y valor iguales. 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /basic/c06_loops/Loops.java: -------------------------------------------------------------------------------- 1 | package basic.c06_loops; 2 | 3 | /* 4 | Clase 5 - Bucles y funciones (06/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2452053839 6 | */ 7 | 8 | import java.util.HashMap; 9 | import java.util.HashSet; 10 | import java.util.Map; 11 | 12 | public class Loops { 13 | 14 | public static void main(String[] args) { 15 | 16 | // Loops 17 | 18 | // - for controlado por contador 19 | 20 | for (int index = 0; index < 5; index++) { 21 | System.out.println("Hola, Java!"); 22 | } 23 | 24 | String[] names = {"Brais", "Moure", "mouredev"}; 25 | 26 | for (int index = 0; index < names.length; index++) { 27 | System.out.println(names[index]); 28 | } 29 | 30 | // - for-each 31 | 32 | for (String name: names) { 33 | System.out.println(name); 34 | } 35 | 36 | HashSet numbers = new HashSet<>(); 37 | numbers.add(1); 38 | numbers.add(2); 39 | numbers.add(3); 40 | numbers.add(4); 41 | numbers.add(5); 42 | 43 | for (Integer number: numbers) { 44 | System.out.println(number); 45 | } 46 | 47 | HashMap emails = new HashMap<>(); 48 | emails.put("Brais", "brais@gmail.com"); 49 | emails.put("Moure", "moure@gmail.com"); 50 | emails.put("MoureDev", "mouredev@gmail.com"); 51 | 52 | for (Map.Entry email: emails.entrySet()) { 53 | System.out.println(email.getKey()); 54 | System.out.println(email.getValue()); 55 | } 56 | 57 | // - while 58 | 59 | int index = 0; 60 | while (index < 5) { 61 | System.out.println("Hola, Java!"); 62 | index++; 63 | } 64 | 65 | index = 0; 66 | while (index < names.length) { 67 | System.out.println(names[index]); 68 | index++; 69 | } 70 | 71 | index = 0; 72 | boolean find = false; 73 | while (!find) { 74 | System.out.println(names[index]); 75 | if (names[index].equals("Moure")) { 76 | find = true; 77 | } 78 | index++; 79 | } 80 | 81 | // - do-while 82 | 83 | index = 0; 84 | do { 85 | System.out.println("Hola, Java!"); 86 | index++; 87 | } while (index < 0); 88 | 89 | // Control de bucles 90 | 91 | // - break 92 | 93 | for (String name: names) { 94 | if (name.equals("Moure")) { 95 | break; 96 | } 97 | System.out.println(name); 98 | } 99 | 100 | // - continue 101 | 102 | for (int i = 0; i < 5; i++) { 103 | if (i == 3) { 104 | continue; 105 | } 106 | System.out.println(i); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /basic/c06_loops/LoopsExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c06_loops; 2 | 3 | /* 4 | Clase 5 - Bucles y funciones (06/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2452053839 6 | */ 7 | 8 | public class LoopsExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Imprime los números del 1 al 10 usando while. 13 | 14 | // 2. Usa do-while para mostrar todos los valores de un ArrayList. 15 | 16 | // 3. Imprime los múltiplos de 5 del 1 al 50 usando for. 17 | 18 | // 4. Recorre un Array de 5 números e imprime la suma total. 19 | 20 | // 5. Usa un for para recorrer un Array y mostrar sus valores. 21 | 22 | // 6. Usa for-each para recorrer un HashSet y un HashMap. 23 | 24 | // 7. Imprime los números del 10 al 1 (descendiente) con un bucle for. 25 | 26 | // 8. Usa continue para saltar los múltiplos de 3 del 1 al 20. 27 | 28 | // 9. Usa break para detener un bucle cuando encuentres un número negativo en un array. 29 | 30 | // 10. Crea un programa que calcule el factorial de un número dado. 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /basic/c07_functions/Functions.java: -------------------------------------------------------------------------------- 1 | package basic.c07_functions; 2 | 3 | /* 4 | Clase 5 - Bucles y funciones (06/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2452053839 6 | */ 7 | 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | 11 | public class Functions { 12 | 13 | public static void main(String[] args) { 14 | 15 | // Funciones 16 | 17 | for (int index = 0; index < 5; index++) { 18 | sendEmail(); 19 | } 20 | 21 | // ... 22 | 23 | sendEmail(); 24 | 25 | sendEmailToUser("brais@gmail.com"); 26 | sendEmailToUser("brais@gmail.com", "Brais"); 27 | 28 | var users = new ArrayList<>(Arrays.asList("brais@gmail.com", "moure@gmail.com")); 29 | sendEmailToUser(users); 30 | 31 | var state = sendEmailWithState("brais@gmail.com"); 32 | System.out.println(state); 33 | 34 | System.out.println(sendEmailWithState("")); 35 | } 36 | 37 | // Función sin parámetros ni retorno 38 | 39 | public static void sendEmail() { 40 | System.out.println("Se envía el email"); 41 | } 42 | 43 | // Función con parámetros 44 | 45 | public static void sendEmailToUser(String email) { 46 | System.out.println("Se envía el email a " + email); 47 | } 48 | 49 | // Sobrecarga de funciones 50 | 51 | public static void sendEmailToUser(String email, String name) { 52 | System.out.println("Se envía el email a " + name + " (" + email + ")"); 53 | } 54 | 55 | public static void sendEmailToUser(ArrayList emails) { 56 | for (String email: emails) { 57 | sendEmailToUser(email); 58 | } 59 | } 60 | 61 | // Función con retorno 62 | 63 | public static boolean sendEmailWithState(String email) { 64 | 65 | if (email.isEmpty()) { 66 | return false; 67 | } 68 | 69 | System.out.println("Se envía el email a " + email); 70 | return true; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /basic/c07_functions/FunctionsExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c07_functions; 2 | 3 | /* 4 | Clase 5 - Bucles y funciones (06/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2452053839 6 | */ 7 | 8 | public class FunctionsExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Crea una función que imprima "¡Te doy la bienvenida al curso de Java desde cero!". 13 | 14 | // 2. Escribe una función que reciba un nombre como parámetro y salude a esa persona. 15 | 16 | // 3. Haz un método que reciba dos números enteros y devuelva su resta. 17 | 18 | // 4. Crea un método que calcule el cuadrado de un número (n * n). 19 | 20 | // 5. Escribe una función que reciba un número y diga si es par o impar. 21 | 22 | // 6. Crea un método que reciba una edad y retorne true si es mayor de edad (y false en caso contrario). 23 | 24 | // 7. Implementa una función que reciba una cadena y retorne su longitud. 25 | 26 | // 8. Crea un método que reciba un array de enteros, calcula su media y lo retorna. 27 | 28 | // 9. Escribe un método que reciba un número y retorna su factorial. 29 | 30 | // 10. Crea una función que reciba un ArrayList y lo recorra mostrando cada elemento. 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /basic/c08_oop/Abstraction.java: -------------------------------------------------------------------------------- 1 | package basic.c08_oop; 2 | 3 | /* 4 | Clase 7 - Polimorfismo, abstracción y composición (21/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2464789369 6 | */ 7 | 8 | public class Abstraction { 9 | 10 | public static void main(String[] args) { 11 | 12 | // Abstracción 13 | 14 | // - Clase abstracta 15 | 16 | var dog = new Dog(); 17 | dog.sleep(); 18 | dog.sound(); 19 | 20 | var cat = new Cat(); 21 | cat.sleep(); 22 | cat.sound(); 23 | 24 | // - Interface 25 | } 26 | 27 | // - Clase abstracta 28 | 29 | public static abstract class Animal { 30 | 31 | public abstract void sound(); 32 | 33 | public void sleep() { 34 | System.out.println("El animal está durmiendo"); 35 | } 36 | } 37 | 38 | public static class Dog extends Animal { 39 | 40 | @Override 41 | public void sound() { 42 | System.out.println("Guau"); 43 | } 44 | 45 | @Override 46 | public void sleep() { 47 | System.out.println("El perro está durmiendo"); 48 | } 49 | } 50 | 51 | public static class Cat extends Animal { 52 | 53 | @Override 54 | public void sound() { 55 | System.out.println("Miau"); 56 | } 57 | } 58 | 59 | // - Interface 60 | 61 | public interface Flying { 62 | 63 | void fly(); 64 | } 65 | 66 | public static class Bird extends Animal implements Flying { 67 | 68 | @Override 69 | public void sound() { 70 | System.out.println("Pio pio"); 71 | } 72 | 73 | @Override 74 | public void fly() { 75 | System.out.println("El pájaro vuela"); 76 | } 77 | } 78 | 79 | public static class Bat extends Animal implements Flying { 80 | 81 | @Override 82 | public void sound() { 83 | System.out.println("Soy batman!"); 84 | } 85 | 86 | @Override 87 | public void fly() { 88 | System.out.println("El murciélago vuela"); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /basic/c08_oop/AbstractionExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c08_oop; 2 | 3 | /* 4 | Clase 7 - Polimorfismo, abstracción y composición (21/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2464789369 6 | */ 7 | 8 | public class AbstractionExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Crea una clase abstracta Shape con el método calculateArea(). Luego implementa dos subclases: Circle y Rectangle, y haz que cada una calcule su propia área. 13 | 14 | // 2. Crea una interfaz Playable con el método play(). Luego implementa esa interfaz en dos clases: Guitar y Piano. Cada una debe mostrar un mensaje diferente al ejecutarse. 15 | 16 | // 3. Define una clase abstracta Animal con el método makeSound(). Implementa Dog y Cat para que hagan sonidos distintos. Crea un array de Animal para mostrar polimorfismo. 17 | 18 | // 4. Crea una interfaz Drawable. Implementa las clases Circle, Square, y Triangle que muestren cómo se dibuja cada figura usando draw(). 19 | 20 | // 5. Crea una clase abstracta Employee con un método calculateSalary(). Implementa FullTimeEmployee y PartTimeEmployee con lógica diferente para calcular el salario. 21 | 22 | // 6. Crea una interfaz Movable con el método move(). Haz que las clases Car y Robot implementen ese método con comportamientos diferentes. 23 | 24 | // 7. Crea una clase abstracta Appliance con método turnOn() y turnOff(). Implementa TV y WashingMachine con mensajes diferentes al encender y apagar. 25 | 26 | // 8. Crea dos interfaces Flyable y Swimmable. Crea una clase Duck que implemente ambas interfaces y muestre cómo puede volar y nadar. 27 | 28 | // 9. Crea una clase abstracta Document con el método print(). Luego crea PDFDocument y WordDocument, cada una con su forma de imprimir. 29 | 30 | // 10. Crea una interfaz Payable con el método pay(). Luego implementa las clases Invoice y EmployeePayment, cada una mostrando un mensaje de pago diferente. 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /basic/c08_oop/AccessModifiers.java: -------------------------------------------------------------------------------- 1 | package basic.c08_oop; 2 | 3 | /* 4 | Clase 6 - Clases, encapsulamiento y herencia (14/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2459212698 6 | */ 7 | 8 | public class AccessModifiers { 9 | 10 | public static void main(String[] args) { 11 | 12 | // Encapsulamiento 13 | 14 | // - Modificadores de acceso 15 | // public 16 | // private 17 | // protected 18 | // (default) 19 | 20 | // getters 21 | // setters 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /basic/c08_oop/AccessModifiersExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c08_oop; 2 | 3 | /* 4 | Clase 7 - Polimorfismo, abstracción y composición (21/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2464789369 6 | */ 7 | 8 | public class AccessModifiersExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Crea una clase Person con atributos privados name y age. Usa los métodos getName(), setName(), getAge() y setAge() para asignar y mostrar valores desde otra clase. 13 | 14 | // 2. Crea una clase Product con el atributo privado price. Añade el método setPrice(double price) que solo permita precios mayores a 0. 15 | 16 | // 3. Crea una clase BankAccount con el atributo privado balance. Implementa los métodos deposit(double amount) y withdraw(double amount) que validen las cantidades correctamente. 17 | 18 | // 4. Crea una clase Book con el atributo privado title. Permite leerlo con el método getTitle() pero no modificarlo (sin setTitle()). El título debe asignarse solo por el constructor. 19 | 20 | // 5. Crea una clase Temperature con el atributo privado celsius. El método setCelsius(double celsius) solo debe aceptar valores entre -100 y 100. 21 | 22 | // 6. Crea una clase User con los atributos privados username y password. Implementa los métodos setUsername(String username), setPassword(String password) y checkPassword(String inputPassword) que compare contraseñas. 23 | 24 | // 7. Crea una clase Employee con el atributo privado salary. Agrega el método raiseSalary(double percent) que solo permita aumentos positivos. 25 | 26 | // 8. Crea una clase Rectangle con los atributos privados width y height. Agrega setters y el método calculateArea() que devuelva el resultado de width * height. 27 | 28 | // 9. Crea una clase Student con el atributo privado grade. Agrega los métodos setGrade(int grade) y isPassed() que retorne true si la nota es mayor o igual a 60. 29 | 30 | // 10. Crea una clase Car con el atributo privado speed. Agrega los métodos accelerate(int amount) que aumente la velocidad (máximo 120) y brake(int amount) que reduzca la velocidad (mínimo 0). 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /basic/c08_oop/Classes.java: -------------------------------------------------------------------------------- 1 | package basic.c08_oop; 2 | 3 | /* 4 | Clase 6 - Clases, encapsulamiento y herencia (14/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2459212698 6 | */ 7 | 8 | public class Classes { 9 | 10 | public static void main(String[] args) { 11 | 12 | var person = new Person("Brais", -38, "123456789A"); 13 | 14 | // person.name = "Brais"; 15 | // person.age = 38; 16 | 17 | person.sayHello(); 18 | 19 | person.name = "Brais Moure"; 20 | System.out.println(person.name); 21 | 22 | // person.id = "123456789A"; 23 | 24 | System.out.println(person.getId()); 25 | 26 | person.setAge(38); 27 | System.out.println(person.getAge()); 28 | 29 | var person2 = new Person("MoureDev", 18, "123456789B"); 30 | person2.sayHello(); 31 | } 32 | } -------------------------------------------------------------------------------- /basic/c08_oop/ClassesExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c08_oop; 2 | 3 | /* 4 | Clase 6 - Clases, encapsulamiento y herencia (14/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2459212698 6 | */ 7 | 8 | public class ClassesExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Crea una clase Book con atributos title y author. Crea un objeto y muestra sus datos. 13 | 14 | // 2. Crea una clase Dog con un método bark() que imprima su sonido. 15 | 16 | // 3. Añade un constructor a la clase Book que reciba title y author. 17 | 18 | // 4. Crea una clase Car con atributos brand y model y un método showData(). 19 | 20 | // 5. Crea una clase Student con atributo score y un método que diga si aprobó (mayor o igual a 60). 21 | 22 | // 6. Crea una clase BankAccount con atributo balance y un método deposit() que sume el saldo. 23 | 24 | // 7. Crea una clase Rectangle con métodos para calcular el área y el perímetro. 25 | 26 | // 8. Crea una clase Worker que reciba nombre y salario, y un método para mostrar su salario. 27 | 28 | // 9. Crea varios objetos Person y guárdalos en un ArrayList. 29 | 30 | // 10. Crea una clase Product y un método que aplique un descuento sobre su precio. 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /basic/c08_oop/Composition.java: -------------------------------------------------------------------------------- 1 | package basic.c08_oop; 2 | 3 | /* 4 | Clase 7 - Polimorfismo, abstracción y composición (21/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2464789369 6 | */ 7 | 8 | public class Composition { 9 | 10 | public static void main(String[] args) { 11 | 12 | // Composición ("tiene un") 13 | 14 | var car = new Car(); 15 | car.on(); 16 | } 17 | 18 | public static class Engine { 19 | 20 | public void on() { 21 | System.out.println("Motor encendido"); 22 | } 23 | } 24 | 25 | public static class Car { 26 | 27 | final private Engine engine = new Engine(); 28 | 29 | public void on() { 30 | engine.on(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /basic/c08_oop/Inheritance.java: -------------------------------------------------------------------------------- 1 | package basic.c08_oop; 2 | 3 | /* 4 | Clase 6 - Clases, encapsulamiento y herencia (14/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2459212698 6 | */ 7 | 8 | public class Inheritance { 9 | 10 | public static void main(String[] args) { 11 | 12 | // Herencia ("es un") 13 | 14 | var animal = new Animal("Mi animal"); 15 | // animal.name = "Mi animal"; 16 | animal.eat(); 17 | 18 | var dog = new Dog("Mou", 3); 19 | // dog.name = "Mou"; 20 | dog.eat(); 21 | 22 | var cat = new Cat("Cou"); 23 | // cat.name = "Cou"; 24 | cat.eat(); 25 | 26 | var bird = new Bird("Bou"); 27 | // bird.name = "Bou"; 28 | bird.eat(); 29 | bird.fly(); 30 | } 31 | 32 | public static class Animal { 33 | 34 | String name; 35 | 36 | public Animal(String name) { 37 | this.name = name; 38 | } 39 | 40 | public void eat() { 41 | System.out.println("El animal con nombre " + name + " está comiendo."); 42 | } 43 | } 44 | 45 | public static class Dog extends Animal { 46 | 47 | int age; 48 | 49 | public Dog(String name, int age) { 50 | super(name); 51 | this.age = age; 52 | } 53 | 54 | @Override 55 | public void eat() { 56 | System.out.println("El perro con nombre " + name + " está comiendo."); 57 | } 58 | } 59 | 60 | public static class Cat extends Animal { 61 | 62 | public Cat(String name) { 63 | super(name); 64 | } 65 | } 66 | 67 | public static class Bird extends Animal { 68 | 69 | public Bird(String name) { 70 | super(name); 71 | } 72 | 73 | public void fly() { 74 | System.out.println("Está volando"); 75 | } 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /basic/c08_oop/InheritanceExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c08_oop; 2 | 3 | /* 4 | Clase 7 - Polimorfismo, abstracción y composición (21/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2464789369 6 | */ 7 | 8 | public class InheritanceExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Crea una clase Vehicle con un método move(). Luego crea una subclase Car que herede de Vehicle y agrega el método honk(). 13 | 14 | // 2. Define una clase Person con los atributos name y age. Luego crea una clase Student que agregue el atributo grade y un método study(). 15 | 16 | // 3. Crea una clase Animal con el método makeSound(). Haz que Dog diga “Woof” y Cat diga “Meow” sobrescribiendo ese método. 17 | 18 | // 4. La clase Employee tiene los atributos name y salary. Manager hereda de Employee y agrega el atributo department. 19 | 20 | // 5. Crea una clase abstracta Shape con un método calculateArea(). Luego implementa ese método en Circle y Rectangle. 21 | 22 | // 6. Crea una clase Bird con el método fly(). Luego crea Eagle que sobrescriba fly() pero también llame al método original con super.fly(). 23 | 24 | // 7. Haz una clase Device con un constructor que imprima “Device created”. Luego crea Phone que herede de Device y en su constructor imprima “Phone ready”. 25 | 26 | // 8. Account tiene un saldo y métodos para deposit() y withdraw(). SavingsAccount hereda y agrega un método addInterest(). 27 | 28 | // 9. Crea una clase Vehicle y tres subclases: Car, Bike y Truck, cada una con un método describe() sobrescrito. 29 | 30 | // 10. Crea un ArrayList que contenga instancias de Dog, Cat y Bird. Recorre la lista y llama a makeSound(). 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /basic/c08_oop/Person.java: -------------------------------------------------------------------------------- 1 | package basic.c08_oop; 2 | 3 | /* 4 | Clase 6 - Clases, encapsulamiento y herencia (14/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2459212698 6 | */ 7 | 8 | public class Person { 9 | 10 | // Atributos 11 | protected String name; 12 | private int age; 13 | final private String id; 14 | 15 | // Constructor 16 | public Person(String name, int age, String id) { 17 | this.name = name; 18 | this.setAge(age); 19 | this.id = id; 20 | } 21 | 22 | // Métodos 23 | public void sayHello() { 24 | System.out.println("Hola, soy " + name + ", tengo " + age + " años, y mi id es " + id + "."); 25 | } 26 | 27 | // Getter 28 | public int getAge() { 29 | return age; 30 | } 31 | 32 | public String getId() { 33 | return id; 34 | } 35 | 36 | // Setter 37 | public void setAge(int age) { 38 | if (age > 0) { 39 | this.age = age; 40 | } else { 41 | System.out.println("Edad no válida"); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /basic/c08_oop/Polymorphism.java: -------------------------------------------------------------------------------- 1 | package basic.c08_oop; 2 | 3 | /* 4 | Clase 7 - Polimorfismo, abstracción y composición (21/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2464789369 6 | */ 7 | 8 | public class Polymorphism { 9 | 10 | public static void main(String[] args) { 11 | 12 | 13 | // Polimorfismo 14 | 15 | // - Polimorfismo por herencia (sobrescritura) 16 | 17 | var animal = new Animal(); 18 | animal.sound(); 19 | 20 | var dog = new Dog(); 21 | dog.sound(); 22 | 23 | // - Polimorfismo por sobrecarga (sobrecarga de métodos) 24 | 25 | var calculator = new Calculator(); 26 | System.out.println(calculator.sum(3, 5)); 27 | System.out.println(calculator.sum(3.2, 5.4)); 28 | } 29 | 30 | // - Polimorfismo por herencia (sobrescritura) 31 | 32 | public static class Animal { 33 | 34 | public void sound() { 35 | System.out.println("Algún sonido"); 36 | } 37 | } 38 | 39 | public static class Dog extends Animal { 40 | 41 | @Override 42 | public void sound() { 43 | System.out.println("Guau"); 44 | } 45 | } 46 | 47 | // - Polimorfismo por sobrecarga (sobrecarga de métodos) 48 | 49 | public static class Calculator { 50 | 51 | public int sum(int a, int b) { 52 | return a + b; 53 | } 54 | 55 | public int sum(int a, int b, int c) { 56 | return a + b + c; 57 | } 58 | 59 | public double sum(double a, double b) { 60 | return a + b; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /basic/c08_oop/PolymorphismExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c08_oop; 2 | 3 | /* 4 | Clase 7 - Polimorfismo, abstracción y composición (21/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2464789369 6 | */ 7 | 8 | public class PolymorphismExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Crea una clase Animal con el método makeSound(). Luego crea subclases Dog, Cat y Cow que sobrescriban ese método con sonidos diferentes. Llama al método desde una lista de Animal. 13 | 14 | // 2. Crea una clase Shape con el método calculateArea(). Luego implementa subclases Circle y Rectangle con sus propias fórmulas. Usa una lista de Shape para recorrer e imprimir el área de varias figuras. 15 | 16 | // 3. Crea una clase Printer con varios métodos print() sobrecargados que acepten diferentes tipos de parámetros (String, int, double). Llama a cada uno desde main. 17 | 18 | // 4. Crea una clase Greeter con dos métodos greet(): uno que salude con “Hello”, y otro que reciba un nombre y salude con “Hello, [nombre]”. 19 | 20 | // 5. Crea una clase Vehicle con un método start(). Luego crea Car, Bike y Truck que sobrescriban ese método. Recorre una lista ArrayList para llamar a start() en cada uno. 21 | 22 | // 6. Crea una clase Notification con método send(), y subclases EmailNotification, SMSNotification. Luego crea una función sendNotification(Notification n) que reciba cualquier tipo y lo ejecute. 23 | 24 | // 7. Crea una función showAnimalType(Animal animal) que imprima el tipo de animal. Pasa diferentes subclases (Dog, Cat, Horse) para que cada una imprima su tipo con su propio getType() sobrescrito. 25 | 26 | // 8. Crea una clase Converter con métodos convert(int), convert(double), y convert(String) que devuelvan diferentes formatos de texto. 27 | 28 | // 9. Crea una clase Product con el método getPrice(). Luego, Book y Electronic deben sobrescribirlo con su propia lógica de descuento. Recorre una lista de Product e imprime el precio final de cada uno. 29 | 30 | // 10. Crea una clase Character con método attack(). Luego crea subclases Warrior, Archer, Mage con ataques diferentes. En main, crea un array de Character y llama a attack() para cada uno. 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /basic/c08_test_oop/Classes.java: -------------------------------------------------------------------------------- 1 | package basic.c08_test_oop; 2 | 3 | /* 4 | Clase 6 - Clases, encapsulamiento y herencia (14/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2459212698 6 | */ 7 | 8 | import basic.c08_oop.Person; 9 | 10 | public class Classes { 11 | 12 | public static void main(String[] args) { 13 | 14 | var person = new Person("Brais", 38, "123456789A"); 15 | 16 | // person.name = "Brais"; 17 | // person.age = 38; 18 | 19 | person.sayHello(); 20 | 21 | // person.name = "Brais Moure"; 22 | // System.out.println(person.name); 23 | } 24 | } -------------------------------------------------------------------------------- /basic/c09_exceptions/CustomException.java: -------------------------------------------------------------------------------- 1 | package basic.c09_exceptions; 2 | 3 | /* 4 | Clase 8 - Manejo de excepciones, depuración y extras (28/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2471305243 6 | */ 7 | 8 | public class CustomException extends Exception { 9 | 10 | public CustomException(String message) { 11 | super(message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /basic/c09_exceptions/Exceptions.java: -------------------------------------------------------------------------------- 1 | package basic.c09_exceptions; 2 | 3 | /* 4 | Clase 8 - Manejo de excepciones, depuración y extras (28/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2471305243 6 | */ 7 | 8 | public class Exceptions { 9 | 10 | public static void main(String[] args) { 11 | 12 | // Manejo de excepciones 13 | 14 | // try catch 15 | try { 16 | var result = 10 / 0; 17 | System.out.println(result); 18 | } catch (ArithmeticException e) { 19 | System.out.println("Error: " + e); 20 | } 21 | 22 | // try con múltiples catch 23 | try { 24 | var result = 10 / 5; 25 | System.out.println(result); 26 | 27 | var name = "Brais"; 28 | name = null; 29 | System.out.println("Name: " + name.toUpperCase()); 30 | } catch (ArithmeticException e) { 31 | System.out.println("Cuidado con dividir algo que no puedes: " + e); 32 | } catch (NullPointerException e) { 33 | System.out.println("Ha ocurrido un null pointer mítico!"); 34 | } catch (Exception e) { 35 | System.out.println("Se ha producido un error no esperado"); 36 | } 37 | 38 | // finally 39 | try { 40 | var result = 10 / 0; 41 | System.out.println(result); 42 | } catch (ArithmeticException e) { 43 | System.out.println("Error: " + e); 44 | } finally { 45 | System.out.println("Fin del bloque try-catch"); 46 | } 47 | 48 | // throw 49 | var throwExample = new ThrowExample(); 50 | try { 51 | throwExample.checkAge(15); 52 | } catch (IllegalArgumentException e) { 53 | System.out.println("Error revisando la edad: " + e.getMessage()); 54 | } 55 | 56 | // Excepción personalizada 57 | try { 58 | throwExample.checkScore(450); 59 | } catch (CustomException e) { 60 | System.out.println("Error revisando la puntuación: "+ e.getMessage()); 61 | } 62 | 63 | System.out.println("Fin"); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /basic/c09_exceptions/ExceptionsExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c09_exceptions; 2 | 3 | /* 4 | Clase 8 - Manejo de excepciones, depuración y extras (28/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2471305243 6 | */ 7 | 8 | public class ExceptionsExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Divide dos números almacenados en dos variables. Maneja la división por cero con try-catch. 13 | 14 | // 2. Crea un array de 3 elementos e intenta acceder al índice 5. Captura el ArrayIndexOutOfBoundsException. 15 | 16 | // 3. Crea una variable String nula e intenta imprimir su longitud. Maneja el NullPointerException. 17 | 18 | // 4. Escribe una función que transforma texto a número. Usa try-catch para manejar entradas no válidas (NumberFormatException). 19 | 20 | // 5. Escribe un programa con un bloque finally que se ejecute siempre, haya o no error. 21 | 22 | // 6. Usa throw para lanzar un IllegalArgumentException si un número introducido es negativo. 23 | 24 | // 7. Crea una clase TemperatureChecker que lanza una excepción personalizada si la temperatura es menor a -50 o mayor a 50. 25 | 26 | // 8. Crea un programa con varios bloques catch: uno para ArithmeticException, otro para ArrayIndexOutOfBoundsException. 27 | 28 | // 9. Crea una función checkPassword(String pass) que lance una excepción si la contraseña es demasiado corta. 29 | 30 | // 10. Implementa una clase LoginSystem que use una excepción personalizada LoginFailedException si el usuario o contraseña son incorrectos. 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /basic/c09_exceptions/ThrowExample.java: -------------------------------------------------------------------------------- 1 | package basic.c09_exceptions; 2 | 3 | /* 4 | Clase 8 - Manejo de excepciones, depuración y extras (28/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2471305243 6 | */ 7 | 8 | public class ThrowExample { 9 | 10 | public void checkAge(int age) throws IllegalArgumentException { 11 | if (age < 18) { 12 | throw new IllegalArgumentException("Tienes que ser mayor de edad"); 13 | } else { 14 | System.out.println("Es mayor de edad"); 15 | } 16 | } 17 | 18 | public void checkScore(int score) throws CustomException { 19 | if (score < 0 || score > 100) { 20 | throw new CustomException("La puntuación debe estar entre 0 y 100"); 21 | } else { 22 | System.out.println("Puntuación válida: " + score); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /basic/c10_extras/Extras.java: -------------------------------------------------------------------------------- 1 | package basic.c10_extras; 2 | 3 | /* 4 | Clase 8 - Manejo de excepciones, depuración y extras (28/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2471305243 6 | */ 7 | 8 | import basic.c08_oop.Classes; 9 | import basic.c08_oop.Person; 10 | 11 | import java.util.Scanner; 12 | //import basic.c08_oop.*; 13 | 14 | public class Extras { 15 | 16 | static String globalName = "mouredev"; 17 | 18 | public static void main(String[] args) { 19 | 20 | // Extras 21 | 22 | // null 23 | 24 | String name = "Brais"; 25 | name = null; 26 | if (name != null) { 27 | System.out.println(name.toLowerCase()); 28 | } 29 | 30 | // import 31 | 32 | new Person("Brais", 18, "1"); 33 | new Classes(); 34 | 35 | // Scanner 36 | 37 | var scanner = new Scanner(System.in); 38 | 39 | System.out.println("Introduce tu edad: "); 40 | var age = scanner.nextInt(); 41 | 42 | System.out.println("La edad es: " + age); 43 | 44 | // Scope: variables globales y locales 45 | 46 | test(); 47 | 48 | // static 49 | } 50 | 51 | public static void test() { 52 | System.out.println(globalName); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /basic/c10_extras/ExtrasExample.java: -------------------------------------------------------------------------------- 1 | package basic.c10_extras; 2 | 3 | /* 4 | Clase 8 - Manejo de excepciones, depuración y extras (28/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2471305243 6 | */ 7 | 8 | public class ExtrasExample { 9 | 10 | public static void main(String[] args) { 11 | 12 | Extras.test(); 13 | System.out.println(Extras.globalName); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /basic/c10_extras/ExtrasExercises.java: -------------------------------------------------------------------------------- 1 | package basic.c10_extras; 2 | 3 | /* 4 | Clase 8 - Manejo de excepciones, depuración y extras (28/05/2025) 5 | Vídeo: https://www.twitch.tv/videos/2471305243 6 | */ 7 | 8 | public class ExtrasExercises { 9 | 10 | public static void main(String[] args) { 11 | 12 | // 1. Crea una variable de tipo String inicializada como null y verifica que no esté vacía antes de usarla. 13 | 14 | // 2. Escribe un programa que lea el nombre y edad del usuario usando Scanner. 15 | 16 | // 3. Declara una constante final llamada MAX_SCORE con valor 100 y muéstrala. 17 | 18 | // 4. Crea una variable global message y otra local message dentro del método main(). Muestra ambas. 19 | 20 | // 5. Usa import java.util.Scanner; para leer un número y mostrar si es positivo o negativo. 21 | 22 | // 6. Declara una variable static en una clase y accede a ella desde main() sin crear un objeto. 23 | 24 | // 7. Importa java.util.Random y genera un número aleatorio del 1 al 10. 25 | 26 | // 8. Crea una clase con comentarios adecuados explicando cada sección del código. 27 | 28 | // 9. Define una clase User con una constante APP_NAME, una variable global username y una función que imprima ambas. 29 | 30 | // 10. Haz debug del código implementado haciendo uso de sus diferentes herramientas. 31 | } 32 | } 33 | --------------------------------------------------------------------------------