Guide for Java developers

Python for Java Developers: Learn Python Using What You Already Know

Already know Java? Discover how familiar programming concepts translate into Python, what works differently, and the fastest path to getting productive.

Java vs Python, side by side

Each pair below does the same job. Read the Java you know, then see how Python expresses it.

Variables, types and functions

Java
int total = 0;
String name = "Ada";

static int add(int a, int b) {
    return a + b;
}
Python
total = 0
name = "Ada"

def add(a: int, b: int) -> int:
    return a + b

Python has no type declarations: a name simply refers to a value. Type hints document intent and help editors and tools, but Python does not enforce them while the program runs.

Lists, maps and dictionaries

Java
List<String> langs = new ArrayList<>(List.of("Java", "Python"));
langs.add("SQL");

Map<String, Integer> ages = new HashMap<>();
ages.put("Ada", 36);
int age = ages.get("Ada");
Python
langs = ["Java", "Python"]
langs.append("SQL")

ages = {"Ada": 36}
age = ages["Ada"]

Lists and dictionaries are built into the language, with literal syntax and no imports or generics. Reading a missing key with [] raises KeyError; use ages.get(name) to get None instead, like Java's Map.get.

Loops and iteration

Java
for (int i = 0; i < names.size(); i++) {
    System.out.println(i + ": " + names.get(i));
}
Python
for i, name in enumerate(names):
    print(f"{i}: {name}")

Python loops over items directly. When you also need the position, enumerate gives you the index and the value together, so there is no counter to manage.

Classes and objects

Java
public class Point {
    private final int x;
    private final int y;

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public double distanceToOrigin() {
        return Math.sqrt(x * x + y * y);
    }
}
Python
import math

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def distance_to_origin(self):
        return math.hypot(self.x, self.y)

self is an explicit first parameter instead of an implicit this, and you create objects without new. Python has no access modifiers; a leading underscore, as in _x, marks something as internal by convention.

What Java developers need to unlearn

A few habits carry over badly. These shifts matter most.

  • Indentation is the syntax

    Blocks start with a colon and are defined by indentation instead of braces. Use four spaces and stay consistent.

  • Types are checked at runtime

    Dynamic typing means a name can refer to any value, and type errors appear when the line runs. Optional type hints plus a checker such as mypy bring back some of Java's safety.

  • Iterate over things, not indexes

    Loop over the collection itself. Reach for enumerate or zip before writing range(len(items)).

  • Lean on built-in collections

    Lists, dictionaries, sets and tuples cover most of what you import from java.util. A comprehension such as [len(w) for w in words] replaces a simple loop that builds a list; add an if at the end to filter.

  • Write Python, not Java in Python

    Skip getters, setters and one-method classes. Plain functions and modules are normal, and names use snake_case.

Your Java-to-Python learning roadmap

  1. Translate familiar concepts

    Map Java concepts to Python.

  2. Learn Python's differences

    Collections, functions, idiomatic style.

  3. Practice with real code

    Solve small problems, not just read.

  4. Build confidence

    Harder, more realistic challenges.

Hintor's Python for Developers track is designed for developers switching languages, with hands-on practice built into the lessons. Explore the Python for Developers track

Mini challenge

Given a list of integers, write Python code that creates a new list containing the squares of only the even numbers.

Input
[1, 2, 3, 4, 5, 6]
Expected output
[4, 16, 36]

Hint: a list comprehension can include an if filter, and n % 2 == 0 tests whether n is even.

Ready to Turn Your Java Knowledge into Python Skills?

You already know how to program. Now learn to think in Python with guided lessons and hands-on practice.

Start Learning Python on Hintor
Python for Java Developers | Learn Python Faster – Hintor