从Python切换到Java是个好主意吗?

将Python作为第一门编程语言的想法具有合理的背景。 首先,Python的语法简短明了,并且工作的对象和变量的基础模型完全一致。 这意味着您无需费力即可编写“真实的”且功能强大的应用程序。 因此,许多学校教学生使用Python进行编程并不奇怪。

但是,知道两种语言总比说一种更好。 如果您想学习Python之后的第二语言,那么Java可能是一个不错的选择。 在本文中,我们将讨论初学者软件开发人员从Python切换到Java的过程。

Why Java?

有很多不同的流行语言,例如C ++,C#,JavaScript…,学习任何一种都有利弊。 那么为什么要使用Java? 这里有一些想法。

  • 根据排名,Java是最受欢迎的语言之一。 因此,容易找到一份好工作。Java具有工业实力。 大型人员将其用于大型系统。 大公司需要大量初级软件开发人员。 因此,它是初学者友好的。Java是一种通用语言,您可以使用它来开发几乎所有类型的程序。 它具有几乎所有内容的库。 企业,移动,大数据,云服务,软件定义网络(SDN)等。如果您了解Java,那么学习复杂的语言(例如C ++)要比仅使用Python容易得多。Java是Android的本地语言,而Android是最受欢迎的移动平台。 因此,了解Java是进行移动软件开发的最简单方法。JVM(Java虚拟机)语言家族非常广泛且多种多样。 它不仅是Java,还包括现代的Groovy,Closure和Kotlin。 以及Ruby和Python特殊版本-JRuby和Jython。 如果您知道如何使用其本机语言Java与JVM一起使用,则与其他人一起使用会更容易。 Groovy或Kotlin在某种程度上可能是下一个重要的编程问题(但不会很快)。

Switching to Java… What to do?

1. Learn the basics of Java (Java Core)

您可以使用针对初学者的Java课程(对于您而言这将是快速而轻松的)或针对Python软件开发人员的Java课程。 例如:

  • Practical oriented course to learn Java — CodeGym. Learn Java on CodeGym means to solve a huge amount of coding tasks with fast automatic validation, tips, help and so on. Sure the lectures are also available, it is a complete course.
  • Javarevisited — it is a huge website with good articles, courses and interesting problems to solve.
Or elsewhere you may find these topics:
  • First of all read about this scary Java Syntax a little bit
  • Go and try to write easy coding tasks just to get used to your new life
  • Everything in Java is Object, so learn OOP
  • Learn Java Collections, they are really convenient
  • As well as tough but useful Java Multithreading ### 2. “Translate” your own projects from Python to Java. It could be easy coding tasks you did while your studying or your pet projects if you did them. Just rewrite it in Java. It is very useful. ### 3. Learn about JVM (for more advanced programmers) First, you may read some articles about JVM, Memory management, Garbage collection in Java:
  • How JVM Works — JVM Architecture?
  • Understanding JVM Internals There are some interesting courses about the topic. Such as:
  • Understanding the Java Virtual Machine: Memory Management
  • Understanding the Java Virtual Machine: Class loading and Reflection
  • Understanding the Java Virtual Machine: Security
  • Don’t forget to subscribe to Java’s StackOverflow and some Reddit communities, for example, learnjava. Use them! ## Before you start. “Progressive” Python vs “legacy” Java? I came across the opinion that Java is a relic of the past, and Python is modern and progressive very often. It’s funny, especially when you consider that Python is a little bit older than Java. Of course, Python overtook its time. You may say, Java “shot” immediately, became popular quickly, while Python did it very gradually, and only now began to catch up with Java in terms of prevalence. They both took serious changes through the years becoming better for modern programming and keeping their advantages. I want to say they both have strong and weak sides, and it is not about progressivity. Here I am going to describe real and the most important differences between the languages. ## The main difference: dynamically typed Python vs statically-typed Java Java is a statically typed, while Python is dynamically typed. This is the main difference between the topic’s languages. Technically it means that in Python you create your variables and don’t define their type. Types are defined only at runtime and the only condition for not having a runtime bug is to support the operations you used to the variables. So, if we have two objects such as Bird and Dog and give them a command to move fast before we run the program they are both the same. However, if we did everything right at runtime first will fly and the second will run. In Java, the Dog “knows” that it is a dog before runtime because it was defined by a programmer. You write more in Java while your computer has less work. ## Python laconic syntax vs Java verbose one Python was created keeping short syntax and readability in mind. Java is more about the strict structure and staying away from accidental mistakes. Classical example: Java
