Objective-C 和 Java,或者 iPhone 和 Android 之间有什么巨大的区别吗?

发布于 2024-09-11 14:24:21 字数 497 浏览 5 评论 0原文

编辑:我的错,我的意思是 Objective-C,而不是 C#。出于某种原因,我想到了 iPhone 使用的 C#。所以 c# 的答案很棒,谢谢,但它们有点无关紧要,对此感到抱歉。

我已经看过了,但找不到任何可以回答这个问题的东西,尽管有些人通过回答部分问题来缩短了问题。在一个小组中,我们计划在 iPhone 和 Android 上做一些工作,这两个平台大部分是分开的,但互相帮助,并且一些人在它们之间分担图形工作。

但我们正在考虑在两者之间移动事物的可能性,不一定是应用程序,也许只是有用的类或其他东西。看看 Objective-C 和 Java,它们似乎具有相同的功能,最大的障碍是系统接口的东西,所以我们想知道,如果我们在每个系统上创建一个抽象,以便它们可以得到相同的输入(除非我错了,否则不会给系统带来太大的压力?),编写在 Objective-C 和 Java 之间进行转换的东西是否会出现任何问题,比 sdks 中方法的位置更糟糕?或者一种语言中是否有另一种语言没有的关键功能或某些东西我们错过了,这意味着唯一的方法就是从头开始重写。

Edit: My bad, I meant objective-c, not c#. Some reason I got it into my head it was c# the iphone used. So the answers for c# were great, thanks, but theyre a bit irrelevant, sorry about that.

I've had a look but can't find anything that answers this, though a few have shortened the question by answering parts of it. Between a small group, we were planning on doing some work on iPhone and Android, the 2 seperate for the most part but helping each other out, and with some guys doing graphics work split between them.

But we were thinking about the possibilities of moving things between the two, not necessarily apps, maybe just useful classes or something. Looking at objective-c and Java, they seem to have about the same features that the biggest obstacle would be system interface stuff, so we were wondering whether, if we created an abstraction over these on each system so they could be given the same input (which unless I'm wrong wouldn't put too much strain on the system?), would there be any problems in writing something to convert between objective-c and Java, worse than the locations of methods in the sdks? Or are there key features or something in one language that the other doesn't have which we've missed that would mean the only way to do it would be rewriting from scratch.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

晚风撩人 2024-09-18 14:24:21

我不会浪费时间去寻找 iOS 和 Android 之间的共同点。

跨平台几乎总是浪费时间和资源,除非跨平台功能是应用程序功能的核心。对于 iPhone 和 Android 等具有定制操作系统并与硬件紧密配合的平台来说尤其如此。

从长远来看,跨平台开发环境会增加而不是降低复杂性。是的,这听起来很不错,但通常你很容易就得到了你想要的 90%,然后你就会遇到障碍,毁掉你所有的积蓄,然后开始让你陷入困境。只是有很多妥协和方钉塞进圆孔。

除非您的应用程序理论上可以在通用网页上运行,否则跨平台不适合您。

在 Objective-C 和 Java 的具体情况中,尽管 Java 是 Objective-C 的后代,但它们不具有现代的互操作性。您不能在另一方使用其中的代码。

您应该花时间学习每个平台的特定 API。没有捷径。

I wouldn't waste time trying to find commonality between iOS and Android.

Cross-platform is almost always a waste of time and resources unless the cross-platform capability is central to the apps functioning. That is especially true for platforms such as iPhone and Android which have custom OS and work very tightly with the hardware.

Cross-platform development environments add rather than reduce complexity long term. Yeah, it sounds neat but usually you get 90% what you want easily and then you hit a roadblock that destroys all the savings you made and then starts putting you in the hole. There are simply to many compromises and square pegs jammed into round holes.

Unless your app could in theory work from a generic web page, cross-platform is not for you.

In the specific case of Objective-C and Java, although Java is descended from Objective-C they have no modern interoperability. You can't use code from one on the other.

You should spend the time to learn each platform's specific API. There are no shortcuts.

小ぇ时光︴ 2024-09-18 14:24:21

XMLVM代号一iSpectrum告诉我们,您实际上可以将 Java 代码(从 Android 应用程序或从头开始创建)交叉编译为在 iPhone 上运行的 Objective-C 代码,而无需在 Apple 端安装任何虚拟机。

我建议观看使用 Java 开发 iPhone 应用程序

