java vs python_Java vs Python

面试时常问到这两种语言的区别,在此总结一下。

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

Dynamic vs Static Typing

Java: static typing

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.

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值