VisualStudioTutor.com Java Tutorial All Lessons

Lesson 1 of 20

Introduction to Java Programming

Understand what Java is, how Java source code becomes a running program, and the roles of the JDK, JVM, and runtime.

Learning objectives

  • Explain why Java is described as platform-independent.
  • Distinguish the JDK, JVM, and Java runtime.
  • Understand the basic compile-and-run workflow.
  • Read a small Java class and identify its main method.
  • Create and run a first program from the command line or an IDE.

1. What is Java?

Java is a general-purpose, strongly typed, object-oriented programming language. Java source files use the .java extension. Instead of compiling directly to one operating system's machine code, the Java compiler normally produces bytecode. That bytecode is executed by a Java Virtual Machine (JVM).

Example: a minimal Java program

public class HelloJava {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
    }
}

The class is named HelloJava, so the source file must be saved as HelloJava.java. The main method is the starting point of this console application. System.out.println displays text and then moves the cursor to a new line.

2. JDK, JVM, and the Java runtime

These terms describe different parts of the Java platform:

TermMeaningRole
JDKJava Development KitTools for developing Java programs, including the compiler javac and the java launcher.
JVMJava Virtual MachineExecutes Java bytecode and manages services such as memory and garbage collection.
RuntimeLibraries + JVM needed to run Java applicationsProvides the environment in which compiled Java applications execute.

Example: source code to running program

// Step 1: compile
javac HelloJava.java

// Step 2: run the compiled class
java HelloJava

After compilation, Java creates HelloJava.class. The java command asks the JVM to load and execute that class.

3. Why Java is portable

The phrase write once, run anywhere refers to the bytecode model. The same compiled bytecode can normally run on Windows, macOS, or Linux when a compatible JVM is available. The JVM handles the operating-system-specific details.

Example output

Hello, Java!

4. Where Java is used

Java is widely used for enterprise applications, web back ends, cloud services, desktop tools, build systems, data platforms, and many large server-side systems. Android development also has deep Java roots, although Kotlin is common today.

Mini exercise: introduce yourself

Create AboutMe.java and print three lines: your name, the reason you are learning Java, and one application you hope to build.

public class AboutMe {
    public static void main(String[] args) {
        System.out.println("Name: Aisha");
        System.out.println("I am learning Java to understand OOP.");
        System.out.println("Goal: Build a student management system.");
    }
}

Common beginner mistakes

ProblemWhy it happensHow to fix it
File name does not match the public classJava requires the file and public class names to match.Save HelloJava in HelloJava.java.
Typing java HelloJava.java after compilingThe launcher normally expects a class name after compilation.Use java HelloJava.
Missing semicolonMost Java statements end with ;.Check the line reported by the compiler.

Summary

You learned the Java execution model: write source code, compile it into bytecode, then run that bytecode on the JVM. The JDK contains the tools used to build Java software, while the JVM executes it. In Lesson 2, you will install a JDK and verify that the development tools work.