不幸的是Apple的许可证
iPhone SDK 协议禁止
Java虚拟机的移植
机到 iPhone。在这个
演示文稿中我们介绍了一个开放
来源Java-to-Objective-C
交叉编译器
以及基于Java的
Cocoa 库的实现。
借助这些工具,iPhone
应用程序可以用纯粹的语言编写
爪哇。使用Java版本的Cocoa,
可以运行基于Java的
作为 Java 的 iPhone 应用程序
桌面/小程序应用程序可以
交叉编译以在本机上运行
iPhone。演讲将讨论
Java 到 Objective-C 的挑战
交叉编译器以及
基于 Java 的 Cocoa 版本。细节
可在 http://www.xmlvm.org/

获取

,要了解更多信息,请参阅最近关于 Cross 的讨论- 从 2010 年 2 月起,可以将 Android 应用程序编译到 iPhone 此处,记录在 http://www.xmlvm。 org/android/

Android 是一个适用于移动设备的开源平台。由Google发起的Android系统备受关注。 Android 应用程序是使用 Java 开发的,尽管有一个特殊的编译器将类文件转换为专有的、基于寄存器的虚拟机,该虚拟机在 Android 设备上用于执行应用程序。 Android 定义了自己的 API 来编写移动应用程序。借助 XMLVM,可以将基于 Java 的 Android 应用程序交叉编译为本机 iPhone 应用程序。

Android应用程序是用
Java 并利用 Android
具体的API。 XMLVM 提供了
兼容性库,编写于
Java,提供与
Android,但仅使用
基于 Java 的 Cocoa Touch API。期间
交叉编译过程,两者
应用程序和 Android
兼容性库是
从 Java 交叉编译为
Objective-C 并与 Cocoa 联系起来
触摸兼容性库产生
本机 iPhone 应用程序。

摘自 2008 年有关为 iPhone 构建 Java 应用程序的讨论 http://www.xmlvm.org/iphone/:

苹果的iPhone已经产生了巨大的
用户和开发者的兴趣
一样。与 MacOS X 一样,iPhone
开发环境基于
Objective-C作为开发
GUI 语言和 Cocoa
图书馆。 iPhone SDK 许可证
协议不允许
虚拟机的开发。
使用 XMLVM,我们可以规避这个问题
通过交叉编译Java来解决这个问题
iPhone。就像 Java 应用程序一样
可以交叉编译为AJAX、XMLVM
可以用来交叉编译Java
在 Objective-C 中的应用。这
交叉编译也完成了
通过模仿基于堆栈的机器
Objective-C。

Tools like XMLVM, Codename One and iSpectrum tell us that you can actually cross-compile Java code (from an Android app or creating one from scratch) to Objective-C code that is running on an iPhone without having to install any virtual machine on the Apple side of things.

I suggest watching Developing iPhone Applications using Java

Unfortunately Apple's license
agreement for the iPhone SDK prohibits
the porting of the Java virtual
machine to the iPhone. In this
presentation we introduce an Open
Source Java-to-Objective-C
cross-compiler
as well as a Java-based
implementation of the Cocoa library.
With the help of these tools, iPhone
applications can be written in pure
Java. Using the Java version of Cocoa,
it is possible to run a Java-based
iPhone application as a Java
desktop/applet application that can be
cross-compiled to run natively on the
iPhone. The talk will discuss the
challenges of the Java-to-Objective-C
cross-compiler as well as the
Java-based version of Cocoa. Details
are available at http://www.xmlvm.org/

and for more insight a more recent talk about Cross-Compiling Android applications to the iPhone from Frebruary 2010 is available here, which is documented at http://www.xmlvm.org/android/ :

Android is an Open Source platform for mobile devices. Initiated by Google, Android has received much attention. Android applications are developed using Java, although a special compiler converts class files to a proprietary, register-based virtual machine that is used on Android devices to execute applications. Android defines its own API for writing mobile applications. With the help of XMLVM it is possible to cross-compile Java-based Android applications to native iPhone applications.

The Android application is written in
Java and makes use of an Android
specific API. XMLVM offers a
compatibility library, written in
Java, that offers the same API as
Android, but only makes use of the
Java-based API for Cocoa Touch. During
the cross-compilation process, both
the application and the Android
compatibility library are
cross-compiled from Java to
Objective-C and linked with the Cocoa
Touch compatibility library to yield a
native iPhone application.

From the 2008 talk about building Java applications for the iPhone http://www.xmlvm.org/iphone/ :

Apple's iPhone has generated huge
interest amongst users and developers
alike. Like MacOS X, the iPhone
development environment is based on
Objective-C as the development
language and Cocoa for the GUI
library. The iPhone SDK license
agreement does not permit the
development of a virtual machine.
Using XMLVM, we circumvent this
problem by cross-compiling Java to the
iPhone. Just like a Java application
can be cross-compiled to AJAX, XMLVM
can be used to cross-compile a Java
application to Objective-C. The
cross-compilation is also accomplished
by mimicking a stack-based machine in
Objective-C.

