.NET/Mono 还是 Java 是跨平台开发的更好选择?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/61559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 07:48:05  来源:igfitidea点击:

Is .NET/Mono or Java the better choice for cross-platform development?

java.netlinuxmonocross-platform

提问by Hanno Fietz

How much less libraries are there for Mono than for Java?

Mono 的库比 Java 少多少?

I lack the overview over both alternatives but I have pretty much freedom of choice for my next project. I'm looking for hard technical facts in the areas of

我缺乏对这两种选择的概述,但我对下一个项目有很大的选择自由。我正在寻找以下领域的硬技术事实

  • performance (for example, I'm told Java is good for threading, and I hear the runtime code optimization has become very good recently for .NET)
  • real worldportability (it's both meant to be portable, what's Catch-22 for each?)
  • tool availability (CI, build automation, debugging, IDE)
  • 性能(例如,我听说 Java 适合线程处理,我听说最近对 .NET 的运行时代码优化变得非常好)
  • 现实世界的便携性(它都意味着便携,每个 Catch-22 是什么?)
  • 工具可用性(CI、构建自动化、调试、IDE)

I am especially looking for what you actually experienced in your own work rather than the things I could google. My application would be a back-end service processing large amounts of data from time series.

我特别在寻找你在自己的工作中实际经历过的东西,而不是我可以谷歌搜索的东西。我的应用程序将是处理来自时间序列的大量数据的后端服务。

My main target platform would be Linux.

我的主要目标平台是 Linux。

Edit:To phrase my question more adequately, I am interested in the whole package (3rd party libraries etc.), not just the language. For libraries, that probably boils down to the question "how much less libraries are there for Mono than for Java"?

编辑:为了更充分地表达我的问题,我对整个包(第 3 方库等)感兴趣,而不仅仅是语言。对于库,这可能归结为“Mono 的库比 Java 少多少”的问题?



FYI, I have since chosen Java for this project, because it seemed just more battle-worn on the portability side and it's been around for a while on older systems, too. I'm a tiny little bit sad about it, because I'm very curious about C# and I'd love to have done some large project in it, but maybe next time. Thanks for all the advice.

仅供参考,此后我为这个项目选择了 Java,因为它在可移植性方面似乎更加经久不衰,而且它在旧系统上也已经存在一段时间了。我对此有点难过,因为我对 C# 很好奇,我很想用它做一些大型项目,但也许下次吧。感谢所有的建议。

采纳答案by Ben Collins

Well....Java is actually more portable. Mono isn't implemented everywhere, and it lags behind the Microsoft implementation significantly. The Java SDK seems to stay in better sync across platforms (and it works on more platforms).

嗯....Java 实际上更便携。Mono 并未在任何地方实现,而且它明显落后于 Microsoft 的实现。Java SDK 似乎可以更好地跨平台同步(并且可以在更多平台上运行)。

I'd also say Java has more tool availability across all those platforms, although there are plenty of tools available for .NET on Windows platforms.

我还要说 Java 在所有这些平台上都有更多的工具可用性,尽管在 Windows 平台上有很多可用于 .NET 的工具。

Update for 2014

2014 年更新

I still hold this opinion in 2014. However, I'll qualify this by saying I'm just now starting to pay some attention to Mono after a long while of not really caring, so there may be improvements in the Mono runtime (or ecosystem) that I haven't been made aware of. AFAIK, there is still no support for WPF, WCF, WF, of WIF. Mono can run on iOS, but to my knowledge, the Java runtime still runs on far more platforms than Mono. Also, Mono is starting to see some much improved tooling (Xamarin), and Microsoft seems to have a much more cross-platform kind of attitude and willingness to work with partners to make them complimentary, rather than competitive (for example, Mono will be a pretty important part of the upcoming OWIN/Helios ASP.NET landscape). I suspect that in the coming years the differences in portability will lessen rapidly, especially after .NET being open-sourced.

我在 2014 年仍然持有这个观点。但是,我将通过说我刚刚开始关注 Mono 在很长一段时间没有真正关心之后才开始关注这一点,因此 Mono 运行时(或生态系统)可能会有改进) 我还没有意识到。AFAIK,仍然不支持 WPF、WCF、WF、WIF。Mono 可以在 iOS 上运行,但据我所知,Java 运行时仍然可以在比 Mono 多得多的平台上运行。此外,Mono 开始看到一些大大改进的工具 (Xamarin),而且微软似乎有一种更加跨平台的态度和愿意与合作伙伴合作,使他们成为互补的,而不是具有竞争力的(例如,Mono 将成为即将到来的 OWIN/Helios ASP.NET 格局的一个非常重要的部分)。我怀疑在未来几年,便携性的差异会迅速缩小,

