Python → Java Glossary
Quick reference for the most common syntax differences.
Null / None
| Python | Java | Notes |
None | null | Null value |
if not x | if (x == null) | Null check |
x or y | x != null ? x : y | Null fallback |
Data Structures
| Python | Java | Notes |
dict | HashMap<K,V> | Key-value map |
set | HashSet<T> | Unique elements |
list | ArrayList<T> | Dynamic array |
deque | ArrayDeque<T> | Double-ended queue |
[] as stack | Stack<T> | LIFO stack |
deque | LinkedList<T> | Queue (FIFO) |
[0]*n | new int[n] | Fixed array |
[0]*n (list) | Arrays.fill(arr, 0) | Initialize |
String Operations
| Python | Java | Notes |
s[::-1] | new StringBuilder(s).reverse().toString() | Reverse string |
s == t | s.equals(t) | String equality — never use == in Java |
for c in s | for (char c : s.toCharArray()) | Iterate chars |
s[i] | s.charAt(i) | Access char |
s[i:j] | s.substring(i, j) | Slice string |
'x' * n | "x".repeat(n) | Repeat string (Java 11+) |
int(c) | c - '0' | Char to int digit |
ord(c) | (int) c | Char to ASCII |
str(n) | String.valueOf(n) | Int to string |
''.join(lst) | String.join("", list) | Join list |
Math & Numbers
| Python | Java | Notes |
float('inf') | Integer.MAX_VALUE | Positive infinity / max |
float('-inf') | Integer.MIN_VALUE | Negative infinity / min |
a // b | a / b | Integer division (both ints) |
a ** b | Math.pow(a, b) | Power |
abs(x) | Math.abs(x) | Absolute value |
max(a, b) | Math.max(a, b) | Max of two |
min(a, b) | Math.min(a, b) | Min of two |
divmod(a, b) | a/b, a%b | Quotient and remainder |
Control Flow
| Python | Java | Notes |
and | && | Logical AND |
or | || | Logical OR |
not | ! | Logical NOT |
True / False | true / false | Booleans (case sensitive) |
elif | else if | Else-if branch |
while True: ... break | do { ... } while (cond) | Do-while loop |
x if c else y | c ? x : y | Ternary expression |
a <= x < b | a <= x && x < b | Chained comparison |
Sorting
| Python | Java | Notes |
lst.sort() | Arrays.sort(arr) | In-place sort |
sorted(lst) | Arrays.sort(arr.clone()) | Returns new sorted |
lst.sort(key=fn) | Arrays.sort(arr, (a,b) -> ...) | Custom sort |
lst.sort(reverse=True) | Arrays.sort(arr, Collections.reverseOrder()) | Descending sort |
Class Definitions
| Python | Java | Notes |
def __init__(self) | ClassName() { } | Constructor |
self.x = y | this.x = y | Instance variable |
def method(self) | public void method() | Instance method |
isinstance(x, T) | x instanceof T | Type check |