Tutorial details

Java to iOS Objective-C translation tool and runtime | App Code for Sale | Preview

Java to iOS Objective-C translation tool and runtime | Android Tutorial

Google recently released a new tool that makes porting Java code to iOS much easier

Overview PAGE TOP

If you work on a mobile app and you’re planning on developing it on Android and iOS, it may be less work for you to write it on Android first. Google recently released a new tool that makes porting Java code to iOS much easier. The project (j2objc) can be found here.

To give the program a quick test run, I ran it using this Java file:

1   public class hello {
2   public static void main(String[] args) {
3   System.out.println("To Objective C we go!");
4   }
5   }

After running the above code using j2objc, I received two files (as expected): the header file, hello.h, and the source file, hello.m. The source file looks like this:

01  //
02  // Generated by the J2ObjC translator. DO NOT EDIT!
03  // source: hello.java
04  //
05  // Created by Isaac on 10/18/12.
06  //
08  #import "IOSObjectArray.h"
09  #import "hello.h"
11  @implementation hello
13  @end
15  int main( int argc, const char *argv[] ) {
16  int exitCode = 0;
17  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
18  IOSObjectArray *args = J reEmulationMainArguments(argc, argv);
20  NSLog(@"%@", @"To Objective C we go!");
22  [pool release];
23  return exitCode;
24  }

J2Objc certainly has to make a few decisions when converting between the two languages. One is seen above, as System.out.printLn is converted to NSLog. Currently J2Objc can convert much of Java, including things like reflection and anonymous classes in Java. I imagine these kinds of decisions are made through the program.

Although the library can’t touch any specific Java code related to the Android APIs, it can handle anything written in pure Java. The tool certainly has potential, especially for converting standard java classes directly to their Objective C equivalent.

Reference PAGE TOP


0 Comments Leave a comment

Please login in order to leave a comment.

Newest first

to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.