Update for 2018

2018 年更新

My view on this is starting to go the other way. I think .NET, broadly, particularly with .NET Core, has started to achieve "portability parity" with Java. There are efforts underway to bring WPF to .NET Core for some platforms, and .NET Core itself runs on a great many platforms now. Mono (owned by Xamarin, which is now owned by Microsoft) is a more mature and polished product than ever, and writing applications that work on multiple platforms is no longer the domain of deep gnosis of .NET hackery, but is a relatively straightforward endeavor. There are, of course, libraries and services and applications that are Windows-only or can only target specific platforms - but the same can be said of Java (broadly).

我对此的看法开始相反。我认为 .NET,尤其是 .NET Core,已经开始与 Java 实现“可移植性平等”。正在努力将 WPF 引入某些平台的 .NET Core,并且 .NET Core 本身现在可以在许多平台上运行。Mono(归 Xamarin 所有,现在归 Microsoft 所有)是比以往任何时候都更加成熟和精美的产品,编写可在多个平台上运行的应用程序不再是 .NET 黑客的深入知识领域,而是一项相对简单的工作. 当然,有些库、服务和应用程序仅适用于 Windows 或只能针对特定平台——但 Java(广义上)也是如此。

If I were in the OP's shoes at this point, I can think of no reason inherent in the languages or tech stacks themselves that would prevent me from choosing .NET for any application going forward from this point.

如果此时我站在 OP 的立场上,我想不出语言或技术堆栈本身固有的任何原因会阻止我为从现在开始的任何应用程序选择 .NET。

回答by Brad Wilson

I think the question is phrased incorrectly. C# vs. Java is much less interesting in terms of cross-platform usage than is (a) which platforms you need to support, and (b) considering the core libraries and available third party libraries. The language is almost the least important part of the decision-making process.

我认为这个问题的措辞不正确。C# 与 Java 在跨平台使用方面的吸引力远不如 (a) 您需要支持哪些平台,以及 (b) 考虑核心库和可用的第三方库。语言几乎是决策过程中最不重要的部分。

回答by jodonnell

Java actually is as cross-platform as everyone says it is. There's a JVM implementation for just about any mainstream OS out there (even Mac OS X, finally), and they all work really well. And there's tons of open source tools out there that are just as cross platform.

Java 实际上就像每个人所说的那样跨平台。几乎所有主流操作系统都有一个 JVM 实现(最终甚至是 Mac OS X),而且它们都运行良好。并且有大量的开源工具可以跨平台使用。

The only catch is that there are certain native operations you can't do in Java without writing some DLLs or SOs. It's very rare that these come up in practice. In all those cases, though, I've been able to get around it by spawning native processes and screen-scraping the results.

唯一的问题是,如果不编写一些 DLL 或 SO,就无法在 Java 中执行某些本机操作。这些在实践中出现是非常罕见的。不过,在所有这些情况下,我已经能够通过生成本机进程和屏幕抓取结果来解决它。

回答by GEOCHET

I actually develop in .NET, run all my tests first on Mono, and then on Windows. That way I know my applications are cross platform. I have done this very successfully on both ASP.NET and Winforms applications.

我实际上是在 .NET 中开发的,首先在 Mono 上运行我的所有测试,然后在 Windows 上运行。这样我就知道我的应用程序是跨平台的。我在 ASP.NET 和 Winforms 应用程序上都非常成功地做到了这一点。

I am not really sure where some people get the impression Mono is so horrible from, but it certainly has done it's job in my cases and opinions.It is true you will have a bit of lag for the latest and greatest inventions in the .NET world, but so far, .NET 2.0 on Windows and Linux is very solid for me.

我不太确定有些人从哪里得到 Mono 如此可怕的印象,但它确实在我的案例和意见中完成了它的工作。确实,对于 .NET 中最新和最伟大的发明,您会有些滞后世界,但到目前为止,Windows 和 Linux 上的 .NET 2.0 对我来说非常可靠。

Keep in mind there are obviously many quirks to this, but most of them come from making sure you are writing portable code. While the frameworks do a great job of abstracting away what OS you are running on, little things like Linux's case sensitivity in paths and file names takes a bit of getting used to, as do things like permissions.

请记住,这显然有很多怪癖,但其中大部分来自确保您正在编写可移植的代码。虽然这些框架在抽象出你正在运行的操作系统方面做得很好,但是像 Linux 在路径和文件名中区分大小写这样的小事情需要一点时间来适应,权限之类的事情也是如此。

