RESUMEN COMPLETO DEL LENGUAJE JAVA (Nivel Principiante–Intermedio)
1. TIPOS DE DATOS
Primitivos:
int, double, float, char, boolean, long, byte, short.
No primitivos:
String, Arrays, Objetos, Clases.
2. VARIABLES
int edad = 25;
String nombre = "Isabel";
boolean activo = true;
3. OPERADORES
Aritméticos: + - * / %
Relacionales: == != > < >= <=
Lógicos: && || !
Asignación: = += -= *=
4. IF – ELSE
if (edad >= 18) {
[Link]("Mayor de edad");
} else {
[Link]("Menor de edad");
}
5. SWITCH
switch (dia) {
case 1: [Link]("Lunes"); break;
default: [Link]("Otro día");
}
6. BUCLES
For:
for (int i = 1; i <= 5; i++) { [Link](i); }
While:
int i = 1;
while (i <= 5) {
[Link](i);
i++;
}
Do-While:
int x = 1;
do {
[Link](x);
x++;
} while (x <= 5);
7. MÉTODOS (Funciones)
Sin retorno:
public static void saludar() {
[Link]("Hola Isabel");
}
Con parámetros:
public static void saludarPersona(String nombre) {
[Link]("Hola " + nombre);
}
Con retorno:
public static int sumar(int a, int b) {
return a + b;
}
8. STRINGS
String texto = "Hola Isabel";
[Link]();
[Link]();
[Link](0);
9. ARRAYS
int[] numeros = {1, 2, 3};
for (int n : numeros) { [Link](n); }
10. EXCEPCIONES (TRY - CATCH)
try {
int x = 10 / 0;
} catch (Exception e) {
[Link]("Error: " + [Link]());
}
11. SCANNER (Entrada de datos)
import [Link];
Scanner sc = new Scanner([Link]);
String nombre = [Link]();
12. CLASES Y OBJETOS
class Persona {
String nombre;
int edad;
void saludar() {
[Link]("Hola, soy " + nombre);
}
}
Crear objeto:
Persona p = new Persona();
[Link] = "Isabel";
[Link] = 30;
[Link]();