JPRO192
0% completed
A complete Java OOP roadmap

Learn Java from
first line to OOP.

Fourteen in-depth lessons, runnable examples, guided exercises, and quick quizzes. Learn at your own pace and keep your progress on this device.

16+ hours of guided learning
learners have visited this course
Student.javaJAVA
class Student {
  private String name;
  private double gpa;

  // Keep behavior close to data
  boolean isExcellent() {
    return gpa >= 8.0;
  }
}
Build successful 0.42s
14In-depth lessons
14Runnable examples
70+Practice requirements
100%Free to learn
Foundation 50 minutesLesson 1/14

Java Basics

Java is a statically typed language, which means every variable has a known type before the program runs. In this lesson, you will learn how a Java program is organized, how values are stored, and how expressions turn those values into useful results.

Learning objectives

  • Explain the role of a class and the main method
  • Choose suitable primitive and reference types
  • Create readable expressions with Java operators
CORE CONCEPTS

Build a strong mental model

01

The shape of a Java program

Java source code lives inside classes. The JVM starts a simple console program by calling public static void main(String[] args). Statements end with semicolons, and braces group statements into blocks. Java is case-sensitive, so score and Score are different names.

02

Variables and types

A variable combines a type, a name, and a value. Primitive types such as int, double, boolean, and char store simple values. Reference types such as String point to objects. Use descriptive camelCase names and prefer the narrowest type that correctly represents the data.

03

Operators and conversion

Arithmetic, comparison, and logical operators build expressions. Integer division removes the decimal part, while casting can request a conversion explicitly. Java also performs safe widening conversions, such as int to double, but rejects unsafe narrowing without a cast.

WORKED EXAMPLE

Read the code, understand the design

Main.java Java 21
public class StudentProfile {
    public static void main(String[] args) {
        String name = "Alex";
        int birthYear = 2005;
        double javaScore = 8.5;
        boolean passed = javaScore >= 5.0;

        int age = 2026 - birthYear;
        System.out.println(name + " is " + age + " years old.");
        System.out.println("Passed Java: " + passed);
    }
}

How this example works

  1. The variables use types that match the meaning of their values.
  2. The comparison javaScore >= 5.0 produces a boolean result.
  3. The + operator performs addition for numbers and concatenation when a String is involved.

Common mistakes to avoid

  • Using int when a value may contain decimals
  • Forgetting that integer division truncates the result
  • Using unclear names such as x or data in learning projects
PRACTICE

Build a console profile for a course student.

  • Store the student's name, student ID, Java score, and attendance percentage
  • Calculate whether the student passes: score >= 5 and attendance >= 80
  • Print a clear, multi-line summary
Stretch goal: Calculate how many additional points the student needs to reach a score of 8.0.
?
KNOWLEDGE CHECK

Which type is the best choice for a score such as 8.5?

1 question