From 01c3026fff1ad7818a1970fc6cdc750ccffa0b70 Mon Sep 17 00:00:00 2001 From: DarkSun Date: Thu, 5 Dec 2019 00:58:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=80=89=E9=A2=98:=2020191204=20Java=20vs.?= =?UTF-8?q?=20Python:=20Which=20should=20you=20choose=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sources/tech/20191204 Java vs. Python- Which should you choose.md --- ...ava vs. Python- Which should you choose.md | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 sources/tech/20191204 Java vs. Python- Which should you choose.md diff --git a/sources/tech/20191204 Java vs. Python- Which should you choose.md b/sources/tech/20191204 Java vs. Python- Which should you choose.md new file mode 100644 index 0000000000..b8b38f494b --- /dev/null +++ b/sources/tech/20191204 Java vs. Python- Which should you choose.md @@ -0,0 +1,157 @@ +[#]: collector: (lujun9972) +[#]: translator: ( ) +[#]: reviewer: ( ) +[#]: publisher: ( ) +[#]: url: ( ) +[#]: subject: (Java vs. Python: Which should you choose?) +[#]: via: (https://opensource.com/article/19/12/java-vs-python) +[#]: author: (Archit Modi https://opensource.com/users/architmodi) + +Java vs. Python: Which should you choose? +====== +Compare the two most popular programming languages in the world, and let +us know which one you prefer in our poll. +![Developing code.][1] + +Let's compare the two most popular and powerful programming languages in the world: Java and Python! Both languages have huge community support and libraries to perform almost any programming task, although selecting a programming language usually depends on the developer's use case. After you compare and contrast, please make sure to answer our poll to [share your opinion][2] on which is best. + +### What is it? + + * **Java** is a general-purpose object-oriented programming language used mostly for developing a wide range of applications from mobile to web to enterprise apps. + * **Python** is a high-level object-oriented programming language used mostly for web development, artificial intelligence, machine learning, automation, and other data science applications. + + + +### Creator + + * **Java** was created by James Gosling (Sun Microsystems). + * **Python** was created by Guido van Rossum. + + + +### Open source status + + * **Java** is free and (mostly) open source except for corporate use. + * **Python** is free and open source for all use cases. + + + +### Platform dependencies + + * **Java** is platform-independent (although JVM isn't) per its WORA ("write once, run anywhere") philosophy. + * **Python** is platform-dependent. + + + +### Compiled or interpreted + + * **Java** is a compiled language. Java programs are translated to byte code at compile time and not runtime. + * **Python** is an interpreted language. Python programs are translated at runtime. + + + +### File creation + + * **Java**: After compilation, **<filename>.class** is generated. + * **Python**: During runtime, **<filename>.pyc** is created. + + + +### Errors types + + * **Java** has ****2 ****types of errors: compile and runtime errors. + * **Python** has 1 error type: traceback (or runtime) error. + + + +### Statically or dynamically typed + + * **Java** is statically typed. When initiating variables, their types need to be specified in the program because type checking is done at compile time. + * **Python** is dynamically typed. Variables don't need to have a type specified when initiated because type checking is done at runtime. + + + +### Syntax + + * **Java**: Every statement needs to end with a semicolon ( **;** ), and blocks of code are separated by curly braces ( **{}** ). + * **Python**: Blocks of code are separated by indentation (the user can choose how many white spaces to use, but it should be consistent throughout the block). + + + +### Number of classes + + * **Java**: Only one public top-level class can exist in a single file in Java. + * **Python**: Any number of classes can exist in a single file in Python. + + + +### More or less code? + + * **Java** generally involves writing more lines of code compared to Python. + * **Python** involves writing fewer lines of code compared to Java. + + + +### Multiple inheritance + + * **Java** does not support multiple inheritance (inheriting from two or more base classes) + * **Python** supports multiple inheritance although it is rarely implemented due to various issues like inheritance complexity, hierarchy, dependency issues, etc. + + + +### Multi-threading + + * **Java** multi-threading can support two or more concurrent threads running at the same time. + * **Python** uses a global interpreter lock (GIL), allowing only a single thread (CPU core) to run at a time. + + + +### Execution speed + + * **Java** is usually faster in execution time than Python. + * **Python** is usually slower in execution time than Java. + + + +### Hello world in Java + + +``` +public class Hello { +   public static void main([String][3][] args) { +      [System][4].out.println("Hello Opensource.com from Java!"); +   } +} +``` + +### Hello world in Python + + +``` +`print("Hello Opensource.com from Java!")` +``` + +### Run the programs + +![Java vs. Python][5] + +To run the java program "Hello.java" you need to compile it first which creates a "Hello.class" file. To run just the class name, use "java Hello." For Python, you would just run the file "python3 helloworld.py." + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/19/12/java-vs-python + +作者:[Archit Modi][a] +选题:[lujun9972][b] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/architmodi +[b]: https://github.com/lujun9972 +[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_development_programming.png?itok=M_QDcgz5 (Developing code.) +[2]: tmp.Bpi8QYfp8j#poll +[3]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+string +[4]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+system +[5]: https://opensource.com/sites/default/files/uploads/python-java-hello-world_0.png (Java vs. Python) From c18ea08d405720102b9528f13af46c75852c2890 Mon Sep 17 00:00:00 2001 From: "Xingyu.Wang" Date: Thu, 5 Dec 2019 07:06:17 +0800 Subject: [PATCH 2/2] Rename sources/tech/20191204 Java vs. Python- Which should you choose.md to sources/talk/20191204 Java vs. Python- Which should you choose.md --- .../20191204 Java vs. Python- Which should you choose.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sources/{tech => talk}/20191204 Java vs. Python- Which should you choose.md (100%) diff --git a/sources/tech/20191204 Java vs. Python- Which should you choose.md b/sources/talk/20191204 Java vs. Python- Which should you choose.md similarity index 100% rename from sources/tech/20191204 Java vs. Python- Which should you choose.md rename to sources/talk/20191204 Java vs. Python- Which should you choose.md