Java vs Python
2015-11-07 04:03
483 查看
面试时常问到这两种语言的区别,在此总结一下。
Referrence: Udemy:python-vs-java
Generally, Python is much simpler to use, and more compact than Java. It is generally easier to learn, and more forgiving when it comes to using shortcuts like reusing an old variable. You will also need fewer lines to write code in Python than in Java, partly due to the removal of the braces. As a side-effect, Python code is a bit easier to read and understand than Java.
Python: dynamic typing
Java and Python differ in handling variables.
Java forces programmers to define the type of a variable when first declaring it. And Java will not allow you to cahnge the type later in the program.
Python allows programmers to change the type of a variable, like replacing an integer with a string.
Dynamic typing is easier for novice programmers.
But static typing can reduce the risk of undetected errors. 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.
Java, like most other languages, uses curly braces to define start and end of each funcation and class definition.
Advantage of using indentation:
1. Makes the program easy to read
2. Avoid errors resulting from a missing brace
Whereas to run Python programs you need a compiler that can turn Python code into code that your particular operating system can understand.
Because 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.
Referrence: Udemy:python-vs-java
Generally, Python is much simpler to use, and more compact than Java. It is generally easier to learn, and more forgiving when it comes to using shortcuts like reusing an old variable. You will also need fewer lines to write code in Python than in Java, partly due to the removal of the braces. As a side-effect, Python code is a bit easier to read and understand than Java.
Scripting Language vs Compiled Language
comparationDynamic vs Static Typing
Java: static typingPython: dynamic typing
Java and Python differ in handling variables.
Java forces programmers to define the type of a variable when first declaring it. And Java will not allow you to cahnge the type later in the program.
Python allows programmers to change the type of a variable, like replacing an integer with a string.
Dynamic typing is easier for novice programmers.
But static typing can reduce the risk of undetected errors. 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
Python uses indentation to separate code into blocks.Java, like most other languages, uses curly braces to define start and end of each funcation and class definition.
Advantage of using indentation:
1. Makes the program easy to read
2. Avoid errors resulting from a missing brace
Speed vs Portability
Java: "compile once, run everywhere" One major advantage of Java is that it can be used to create platform-independent applicaitons.Whereas to run Python programs you need a compiler that can turn Python code into code that your particular operating system can understand.
Because 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.
相关文章推荐
- 使用Python导出Excel图表以及到处为图片的方法
- Python的Flask框架中SQLAlchemy使用时的乱码问题解决
- 用Python的Flask框架结合MySQL些一个内存监控程序
- Vim与Python真乃天作之和
- python 学习爬虫教程~
- python 邮件发送 zabbix 图片
- Python多版本管理软件pyenv的安装应用及pip的使用讲解
- Python之对象的属性
- Python之闭包
- Python之str方法
- gevent For the Working Python Developer
- Python之L.pop()和del L[i]
- Python之L.reverse()和L.sort()
- python字符串格式化--dict传参
- 记录学习python装饰器
- python实现简单用户认证和角色制授权
- 基于Python的机器学习实战:KNN
- python第二课
- python操作Excel读写--使用xlrd和xlwt
- 4.2.2 编码和UNICODE