From Python to Java (or from Java to Python)

 

This site gives a quick overview of the differences and similarities between common programming idoms in Python and Java. Although it is intended for programmers who are making a transition from Python to Java, those who are making the move in the opposite direction can use it as well.


Python and Java programs both compile to machine-independent byte code, which can then be run on virtual machines (PVM and JVM, respectively) on host computers. Both languages support objects and classes, but Python, like C++, also allows the programmer to define free functions as well. Type checking in Java is done at compile time and in Python at run time. Python code can also be tried out interactively within an interpreter, whereas Java programs must flow through an edit/compile/execute cycle.

Program Structure and Execution

Programs and Their Execution

Running a Program

Example: Hello World!

Lexical Structure

Syntactical Structure

Program Comments

Data Types and Expressions

Primitive Types and Reference Types

Numeric Data Types

Strings and Characters

String Concatenation

Type Conversions

Arithmetic and Math Functions

Comparisons

Boolean Values and Logical Operators

Method Calls

Simple Statements

Import Statements

Variable Declarations and Typing

Assignment Statements

break, return, and Empty Statements

Terminal Input and Output

Terminal Output

Terminal Input

Control Statements

while Loops

for Loops

if Statements

Objects and Interfaces

Object Instantiation

Assignment, Parameters, and Casting

Interfaces

Collections

Strings

Arrays

Lists

Sets

Dictionaries or Maps

Iterators

Defining Classes

Class Structure

Visibility Modifiers

Instance Variables and Constructors

Defining Other Constructors

Instance Methods

Method Overloading

Class (static) Variables and Methods

Symbolic Constants (Final Variables)

Defining a String Representation

Defining Equality

Defining Comparisons

Defining Interfaces

Inner Classes

Defining an Iterator

Inheritance

Defining Subclasses

Abstract Classes and Methods