Java vs Python

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

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

comparation

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.

时间: 2024-10-29 10:47:38

Java vs Python的相关文章

java与python在处理大文件操作上的对比

1.问题描述 现在对一个2g的大文件,抽取第二列含有特点16个串的信息,并将这些含有特串的信息,写回到两个文件中 2.具体实现 (1)java代码 package naifen; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java

fasttext的基本使用 java 、python为例子

fasttext的基本使用 java .python为例子 今天早上在地铁上看到知乎上看到有人使用fasttext进行文本分类,到公司试了下情况在GitHub上找了下,最开始是c++版本的实现,不过有Java.Python版本的实现了,正好拿下来试试手, python情况: python版本参考,作者提供了详细的实现,并且提供了中文分词之后的数据,正好拿下来用用,感谢作者,代码提供的数据作者都提供了,点后链接在上面有百度盘,可下载,java接口用到的数据也一样: [html] view plai

利用thrift在c++、java和python之间相互调用

转自:http://blog.csdn.net/andy_yf/article/details/7487384 thrift做为跨语言调用的方案有高效,支持语言较多,成熟等优点:代码侵入较强是其弱点. 下面记录以C++做服务器,C++,java和python做客户端的示例,这个和本人现在工作环境吻合,使用多线程长连接的socket来建立高效分布式系统的跨语言调用平台.遗憾的是目前版本(0.7.0)的C语言还不支持Compact协议,导致在现在的环境中nginx c module调用thrift要

ubuntu上用eclipse搭建java、python开发环境

上一篇文章讲到如何在windwos上用eclipse搭建java.python开发环境,这一讲将关注如何在ubuntu上实现搭建,本人使用虚拟机安装的ubuntu系统,系统版本为:14.04 lts 一.用eclipse + jdk搭建java开发环境 1.jdk官方下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html 本人下载的是:jdk-8u77-linux-x64.tar.gz

Java vs. Python (1): Simple Code Examples

Some developers have claimed that Python is more productive than Java. It is dangerous to make such a claim, because it may take several days to prove that thoroughly. From a high level view, Java is statically typed, which means all variable names h

C/C++、Java、Python谁是编译型语言,谁是解释型语言?

最近各大互联网公司线上笔试,编程题目里的编译器只支持C/C++.Java,甚至有的支持javaScrpit和Pascal,就是不支持Python.让一直以来用惯了Python的我直吐血,于是今天痛定思痛还是熟悉一下Java,免得继续被虐.学习的过程中,看到这样一个争论“Java.Python谁是编译型语言,谁是解释性语言?”.我在网上查了很多资料,也结合了自己的理解,下面与大家分享一下. 总的来说,如今编译型语言.解释性语言的分界线不再那么明显,应该避免把语言简单归类为“编译型”和“解释型”.

Java与Python下载Bing首页图片

Java与Python下载Bing首页图片 一,首先是Java代码 import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache

Java 和 Python 的 Socket 通信

网络上两个程序通过一个双向通讯连接实现数据的交换,这个双向链路的一端称为一个Socket.Socket支持的协议有多种,这里主要介绍基于 TCP/IP 协议族的 Socket 编程. 首先,IP协议族决定了socket的地址类型,在通信中必须采用对应的地址.AF_INET(AF 表示 Adress Family)表示要用 ipv4 地址(32位)与端口号(16位)的组合. 然后,根据传输协议又分为:流式 Socket(SOCK_STREAM) 和数据报式 Socket(SOCK_DGRAM):

Java集合-Python数据结构比较

Java list与Python list相比较 Java List:有序的,可重复的.(有序指的是集合中对象的顺序与添加顺序相同) Python list(列表)是有序的,可变的. Java List分类: ---ArrayList:底层使用数组,线程不安全,查找速度快,增删速度慢 在迭代过程中,对集合对象的增删会出现异常 ---LinkedList:底层使用链表,线程不安全,查找速度慢,增删速度快 后进先出,类似于栈 ---Vector:     底层使用数组,线程安全,查找速度快,增删速度