Python is everywhere now. It’s in the AI tutorials you read, in every LLM SDK’s examples, and in the code your AI assistant writes when you ask it for “a quick script”. As a Java developer, you can read most of it. But then a line like if not docs: or @app.post("/chat") stops you, and you’re not sure what it really does.
Here’s the good news: you don’t need to learn Python from zero. You already know variables, loops, classes, collections, exceptions and packages. Python has all of them. What changed is mostly the ceremony around them.
This article is the map. It lists the ten differences that matter, shows each one side by side, and tells you where the traps are. The rest of the Python for Java Developers series takes them one at a time.
The same program, twice
Here is a complete program in both languages:
// Java · Hello.java
public class Hello {
public static void main(String[] args) {
String name = "Java developer";
System.out.println("Hello, " + name + "!");
}
}# Python · hello.py
name = "Java developer"
print(f"Hello, {name}!")Run the Python one with python hello.py. No class, no main method, no compile step. Python reads the file from top to bottom and runs each line.
The 10 differences at a glance
| # | Java | Python |
|---|---|---|
| 1 | You compile, then run | You just run the file |
| 2 | Types on variables: int count = 0; |
Types on values: count = 0 |
| 3 | Blocks use { } |
Blocks use a colon and indentation |
| 4 | Statements end with ; |
A line ends the statement |
| 5 | Everything lives in a class | Functions can live on their own |
| 6 | ArrayList, HashMap imported |
list, dict built in, with literals |
| 7 | Overloading and builders | Default and keyword arguments |
| 8 | private, public keywords |
A naming convention: _name |
| 9 | Checked exceptions | No checked exceptions |
| 10 | Maven or Gradle | pip or uv, one virtual environment per project |
Let’s go through them.
1. You run the file, not a build
In Java you compile .java into .class files, then run them on the JVM. In Python you run the source file directly:
python hello.py
Python does compile your code to bytecode too, but it does it for you, behind the scenes, every time you run. There is no separate build step to think about.
For learning, the best tool is the REPL, Python’s interactive shell. Type python in a terminal and try lines one by one. It’s like JShell, but you’ll actually use it every day.
2. Variables don’t have types. Values do
String model = "gpt";
int maxTokens = 500;
boolean stream = true;
String answer = null;model = "gpt"
max_tokens = 500
stream = True
answer = NoneA Python variable is just a name stuck on a value. The value knows its type; the name doesn’t. So x = 5 followed by x = "five" is legal. Notice also: True and None start with a capital letter, and Python names use snake_case, not camelCase.
This is the biggest mental shift, and it has a few traps (None, is vs ==, “truthy” values). Part 2 covers them: Python variables, None and truthiness.
3. Indentation is the syntax
In Java, indentation is for humans. In Python, indentation is the code. A colon opens a block, and the indented lines below it are the block:
if score > 0.8:
print("Relevant") # inside the if
keep = True # inside the if
print("Done") # outside: always runs
Use 4 spaces and never mix tabs with spaces. Your editor will do this for you if you let it.
4. No semicolons, no braces
A line ends a statement. Python accepts a stray ;, but nobody writes one. And braces mean something completely different in Python: {} is an empty dictionary (a map), not a block.
“Python didn’t remove the ideas you know. It removed the ceremony around them.”
5. Functions don’t need a class
In Java, every method lives inside a class. In Python, a file can hold plain functions:
public class Greeter {
public static String greet(String name) {
return "Hello, " + name;
}
}def greet(name):
return f"Hello, {name}"No access modifier, no static, no return type. A function with no return gives back None. Python has classes too, and you’ll use them, but you only reach for one when you need state and behaviour together.
6. Lists and dicts are built in
No imports, no new, no generics. Python’s collections have their own literal syntax:
models = ["small", "medium", "large"] # like ArrayList
user = {"name": "Asha", "plan": "pro"} # like HashMap
tags = {"ai", "java"} # like HashSet
point = (3, 4) # a tuple: a small fixed group
You’ll see list and dict in almost every Python file, especially a list of dicts, which is exactly what JSON looks like.
7. Keyword arguments replace overloading and builders
This one changes how APIs look. Python lets you give arguments default values and pass them by name:
def summarize(text, max_words=50, style="plain"):
...
summarize(article) # both defaults
summarize(article, style="bullets") # name the one you change
In Java you’d write three overloads or a builder. In Python, one function does it. That’s why every AI SDK call looks like this:
reply = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=500,
messages=messages,
)
Read it as a builder without the builder: each name=value sets one option.
8. Private is a promise, not a lock
Python has no private, protected or public. Instead, a leading underscore means “internal, please don’t touch”:
class Retriever:
def __init__(self):
self._cache = {} # internal by convention
Nothing stops someone from using _cache. It’s a signal to other developers, and every Python developer respects it.
9. No checked exceptions
try/catch becomes try/except, and throw becomes raise. Same idea, different words:
try {
result = callModel(prompt);
} catch (TimeoutException e) {
log.warn("Timed out", e);
}try:
result = call_model(prompt)
except TimeoutError as e:
print("Timed out:", e)But nothing forces you to catch anything. There are no checked exceptions and no throws clauses. That makes code shorter, and it means you have to think about failures yourself.
10. pip and a virtual environment instead of Maven
Maven keeps one shared cache in ~/.m2 and builds a classpath per project. Python installs packages into an environment. If you install everything globally, projects fight over versions. So the rule is: one virtual environment per project, always.
The modern tool for this is uv, which does Maven’s job (environment, dependencies, lock file) in one command:
uv init my-app
cd my-app
uv add requests
uv run main.py
pyproject.toml is Python’s pom.xml. Older projects use pip and a requirements.txt file instead.
What stays exactly the same
It’s worth saying what you don’t have to relearn:
- Classes, objects and inheritance. Python has them, with
selfin place ofthis. - Exceptions. Same model: raise, catch, clean up with
finally. - References. Variables point to objects, as in Java.
b = ashares one list, it doesn’t copy it. - Garbage collection. You never free memory yourself.
- Packages and imports. A folder of
.pyfiles is a package,importworks like you’d expect. - Your design sense. Small functions, clear names, separation of concerns. All of it transfers.
How to learn Python fast as a Java developer
- Don’t start from a beginner’s course. You’ll be bored by chapter two. Learn the differences, then read real code.
- Keep the REPL open. Type every example. It’s faster than any IDE run configuration.
- Read before you write. Open a Python project you care about (an SDK example, an AI tool) and explain each line to yourself.
- Use one bridge per idea, then let go. Map
dicttoHashMaponce, then think indict. Translating every line in your head slows you down. - Learn the traps on purpose. Most bugs Java developers write in Python come from a short, known list:
isvs==, truthiness, mutable default arguments, and forgetting a colon.
Key takeaways
- A Java developer already knows most of Python’s ideas. What changes is syntax and ceremony.
- Python files run top to bottom: no class, no
main, no build step. - Types belong to values, indentation is the block, and
{}is a dict. - Default and keyword arguments replace overloading and builders.
_namemeans private by convention, and there are no checked exceptions.- Use one virtual environment per project;
uvmakes it painless.
Frequently asked questions
Is Python easy to learn for a Java developer?
Yes, mostly. The concepts are the same, so you’re learning new syntax and a few new habits, not programming. The parts that take practice are dynamic typing, indentation, and Python-only features like comprehensions and decorators.
How long does it take a Java developer to learn Python?
Reading Python comfortably takes a few days of focused practice. Writing idiomatic Python, instead of Java in Python syntax, takes a few weeks of real use.
Is Python compiled or interpreted?
Both, like Java in a way. The standard Python (CPython) compiles your source to bytecode automatically and then interprets it. You never run a separate compile step.
Should Java developers learn Python for AI?
It helps a lot. You can build AI apps in Java, and this site’s Java for AI Engineers series shows how. But most AI examples, SDK docs and research code are in Python, so reading it fluently makes you faster in both languages.
Does Python have static types like Java?
Python has optional type hints (def embed(text: str) -> list[float]:), but Python itself doesn’t enforce them when the program runs. Tools like mypy and pyright check them before you run, similar to the Java compiler.
Next in the series: Python variables, None and truthiness, and the is vs == trap that catches every Java developer once.
Comments