.NET is definitely very cross platform due to Mono based on my experiences so far.

根据我目前的经验,由于 Mono,.NET 绝对是非常跨平台的。

回答by AlexeyMK

Java was designed to be cross-platform; C#/.Net wasn't. When in doubt, use the tool that was designed for your purpose.

Java 被设计为跨平台的;C#/.Net 不是。如有疑问,请使用专为您设计的工具。

EDIT: in fairness, .NET was designed to work on embedded/PC/Server environments, so that's SORT of cross-platform. But it wasn't designed for Linux.

编辑:公平地说,.NET 被设计用于嵌入式/PC/服务器环境,所以这是跨平台的排序。但它不是为 Linux 设计的。

回答by warren_s

I'm going to say Java as well. If you look at it in terms of maturity, a lot more time and effort has been expended by Sun (and others) in getting the JVM to work on non-Windows platforms.

我还要说Java。如果从成熟度的角度来看,Sun(和其他公司)已经花费了更多的时间和精力来让 JVM 在非 Windows 平台上工作。

In contrast, Mono is definitely a second class citizen in the .NET ecosystem.

相比之下,Mono 绝对是 .NET 生态系统中的二等公民。

Depending on who your target customers are, you may also find there is real pushback against using Mono - does Novell offer the same kind of vendor support for Mono that you would get for Java or .NET on Windows?

根据您的目标客户是谁,您可能还会发现使用 Mono 确实存在阻力——Novell 是否为 Mono 提供了与 Windows 上的 Java 或 .NET 相同的供应商支持?

If you were primarily targeting hosting your service on Windows, it would make sense to be considering this choice, but since you're targeting Linux primarily, it seems like kind of a no-brainer to me.

如果您的主要目标是在 Windows 上托管您的服务,那么考虑这个选择是有意义的,但由于您主要针对 Linux,这对我来说似乎是一种明智的选择。

回答by George V. Reilly

There are other language choices too. I've become quite fond of Python, which works well on Windows, Linux, and Mac, and has a rich set of libraries.

还有其他语言选择。我非常喜欢 Python,它在 Windows、Linux 和 Mac 上运行良好,并且拥有丰富的库集。

回答by George V. Reilly

I would vote for Java being more portable than C#. Java definitely also has a very rich set of standard libraries. There is also a broad set of open source 3rd party libraries out there such as those provided by the Jakarta project (http://jakarta.apache.org/).

我会投票支持 Java 比 C# 更可移植。Java 肯定也有一套非常丰富的标准库。还有一系列广泛的开源 3rd 方库,例如 Jakarta 项目 ( http://jakarta.apache.org/)提供的库。

All the usual suspects exist for CI, Unit testing, etc too. Cross platform IDE support is also very good with the likes of Eclipse, Netbeans, IntelliJ IDEA etc.

CI、单元测试等也存在所有常见的嫌疑人。跨平台 IDE 支持也很好,例如 Eclipse、Netbeans、IntelliJ IDEA 等。

回答by Kendall Helmstetter Gelner

To add a bit more to the conversation, Java is more portable if you remain about one version behind - Java 5 still has many excellent features so you can wait for Java 6 and still have a lot of range in terms of language and libraries to develop with. The Mac is the primary platform that can take some time to catch up to the latest Java version.

再补充一点,如果你落后大约一个版本,Java 会更具有可移植性——Java 5 仍然有许多优秀的特性,所以你可以等待 Java 6 并且在语言和库方面仍然有很多可以开发的范围和。Mac 是主要平台,可能需要一些时间才能赶上最新的 Java 版本。

Java also has an excellent standards bodythat intelligently grows the platform based on input from many different companies. This is an oft overlooked feature but it keeps even new features working well across multiple platforms and provides a lot of range in library support for some esoteric things (as optional extensions).

Java 也有一个优秀的标准机构,可以根据许多不同公司的意见智能地发展平台。这是一个经常被忽视的功能,但它使新功能在多个平台上都能正常运行,并为一些深奥的东西(作为可选扩展)提供了大量的库支持。

回答by Swaroop C H

I've been asking the same question off-late and IMHO, .NET/Mono seems to be a better option simply because Mono has a great track record for cross-platform desktop applications(as opposed to Java) and of course, Mono is improving by leaps and boundsthese days.

我最近一直在问同样的问题,恕我直言,.NET/Mono 似乎是一个更好的选择,因为Mono 在跨平台桌面应用程序(与 Java 相对)方面有着出色的记录,当然,Mono 是这些天突飞猛进地改进