Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Sumario Fundamentos Java

Rating
-
Sold
-
Pages
5
Uploaded on
18-01-2026
Written in
2025/2026

Fundamentos Java (Fundamentos Java)

Institution
Course

Content preview

ud2_prog.md 2026-01-17




📝 RESUMEN: UD2 - FUNDAMENTOS DE JAVA

1. ⚠ Conceptos Clave
A. La Regla de Oro del Archivo

En Java, todo código vive dentro de una clase.

Nombre del Archivo: DEBE ser idéntico al nombre de la clase pública .java.
Case Sensitive: Java distingue mayúsculas de minúsculas (Main no es main).
Punto de entrada: El programa arranca siempre en public static void main(String[] args).

B. Tipos de Datos: Primitivos vs Clases

No confundas datos básicos con objetos. En el examen suelen poner trampas con esto.

Tipo Descripción Ejemplo Nota Importante

int Entero estándar (32 bits) int x = 10; El más usado para contar.

double Decimal estándar (64 bits) double p = 9.99; Más preciso que float.

boolean Lógico boolean b = true; Vital para los if y while.

String CLASE (Texto) String s = "Hola"; ¡Va con mayúscula! No es primitivo.

char Un solo carácter char c = 'A'; Usa comillas simples ' '.


C. La "Trampa" del Scanner (Buffer)

Es el error más común en exámenes de principiantes.

El Problema: Cuando lees un número (nextInt(), nextDouble()) y luego intentas leer texto
(nextLine()), el programa se salta la lectura del texto.
La Causa: El método numérico lee la cifra pero deja el "Intro" (\n) en la memoria temporal.
La Solución: Escribe sc.nextLine(); justo después de leer el número para "limpiar" el buffer antes de
leer el texto.

D. Comparativa de Bucles (Cuándo usar cuál)

WHILE: Se repite mientras la condición sea verdadera. Puede no ejecutarse nunca si la condición
empieza siendo falsa.
DO-WHILE: Garantiza que el código se ejecuta al menos una vez (ej: menús que deben mostrarse al
entrar).
FOR: Úsalo cuando sabes el número exacto de repeticiones (ej: recorrer un array o contar hasta 10).




2. 💻Snippets
1/5

, ud2_prog.md 2026-01-17


Memoriza estas estructuras. Son los bloques de construcción para cualquier ejercicio de la UD2.

A. La Estructura Base (Lectura y Escritura)

Copia este esqueleto. Incluye la importación y la limpieza de buffer crítica.



import java.util.Scanner; // 1. Importar la herramienta

public class EstructuraBase { // Nombre igual al archivo
public static void main(String[] args) {
// 2. Crear el objeto Scanner (Input)
Scanner sc = new Scanner(System.in);

System.out.print("Introduce tu edad: ");
int edad = sc.nextInt(); // Leer entero

// 3. ⚠ LIMPIEZA DE BUFFER (Truco de examen)
sc.nextLine();

System.out.print("Introduce tu nombre: ");
String nombre = sc.nextLine(); // Leer línea completa

// 4. Salida de datos (Output)
System.out.println("Alumno: " + nombre + " | Edad: " + edad);

sc.close(); // Buena práctica: cerrar recursos
}
}




(Referencias:,)

B. El Menú Estándar (Switch + Break)

Si olvidas el break, Java ejecutará todos los casos seguidos (efecto cascada).



int opcion = 2;
switch (opcion) {
case 1:
System.out.println("Opción 1 elegida");
break; // ¡OBLIGATORIO para salir!
case 2:
System.out.println("Opción 2 elegida");
break;
default: // "Si no es ninguno de los anteriores"
System.out.println("Opción incorrecta");
}




2/5

Written for

Course

Document information

Uploaded on
January 18, 2026
Number of pages
5
Written in
2025/2026
Type
SUMMARY

Subjects

$4.09
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
jesús6

Also available in package deal

Get to know the seller

Seller avatar
jesús6 Universidad Nacional de Educación a Distancia
Follow You need to be logged in order to follow users or courses
Sold
1
Member since
6 months
Number of followers
0
Documents
17
Last sold
5 months ago

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions