Python与Java的主要区别

原文链接: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.

Python和Java是两种截然不同的编程语言,但两者对于现在的程序员来说都是十分有用的工具。如果你刚开始考虑学习编程,你可能会发现Python更加易学。Pyton的语法设计的非常直观,并且其相对的简单性让新手们可以快速上手写各种应用。而Java的学习曲线则更加陡峭,它非常适用于开发在各种平台上都可以运行的应用。

python-vs-java

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.

Python与Java之间最大的区别之一就是两种语言处理变量的方式。Java强迫你在第一次声明变量时定义其类型并且不允许你在后面的程序中更改它的类型。这就是所谓的静态类型。与之相对,Python使用的是动态类型,允许你改变一个变量的类型,例如可以把整型替换为字符串。

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.

Python与众多编程语言的不同之处还在于它使用缩进将代码分割成块。Java,像大部分其他语言一样,使用大括号定义函数和类定义的开头和结尾。使用缩进的好处在于它强迫你将你的程序写得比较易读,不会有缺括号导致错误的可能。

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.

大部分程序员同意Python对于新手程序员更加易学这一观点。如果你把Python作为第一门编程语言学习,你的进步速度会比首先学习Java要快。然而,Java的流行意味着学习这门强大的语言是必须的,比如说,假如你想要开发安卓应用程序的话。

本文链接:http://bookshadow.com/weblog/2014/05/17/python-vs-java-key-differences/
请尊重作者的劳动成果,转载请注明出处!书影博客保留对文章的所有权利。

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

Pingbacks已关闭。

暂无评论

张贴您的评论