爱你是孤单的心事 2024-09-18 14:24:21

如果您专注于抽象系统交互之类的东西,并坚持使用语言的公共子集,那么您可能可以构建只需要很少或不需要修改即可从一种语言转移到另一种语言的类。

C# 确实比 Java 有更好的泛型实现,因为 C# 的泛型在运行时保留了强类型。

C# 也有 LINQ,据我所知,Java 中还没有等效的语言。 LINQ 提供了类似 SQL 的查询功能,该功能内置于该语言中并受到 .NET 框架的完全支持,它允许您查询对象集合,并且以非常函数式语言的方式执行此操作。一旦查询提供程序提供了可转换为其他格式的对象模型,查询提供程序就可以扩展 LINQ,使其能够与其他数据格式(例如 XML 和 SQL)一起使用。 LINQ 还使多核工作的并行化变得非常容易。这是语言能力的巨大扩展。

If you focus on abstracting away things like system interactions, and stick to the common subset of the languages, you can probably build classes that would require little or no modification to move from one language to the other.

C# does have a better implementation of generics than Java, in that C#'s generics retain strong typing at run-time.

C# also has LINQ, which as far as I know has no equivalent (yet) in Java. LINQ provides a SQL-like query capability, built into the language and fully supported by the .NET frameowrk, that lets you query object collections, and does so in a very functional-language style. LINQ can be extended by query providers to work with other data formats, such as XML and SQL, once the query provider provides an object model that translates to the other format. LINQ also makes parallelization very easy for multi-core work. It's a huge extension to language capability.

橙味迷妹 2024-09-18 14:24:21

这个话题通常充满了技术圣战的教条,所以我将在我的回答中尽量避开这一点。

根据我的经验,我在很大程度上同意人们的说法,尝试在两个平台之间共享代码会很困难。但是,有一些重要的例外:

我会考虑跨平台开发,其中您的业务逻辑

  • 非常重要;
  • 应跨平台标准化;并
  • 与外界(例如网络堆栈或 UI)有明确的交互。
  • (奖金)已经写好了。

鉴于现在臭名昭著的 3.3.1 对源代码语言的限制,Apple 是这里的速率决定步骤。您可以根据捆绑的 Webkit、C、C++ 和 Objective C 用 Ja​​vascript 编写代码。

如果您不想在 'droid 上安装额外的语言,您可以使用编译为 dalvik 代码的 Java,Javascript 如下webkit 或 NDK 的构建略有不同。然后你就会看到 C/C++。你可以交叉编译 Objective-C,但我没有这方面的经验。

将业务逻辑与 UI 和网络完全分离很重要,因为您将需要为网络层编写适配器,而为 UI 编写其他内容。

我不会尝试用 C/C++ 编写跨平台 UI 代码,并且会编写使用 HTML/CSS/JS 的代码,或者更可能编写完全自定义的代码以利用不同的 UI 隐喻在每个平台上 - 例如,iPhone 上没有类似的通知栏。 iPhone 上的动画比 Android 上的实现简单几个数量级。

如果您不需要 UI 与操作系统大规模集成,那么 webview 和一些 HTML5 可能就足够了。 Titanium 在这里是一个不错的选择,我的知情同事告诉我它比 PhoneGap 更好(即编译,而不是解释)。我又不知道。

与复杂性相反的是,Open GLES 在两个平台上都可用。

还应该指出的是,SVG 在当前的 Android 操作系统上不可用。

This topic is often filled with the dogma of technology jihadis, so I shall try and steer clear of that in my answer.

In my experience, I would largely agree with people saying that trying to share code between the two platforms would be difficult. However, there are some important exceptions:

I would consider cross-platform development where your business logic:

  • is non-trivial;
  • should be standardized across platforms; and
  • has well defined interactions with the outside world (e.g. network stack or UI).
  • (bonus) is written already.

Apple is the rate determining step here, given the now infamous 3.3.1 restrictions on source code languages. You can write code in Javascript according to the bundled Webkit, C, C++ and Objective C.

If you don't want to install extra languages on a 'droid, you can use the Java that compiles down to dalvik code, the Javascript as per the slightly different build of webkit or something from the NDK. Then you'll be looking at C/C++. You could cross-compile Objective-C, but I haven't had any experience of that.

The clean separation of business logic from UI and networking is important, as you'll be looking to write adapters for the networking layer, something else for the UI.

