Introducción a Java

Your first step into the world of programming with Java

What is Java?

Java is a general-purpose, object-oriented programming language designed to have as few implementation dependencies as possible.

Object-Oriented

Everything in Java is an object, which makes organizing code easier.

Cross-platform

Write once, run anywhere (WORA).

Safe and Robust

Exception handling and compile-time type checking.

High Performance

Just-In-Time (JIT) compilation for optimization.

Java Architecture

Java Application

1
// Your Java codepublic class MiApp {
    public static void main(String[] args) {
        System.out.println("Hola Mundo");
    }
}

JDK (Java Development Kit)

2
javac (Compiler)
JRE (Java Runtime)
Development tools

JVM (Java Virtual Machine)

3
Class Loader
Execution Engine
Garbage Collector

Operating System

4

JDK (Development Kit)

Tools to develop Java applications

  • Compiler (javac)
  • Debugger
  • Documentation
  • Libraries

JRE (Runtime Environment)

Required to run Java applications

  • JVM (Virtual Machine)
  • Standard libraries
  • Plugins

JVM (Virtual Machine)

Runs Java bytecode

  • Interprets bytecode
  • Manages memory
  • Provides security

Installing Java

1 Download JDK
2 Install
3 Configure Variables
4 Verify

Download JDK

Visit the official Oracle page or use OpenJDK:

Oracle JDK
Download

Official version with enterprise support

OpenJDK
Download

Free open-source version

Select your operating system:
Instructions for Windows:
  1. Download the .exe installer
  2. Run the installer as administrator
  3. Follow the installation wizard
  4. Use the default path: C:\Program Files\Java\

Installation Process

Follow these steps to complete the installation:

Run Installer

Double-click the downloaded file

Accept Terms

Accept the license agreement

Select Path

Use the recommended default path

Wait for Installation

The process may take a few minutes

Configure Environment Variables

Command Prompt - Windows
C:\> java -version
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode)
C:\> echo %JAVA_HOME%
C:\Program Files\Java\jdk-17
Manual configuration (Windows):
  1. Search for "Environment Variables" in the start menu
  2. Click on "Environment Variables"
  3. Under "System variables", click "New"
  4. Name: JAVA_HOME
  5. Value: C:\Program Files\Java\jdk-17
  6. Edit the "Path" variable and add: %JAVA_HOME%\bin

Verify Installation

Test your installation:
Java not tested
Javac not tested
Variables not verified
Test code:
public class VerificarJava {
    public static void main(String[] args) {
        System.out.println("✅ Java instalado correctamente");
        System.out.println("Versión: " + System.getProperty("java.version"));
        System.out.println("Directorio: " + System.getProperty("java.home"));
    }
}

Your First Java Program

Java Code Editor

1
2
3
4
5
6
7
8
9
10
Result:

Compile and run to see the result

Press F5 to compile
Modify the code and run again
Code explanation:
public class

Defines a public class named HolaMundo

public static void main

Main method where execution begins

System.out.println

Prints text to the console

// comment

Comments to explain the code

Anatomy of a Java Program

Class Declaration
public class MiClase {
Main Method
    public static void main(String[] args) {
Program Body
        // Instrucciones aquí        System.out.println("Hola Java");
    }
Class Closing
}
Select a part for explanation:
Class Declaration

In Java, all code must be inside a class.

  • public: The class is accessible from anywhere
  • class: Keyword to define a class
  • MiClase: Name of the class (must match the file name)
Main Method

Entry point of any Java program.

  • public: Accessible from outside the class
  • static: Can be called without creating an object
  • void: Does not return any value
  • String[] args: Command-line arguments
Program Body

Contains the statements that get executed.

  • Statements end with ;
  • They run in order from top to bottom
  • Comments are ignored (// or /* */)
Syntax Rules
  • Java is case-sensitive
  • Class names must start with an uppercase letter
  • The file name must match the class name
  • Use .java as extension
  • Braces {} delimit code blocks

Development Tools

Choose a development environment:

Visual Studio Code

Recommended for beginners

✅ Advantages
  • Free and open-source
  • Extensive extensions
  • Light and fast
  • Multi-language
❌ Disadvantages
  • Requires configuration
  • Less pure Java integration
  • Additional extensions required
Basic setup:
  1. Install VS Code from its website
  2. Open the Extensions tab (Ctrl+Shift+X)
  3. Search for and install "Extension Pack for Java"
  4. Restart VS Code

Practice with This Game

Build the Java Program

Drag the pieces to build a correct Java program:

Score: 0
Time: 60s
Available Pieces
public class Programa {
public static void main(String[] args) {
System.out.println("¡Funciona!");
}
echo "Hola Mundo";
print("Java");
}
Drag here in order:
Drag the pieces to build the program!

Summary and Next Steps

What you learned

  • What Java is and its main features
  • Java architecture (JDK, JRE, JVM)
  • Environment installation and setup
  • Basic structure of a Java program
  • Your first "Hello World!"

Next steps

  • Variables and data types
  • Operators and expressions
  • Control structures
  • Methods and functions
  • Introduction to OOP

Learning tips

  • Practice every day, even if just 30 minutes
  • Modify the examples to understand how they work
  • Don't copy and paste, write the code yourself
  • Join programmer communities
  • Build small personal projects

Knowledge Test

Question 1 expression in 5

What is the entry point of a Java program?

Additional Resources