Java Foundations · 8 min read · Beginner
Java Basics, Types & Strings
Write your first Java 21 class, distinguish primitives from reference types, and compare Strings safely with .equals().
What you'll learn
- Understand public class, main(String[] args), and System.out.println
- Distinguish primitive types (int, double, boolean) from reference types (String)
- Compare Strings by value using .equals() instead of ==
Java is a strongly typed, object-oriented language that compiles to JVM bytecode and runs everywhere, from high-throughput Spring Boot microservices to Android apps.
Primitives vs. Reference Types
- Primitives (
int,long,double,boolean,char) store values directly. - Reference types (
String,List, custom classes) store object references. Always compareStringvalues with.equals(), because==compares memory references, not text content.
Fill-in-the-Blank Exercise
Java Entry Point & String Comparison
Print output and compare two String values safely.
String track = "Java";
if (track.("Java")) {
System.out.("Matched!");
}Interactive Code Lab
JavaMain.java
Expected OutputClick “Run Live” to compile with OpenJDK 21
Track: Java 21 (6 lessons, ready=true)
Check Your Understanding
Score: 0 / 1
1. Why should you compare Java Strings with .equals() instead of ==?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.