I would not attempt to write cross platform UI code in C/C++, and would either write something that used HTML/CSS/JS, or more likely write something completely custom to take advantage of the different UI metaphors on each platforms - e.g. there is no analogue to the notification bar on the iPhone. Animation on the iPhone is orders of magnitude simpler to implement than on Android.

If you don't need the UI to be massively integrated with the OS, then a webview and some HTML5 may be sufficient. Titanium is a good option here, and my colleagues in the know tell me it is better (i.e. compiles, not interpreted) than PhoneGap. Again I don't know.

Going the other way in complexity, Open GLES is available on both platforms.

It should also be noted that SVG is not available on the current crop of Android OSes.

初心 2024-09-18 14:24:21

如果你真的想做跨手机开发,只要它不是计算上非常昂贵的东西,我可能会选择 PhoneGap

PhoneGap 是一个用于构建跨平台移动应用程序的开源开发框架。使用 HTML 和 JavaScript 构建应用程序,并且仍然可以利用 iPhone/iTouch、iPad、Google Android、Palm、Symbian 和 Blackberry SDK 中的核心功能。

据我所知,它几乎是 iPhone 应用商店中唯一允许使用的跨平台工具包。

如果您对本机开发一心一意,我想您会发现除非您正在制作游戏并以 c 为目标,否则移植将需要大量工作。框架有很大不同,构建 UI 的方式也有很大不同。也就是说,要回答你关于 Objective-C 与 Java 的直接问题,它并没有那么糟糕。但它的不同之处在于,抽象工具并不那么容易——不像 Java 与 C#。例如,Objective-c 没有垃圾收集(无论如何在 iPhone 上),并且语法非常不同。 Objective-c 在方法调用(objective-c 中的消息)方面的类型更加松散。也就是说,它们在编程范式方面并没有太大不同。它们都是面向对象的命令式语言。它们都有类和方法,公共的和私有的。如果您想手动移植代码,那不会是世界末日,我只是认为您可能会花费更多时间来尝试构建抽象层。

If you actually want to do cross phone development, as long as it is not something really computationally expensive, I would probably go with PhoneGap.

PhoneGap is an open source development framework for building cross-platform mobile apps. Build apps in HTML and JavaScript and still take advantage of core features in iPhone/iTouch, iPad, Google Android, Palm, Symbian and Blackberry SDKs.

As far as I can tell, it's pretty much the only cross platform toolkit that is allowed in the iPhone app store.

If you're dead set on native development, I think you'll find that unless you're making a game and targeting c, it will be a lot of work to port. The frameworks are very different and the way of building UI is very different. That said, to answer you're direct question of objective-c vs. java, it's not that bad. It is different enough, though, that an abstraction tool would not be that easy - not like Java vs C#. Objective-c does not have garbage collection (on the iPhone anyway), for example, and the syntax is very different. Objective-c is more loosely typed in the way that it does method calls (messages in objective-c). That said, they aren't wildly different in terms of programming paradigms. They are both object oriented imperative languages. They both have classes and methods, public and private. If you wanted to port the code by hand, it wouldn't be the end of the world, I just think you might wind up spending a lot more time trying to build an abstraction layer.

烦人精 2024-09-18 14:24:21

如果您正在考虑进行 Android 开发,我最好的建议是选择 java。编写完整的抽象(假设您可以)层来从 C# 转换为 Java 没有任何好处。至于 iPhone 开发,不要怀疑使用 Objective-C 来达到同样的目的。

If you're thinking about doing Android development my best advice is to go for java. There is no benefit at all of writing a complete abstraction (assuming you can) layer to convert from C# to Java. As for the IPhone development dont doubt about using Objective-C for the same purpose.

遗失的美好 2024-09-18 14:24:21

您无法使用与 Android 相同的语言为 iPhone 进行开发。对于iPhone,你只能用Objective C 编程,它是Apple 开发的。你不能将它用于 Android,而进行 iPhone 开发的唯一方法是使用该语言(它在用户协议中)。

至于C#和Java,整个原理是不同的。 Java 是适用于所有平台的一种语言,.Net 是适用于每种语言的一种平台。它们不兼容。您可以在 Android 上使用 Java,但我不确定您是否也可以使用 C# (.Net)。

无论如何,您必须为这两个移动操作系统构建两个不同的应用程序。

You can't develop for the iPhone in the same language as for Android. For the iPhone, you can only program in Objective C, it's developed by Apple. You can't use it for android, and the only way to do iPhone development is with that language (it's in the user agreement).

As for C# vs. Java, the whole principle is different. Java is one language for every platform, .Net is one platform for every language. They are not compatible. You can use Java on Android, but I'm not sure if you can use C# (.Net) as well.

Anyway, you'll have to build two different apps for these two mobile operating systems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文