原文链接:Python vs Java: Key Differences

Python and Java are two very different programming languages, but both can be useful tools for modern developers. If you are thinking about learning to program for the first time, then you might find Python easier to master. Python’s syntax is designed to be intuitive and its relative simplicity allows newbies to quickly start writing code for a variety of applications. While Java has a steeper learning curve, it is extremely useful for developing applications that will run on any platform.



Dynamic vs Static Typing 动态类型 vs. 静态类型

One of the biggest differences between Python and Java is the way that each language handles variables. Java forces you to define the type of a variable when you first declare it and will not allow you to change the type later in the program. This is known as static typing. In contrast, Python uses dynamic typing, which allows you to change the type of a variable, by replacing an integer with a string, for example.


Dynamic typing is easier for the novice programmer to get to grips with, because it means you can just use your variables as you want to without worrying too much about their types. However, many developers would argue that static typing reduces the risk of undetected errors plaguing your program. When variables do not need to be explicitly declared before you use them, it is easy to misspell a variable name and accidentally create a whole new variable.


Braces vs Indentation 括号 vs. 缩进

Python is unusual among programming languages in that it uses indentation to separate code into blocks. Java, like most other languages, uses curly braces to define the beginning and end of each function and class definition. The advantage of using indentation is that it forces you to set your program out in a way that is easy to read, and there is no chance of errors resulting from a missing brace.


Speed vs Portability 速度 vs. 可移植性

The great advantage of Java is that it can be used to create platform-independent applications. Any computer or mobile device that is able to run the Java virtual machine can run a Java application, whereas to run Python programs you need a compiler that can turn Python code into code that your particular operating system can understand. Thanks to the popularity of Java for web applications and simple desktop programs, most devices already have the Java virtual machine installed, so a Java programmer can be confident that their application will be usable by almost all users. The disadvantage of running inside a virtual machine is that Java programs run more slowly than Python programs.

Java的一个很大的好处就是它可用于开发平台独立的应用。任何可以运行Java虚拟机的电脑或者移动设备都可以运行Java的应用,而不管你在哪里运行Python的程序你都需要一个编译器来将Python代码转化为你特定的操作系统可理解的代码。归功于Java Web应用和简单桌面程序的流行,大部分设备已经安装了Java虚拟机,所以Java程序员可以自信的说他们的应用几乎对所有用户都可用。在虚拟机内运行程序的缺点是Java程序比Python的程序运行速度要慢。

Python vs Java: Which is Easier to Use? Python vs. Java 哪一个更加易学?

Most programmers agree that Python is an easier language for novice programmers to learn. You will progress faster if you are learning Python as a first language than Java. However, the popularity of Java means that learning this powerful language is essential if you want to develop apps for Android, for example.



如果您喜欢这篇博文,欢迎您捐赠书影博客: ,查看支付宝二维码