public class HelloWord
{
     public static void main (String[] args)
       {
           System.out.println(“Hello, world!”);
        }
}

蟒蛇

print “Hello, world!”

Interpreted Python and somewhat compiled Java

Java是一种编译语言,而Python是可解释的。 这样说是一种简化,但是这与事实很接近。

无论如何,执行期间都会在运行时解释Python代码。 Java代码在编译时被编译为JVM的字节码,然后JVM运行它。

Cross-Platform

Java虚拟机(JVM)是​​创建可移植的跨平台应用程序的强大工具。 这些应用程序可以在安装了JVM的任何设备上运行。 Python编译器将代码转换为取决于操作系统的特定机器代码。

Multithreading in Java and in Python

Java中的多线程实现比Python中更好(在这里我们谈论的是标准CPython)。 Python中的内存管理不是线程安全的,因此,该语言的实现会阻止Python字节码的多线程执行。

在Python中,存在全局解释器锁或GIL,并且此互斥锁可防止在Python中执行多个线程。 因此,Python唯一的多线程选项是访问IO资源。 因此,Python允许第二个线程的字节码执行,而第一个线程应等待来自网络或文件系统的数据。

Java进程成功使用了多个内核和超线程。 线程安全保证不是隐藏在语言内部,而是在许多线程安全工具中隐藏起来,以使其易于处理。

Backward compatibility

通常,编程语言的发展涉及向后兼容性。 但是,这并不完全适用于Python。 Python 2于2000年问世,Python 3于2008年问世。它们虽然差不多兼容,但是在功能和语法上有足够的差异,因此原则上可以将它们视为不同的语言。 Python 3并没有改变Python 2的新趋势和思想,而是被认为是一种新的语言,多少使用了Python 2的经验。Python2的开发单独继续进行,其最终实现(版本2.7)将仅支持到2020年。

创建Java时要牢记向后兼容性。 这是好事还是坏事? 这种方法导致了庞大的遗留代码库。 另一方面,可以逐渐更新这些古老的代码,并最大程度地降低了Java导致“老手”在现代环境中无法启动的风险。

So what?

我描述了一些主要差异,但几乎没有提及它们会导致什么。 在这一点上,我保证会修复它,并从软件开发人员的角度讨论这些差异会造成什么影响。

Coding Speed or Programmer Efficiency

语法越短,开发人员可以越快地编写它。 在Python中,您不应该编写所有这些括号和类,甚至不编写变量类型,因此……是的,Python程序员的工作速度比Java开发人员要快,尤其是在程序和脚本较短的小型团队中。 Java很冗长,但结构很好。 因此…

Сode support and analysis efficiency

…因此,Java代码的分析和支持比Python容易得多,尤其是在大型项目的情况下。 在Python中,缺乏类型信息使这种分析成为一个难题。 而且,Java提供了类型安全性,并在编译时(而不是在运行时)(如Python)捕获所有潜在的错误。 因此,错误的可能性趋于降低。 它极大地简化了大型应用程序的管理。 运行时错误比编译期间的错误更难以识别和修复。

Speed of program executing

就Python而言,您要做的更少,但是计算机要做的更多。 在Java中,与Python相比,一切都颠倒了。 因此,由于有了所有这些静态和编译功能,而不是动态类型和解释,Java的工作速度大大提高了。 这意味着您的Java程序将在较短的时间内执行,并且操作也将更快地运行。 对于用户而言,这并不总是那么明显。 但是,有时可能很关键。

Conclusions

专业软件开发人员并非总能选择要使用的工具。 时代在改变雇主的喜好,雇主的喜好可能会随之改变。 好消息是这些工具比看起来更相似。 即使在Python之后,Java似乎过于冗长,但Java是一种强大的功能。

from: https://dev.to//selawsky/is-switching-from-python-to-java-is-a-good-idea-1o5o

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值