Java for Python Developers
Transfer Python experience to Java through typed values, control flow, collections, methods, and object contracts. Build a connected multi-file order processor and port a stock ledger.
Python and Java side by side
The same program in Python and in Java, from the lessons of this course.
Strings and Output
Python executes top-level statements; Java starts this example in the static main method of a class. A public class named Example belongs in Example.java. Java strings use double quotes; single quotes describe a single char. Concatenate strings with + or use…
Python1name = "Ada"2print(f"Hi {name}", "!")Java1import java.util.*;2import java.util.function.*;3import java.util.stream.*;4public class Example {5 6public static void main(String[] args) {7String name="Ada";System.out.println("Hi "+name+"!");8}9}String Equality
Python string equality compares contents with ==. In Java, == between references asks whether they refer to the same object. Use equals for string contents, or Objects.equals when either reference may be null. Interned literals can make a mistaken identity…
Python1a = "".join(["a", "b"])2b = "ab"3print(a == b)Java1import java.util.*;2import java.util.function.*;3import java.util.stream.*;4public class Example {5 6public static void main(String[] args) {7String a=new String("ab"),b=new String("ab");System.out.println(a.equals(b));System.out.println(a==b);8}9}Fixed-size Arrays
A Python list can grow and can contain heterogeneous values. A Java array has a fixed length and one component type. Its elements remain mutable even though its length cannot change. Read the length field with .length, not a method call. Access outside the…
Python1a = [2, 4, 6]2print(a[-1])Java1import java.util.*;2import java.util.function.*;3import java.util.stream.*;4public class Example {5 6public static void main(String[] args) {7int[]a={2,4,6};System.out.println(a[a.length-1]);8}9}While and Early Exit
Python and Java both provide break and continue, but Java requires a boolean loop condition. A Java while loop repeats while that condition remains true; update the state on every relevant path so a continue cannot accidentally prevent progress. An enhanced…
Python1words = ["tea", "", " ", "cake", "STOP", "later"]2for word in words:3 if word == "STOP":4 break5 if not word.strip():6 continue7 print(word)Java1public class Example {2 public static void main(String[] args) {3 String[] words = {"tea", "", " ", "cake", "STOP", "later"};4 for (String word : words) {5 if (word.equals("STOP")) {6 break;7 }8 if (word.trim().isEmpty()) {9 continue;10 }11 System.out.println(word);12 }13 }14}Static Methods and Returns
Python functions can live at module scope. Java places methods inside classes. A static method belongs to its class and does not require an instance receiver; an instance method acts on a particular object. Return types are part of method declarations, and a…
Python1def hours(total):2 return total // 603print(hours(125))Java1import java.util.*;2import java.util.function.*;3import java.util.stream.*;4public class Example {5static int hours(int total){return total/60;}6public static void main(String[] args) {7System.out.println(hours(125));8}9}Input and Exact Formatting
Python input returns a line without its trailing newline. The course Java driver uses BufferedReader.readLine for the same line-based shape, then passes the lines to your method. Integer.parseInt does not trim surrounding whitespace automatically, so trim…
Python1cents = 3052print(f"tea: {cents // 100}.{cents % 100:02d}")Java1import java.util.*;2import java.util.function.*;3import java.util.stream.*;4public class Example {5 6public static void main(String[] args) {7int cents=305;System.out.println(String.format(Locale.ROOT,"tea: %d.%02d",cents/100,cents%100));8}9}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsGetting Started in Java
6 lessonsValues and Decisions
5 lessonsCollections and References
5 lessonsIteration and Pipelines
5 lessonsMethods and Callbacks
5 lessonsInput, Errors, and Files
5 lessonsClasses and State
6 lessonsComposition and Contracts
5 lessonsProject: Order Processing
4 lessonsFinal Challenges
2 lessonsFrequently asked questions
Who is Java for Python Developers for?
For people who already write Python and want to learn Java. Each lesson starts from Python you know and shows how Java does the same thing, so you skip the beginner basics.
Do I need to know Java already?
No. The course starts with your first Java program. You need Python basics: variables, conditions, loops, functions and collections.
How many lessons does Java for Python Developers have?
Java for Python Developers contains 48 interactive lessons you can complete at your own pace.
What does Java for Python Developers cover?
The course is organized into chapters covering: Getting Started in Java, Values and Decisions, Collections and References, Iteration and Pipelines, and more.
Is Java for Python Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.