DEV Community

Cover image for Python vs Java: Don’t Choose Blindly — Here’s the Reality
Arul .A
Arul .A

Posted on

Python vs Java: Don’t Choose Blindly — Here’s the Reality

Python :

  • The Variables do not need type declarations.
x = 10          # no type declaration needed
x = "hello"     # can reassign to a different type
Enter fullscreen mode Exit fullscreen mode
  • The syntax uses indentation for code blocks.
def print():
    a=10
print("Hello, World!")
Enter fullscreen mode Exit fullscreen mode
  • Python supports standalone functions outside classes.
def greet(name):
    return f"Hi {name}"
Enter fullscreen mode Exit fullscreen mode

Java :

  • The java is strictly declare the data type before you create a variable.
int x = 10;         // type must be declared
// x = "hello";     // compile error!
Enter fullscreen mode Exit fullscreen mode
  • The Java uses curly braces .
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
Enter fullscreen mode Exit fullscreen mode
  • Java requires everything to be inside a class — no standalone functions
public class Greeter {
    public static String greet(String name) {
        return "Hi " + name;
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)