Java vs Python – Syntax Comparison Chart
Concept Java Syntax Python Syntax
Print Output [Link]("Hello"); print("Hello")
Comments // single-line /* multi-line */ # single-line """multi-line"""
Variable int x = 10; x = 10
Declaration
Input Scanner sc = new Scanner([Link]); int x = int(input())
x = [Link]();
If Condition if(x > 0) { } else { } if x > 0: ... else: ...
Else-if else if(x > 5) elif x > 5:
Switch Case switch(x) { case 1: ... } match x: case 1: ...
For Loop for(int i=0; i<5; i++) for i in range(5):
While Loop while(x < 5) { } while x < 5:
Array/List int arr[] = {1,2,3}; arr = [1,2,3]
String String s = "Hello"; s = "Hello"
Length [Link]() len(s)
Function/Method int add(int a,int b){ return a+b; } def add(a,b): return a+b
Class class A { } class A:
Object Creation A obj = new A(); obj = A()
Constructor A(){ } def __init__(self):
Inheritance class B extends A class B(A):
Exception try { } catch(Exception e){ } try: ... except Exception as e:
Handling
Import Package import [Link].*; import math