我可以使用 Java 构建跨平台移动应用程序吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36213362/
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
Can I use Java for building cross-platform mobile apps?
提问by O Connor
I have read an article about Xamarin was buying RoboVM and enables developers to write mobile apps in Java for cross-platform. I am not sure if it is possible now to use Java for developing cross-platform mobile apps. Is there any reliable tools where I can write in Java for cross-platform mobile apps development? Is it a good choice to choose Java only for potential cross-platform mobile apps? I don't consider using C, C++, C# for that purpose since I have never been focusing on one of them. I apologize for the fans of those langauges. Or Is it a better choice that I better work with Java for Android apps and Swift for iOS apps? I plan to choose Java as a main language for all web apps, cross-platform mobile apps and robotic programming development.
我读过一篇关于 Xamarin 正在购买 RoboVM 并使开发人员能够使用 Java 编写跨平台移动应用程序的文章。我不确定现在是否可以使用 Java 来开发跨平台移动应用程序。是否有任何可靠的工具可以用 Java 编写用于跨平台移动应用程序开发?只为潜在的跨平台移动应用程序选择 Java 是否是一个不错的选择?我不考虑为此目的使用 C、C++、C#,因为我从未专注于其中之一。我为这些语言的粉丝道歉。或者我更好地使用 Java 用于 Android 应用程序和 Swift 用于 iOS 应用程序是更好的选择吗?我计划选择 Java 作为所有 Web 应用程序、跨平台移动应用程序和机器人编程开发的主要语言。
回答by Derek Johnson
I've been using Codename Onefor quite a while now. Libgdx wasn't exactly an option as I'm not a game developer.
我使用Codename One已经有一段时间了。Libgdx 不完全是一个选择,因为我不是游戏开发者。
I played a bit with RoboVM before picking Codename One and it seems that it's more about Java for iOS and not about WORA (Write Once Run Anywhere). This might be a good choice for you if that's what you want but I prefer WORA. I tried the RoboVM FX bindings and they were just horribly broken in basic ways.
在选择 Codename One 之前,我玩了一点 RoboVM,它似乎更多地是关于 iOS 的 Java 而不是 WORA(一次编写,随处运行)。如果这是您想要的,这对您来说可能是一个不错的选择,但我更喜欢 WORA。我尝试了 RoboVM FX 绑定,但它们的基本方式严重损坏。
A few things I love about Codename One are:
我喜欢代号一的一些事情是:
Support - I have never used a product with such amazing free support. You get answers within a day at the latest and that really sealed the deal for me.
No need for a Mac - I use my Mac at home but in the office I need a PC.
Customization and familiarity - this is pretty much Swing but WAY better. Like we always wanted Swing to be as they put it...
支持 - 我从未使用过具有如此惊人的免费支持的产品。您最迟会在一天内得到答案,这对我来说真的很重要。
不需要 Mac - 我在家使用 Mac,但在办公室我需要一台 PC。
自定义和熟悉 - 这几乎是 Swing,但更好。就像我们一直希望 Swing 像他们所说的那样......
The docs used to suck but they made a big push on it and it shows. Now if only they could fix the IntelliJ/IDEA plugin to the level of the NetBeans plugin I'd be golden!
文档过去很糟糕,但他们大力推动它并显示出来。现在,如果他们能够将 IntelliJ/IDEA 插件修复到 NetBeans 插件的级别,我会很高兴!
回答by Benoit Vanalderweireldt
As far as I know they are not compatible with Java, but they claim that if you know Java you'll be fine with C#.
据我所知,它们与 Java 不兼容,但他们声称,如果您了解 Java,您就可以使用 C#。
I found few interesting weirdfacts on their website about the transition... source
我在他们的网站上发现了一些关于过渡的有趣奇怪的事实......来源
- In Java, you can pass parameters only by value, while in C# you can pass by reference as well as by value. (C# provides the
ref
andout
keywords for passing parameters by reference; there is no equivalent to these in Java). - In a Java
switch
statement, code can fall through into the nextcase
section, but in C# the end of everyswitch
section must terminate theswitch
(the end of each section must close with abreak
statement). - ....
- 在 Java 中,只能按值传递参数,而在 C# 中,既可以按引用传递,也可以按值传递。(C# 提供了通过引用传递参数的
ref
和out
关键字;在 Java 中没有与这些等效的关键字)。 - 在 Java
switch
语句中,代码可以进入下case
一部分,但在 C# 中,每个switch
部分的结尾必须终止switch
(每个部分的结尾必须以break
语句结束)。 - ....
回答by dustinroepsch
Depending on what you're trying to write, libgdxmight be a good solution.
根据您尝试编写的内容,libgdx可能是一个不错的解决方案。
You write your code once in java and it compiles to basically everything (even html5!)
您在 java 中编写一次代码,它基本上可以编译为所有内容(甚至是 html5!)
You have to adhere to its coding conventions and use it's classes though. (Which are great for game development, not so much for other things... but you could still probably do whatever you want with it).
你必须遵守它的编码约定并使用它的类。(这对游戏开发来说非常有用,但对其他事情却没有那么多……但你仍然可以用它做任何你想做的事)。