java kotlin_Kotlin VS Java

java kotlin

当您考虑Android开发时,很容易想到一种编程语言,那就是Java。
自从Google在2017年宣布Kotlin作为Google IO上Android开发的官方语言以来,想要成为Android开发人员的程序员就陷入了困境。
他们面前最大的问题是他们应该学习Kotlin还是Java。
让我们来看看这两种语言

替代文字

Java

在Android应用程序开发中,Java是许多开发人员的最爱,主要是因为Android本身是用Java编写的。 Java是由Sun Microsystems(现在是Oracle的财产)开发的,是一种面向对象的编程语言,拥有GitHub第二活跃的语言的称号。 这也就不足为奇了-它已经存在了20多年,而且它的受欢迎程度似乎还在增长。

Java的优点

• Easy to learn and understand; 
• Flexible – you can run it in a browser window or a virtual machine. This comes in handy when you reuse code and update software; 
• A good choice for cross-platform apps; 
• Android relies on Java – the Android SDK contains many standard Java libraries; 
• Java has a large open-source ecosystem, partly as a result of Google's adoption of the Java Virtual Machine (JVM) for Android; 
• Accelerated assembly within Gradle – we're all thankful for it when assembling large projects; 
• Java apps are more compact – in comparison to Kotlin, Java apps tend to be lighter (even in full analogue); a Kotlin app that includes complex computing processes in its code can turn out to work slowly on user devices with low technical specs, if built by inexperienced developers; 
• Top development speed – Java ensures faster build process than Kotlin.

Java的缺点:-

• Java has limitations that cause problems with Android API design; 
• As a verbose language, Java requires writing more code, which carries a higher risk of errors and bugs; 
• It’s slower in comparison to many other languages and requires a lot of memory.

替代文字

Kotlin

Kotlin是由JetBrains(集成开发环境背后的人)的程序员设计的,目的是向Java添加一些在移动开发中很方便的现代功能。 Kotlin是基于Java虚拟机(JVM)的开源静态类型语言,但是您也可以将其编译为JavaScript或Native来构建可在iOS上运行的代码。 它所要做的就是安装Kotlin插件并让其配置您的项目。

Kotlin的优点:-

• Got a lot of traction in Android development, but it’s also being used in backend projects such as Spring 5; 
• Switching from Java to Kotlin is easy – just install the Kotlin plugin, add it to the Gradle build files, and click 'Convert'; 
• Includes smart extension functions to help devs build clean APIs; 
• Has null in its type system – nullability problems are a common pain point in Java, and since Android often uses null to represent the absence of a value, Kotlin solves it by placing null directly in its type system; 
• It's way more concise than Java, which means fewer opportunities for errors; 
• Inter operable with Java – you can write new modules in Kotlin and be sure they will work alongside the existing Java code; Kotlin is compatible with all Java libraries and frameworks, the JVM, and can integrate with the Gradle or Maven build systems; 
• Devs can benefit from the Anko library and over 2000 Kotlin projects on Github; 
• Adopting Kotlin doesn't cost anything (except for learning and training).

Kotlin的缺点:-

• Rather steep learning curve when switching entire teams to Kotlin due to the language's concise syntax (both a blessing and a challenge); 
• Slower compilation speed than Java (though Kotlin was shown to beat Java in some cases); 
• Small developer community, which means limited learning resources and difficulty in finding answers to questions; one look at Stackoverflow will give you a rough idea – there are only around 8000 questions tagged with Kotlin against 1.37 million questions about Java; 
• Experienced Kotlin devs are still a rarity, so finding a mentor for your team might be tricky; 
• Android Studio’s auto-complete and compilation tends to run slower in comparison to pure Java project.

所以让我们来解决主要问题

Kotlin会取代Java进行Android应用开发吗?

Kotlin发布后,网上有很多争论。 有人说Kotlin将在Android本机应用程序开发中完全取代Java。 以我的观点,不,尽管我真的很喜欢它,而且我喜欢它的方式。 但是我认为它不会完全取代Java来开发Android应用程序。
首先,在宣布使Kotlin成为用于编写Android应用程序的一流语言之后,Google在随后的主题演讲中指出,这只是一种附加语言,不能替代其现有的Java支持。
其次,让我们回顾一下Android上Kotlin支持的官方博客。
今天,在Google I / O主题演讲中,Android团队宣布了对Kotlin的一流支持。
关键字是“一流”。 我们应该怎样正确地理解这个词? 我认为这只是意味着Kotlin成为了Android的顶级语言支持之一(因此,至少从理论上讲,Kotlin不应在Android应用程序开发上超越Java)。
第三,Android Framework Layer的代码库由Java开发。 Android团队几乎不可能将整个框架移植到Kotlin上。 同时,Java通过JNI(Java本机接口)与C / C ++进行交互,到目前为止,Kotlin的行为相同。
最后,即使Kotlin有能力或显示出替换Java的趋势,这也是很长的路要走。 但是,对于我们的开发人员来说,学习有趣的新技术总是很不错的,更不用说像Kotlin这样的优秀编程语言了。

使用Kotlin或Java有什么区别吗?

新的Android语言有助于编写更安全的代码,因为只需花费较少的工作,就可以编写更可靠的代码。 当然,对于UX,这可以转化为具有较少错误和崩溃的应用程序。
尽管Java和Kotlin都是用于Android开发的语言,但两种编程语言之间还是有一些比较。 但是,Kotlin从许多方面来说都是干净的选择,它为应用程序创建者增加了许多很棒的功能。
收购Google语言的一个有趣的特征是Kotlin将继续由JetBrains开发和支持。 实际上,两家公司目前都在试图建立一个非营利性的Kotlin基金会来照顾这种语言。
Aaaaannnd结束之前

Kotlin适用于初学者,中级或高级

Android开发人员应该使用Java还是Kotlin?
这是最近应用程序开发人员经常问的一个问题,但这是您必须考虑的一些技巧。
首先,如果您已经决定成为一名Android开发人员,那么最好的办法就是开始或继续学习Java。
与Java相比,目前,学习Kotlin的资源很少。 继续学习Java,最终您将变得更有信心在以后使用Kotlin。
其次,如果您有足够的信心,则应该尝试Kotlin并开始享受用这种新语言创建更少的代码所带来的好处以及其他好处。
即使您不打算很快使用它,也至少要通过参与社区并最终开始将其实施到您的项目中来告知自己。
第三,如果您是高级开发人员,那么您应该已经加入了! 您会发现自己处在两种语言都可以使用的阶段,并且您有足够的知识来充分利用它们。
是否高级,每个Android开发人员都应该尝试一下Kotlin。 到目前为止,Java仍然是最流行的开发语言应用程序,但是,也请密切注意Kotlin,因为它肯定会在不久的将来发挥决定性作用。

所以Java或Kotlin

公平地说,您的团队中很可能已经有人熟悉Java。 一次将整个团队切换到Kotlin可能会有些令人震惊,因此,一次一次地缓慢完成此过渡非常重要。 话虽如此,Kotlin是一种新的官方语言,由于其现代性,将来会被广泛采用,因此现在学习和开始使用Kotlin是一个好主意。 尽管Java在很长一段时间内将继续成为一种流行的语言,并且不太可能被完全取代。 因此,请花点时间轻轻地进行开关。
归根结底,这就是您感到满意的地方。 就像我在一开始所说的那样,要成为一名真正的Androidian,您将需要具备Java的实用知识。 但是,如果您已经拥有了Kotlin,它将成为未来的语言,因此您不妨花一些时间来改善它。

替代文字

翻译自: https://dev.to/shubhamrattra/kotlin-vs-java-35a3

java kotlin

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值