Java to iOS Objective-C translation tool and runtime

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:

 

 

 

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

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:

//
// Generated by the J2ObjC translator. DO NOT EDIT!
// source: hello.java
//
// Created by Isaac on 10/18/12.
//

#import "IOSObjectArray.h"
#import "hello.h"

@implementation hello

@end

int main( int argc, const char *argv[] ) {
int exitCode = 0;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
IOSObjectArray *args = J reEmulationMainArguments(argc, argv);

NSLog(@"%@", @"To Objective C we go!");

[pool release];
return exitCode;
}

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: A Reason to Write Android Apps First from our JCG partner Isaac Taylor at the Programming Mobile blog.

Related Whitepaper:

Rapid Android Development: Build Rich, Sensor-Based Applications with Processing

Create mobile apps for Android phones and tablets faster and more easily than you ever imagined

Use 'Processing', the free, award-winning, graphics-savvy language and development environment, to work with the touchscreens, hardware sensors, cameras, network transceivers, and other devices and software in the latest Android phones and tablets.

Get it Now!  

2 Responses to "Java to iOS Objective-C translation tool and runtime"

  1. harrita s says:

    Hi! i just want to know how to start with this. PLS PLS PLS help me.

    I am having a completed java projet. and i downloaded j2objc also. i has some folders like include, lib, man and two j2objc file. I just wan to know how to start? I know objective c xcode. so pls help me to start. where i should put my xxx.java file.

  2. Crushman says:

    This seems to only be able to translate Very generic java classes. have you been successful in translating more complicating java code? for example java code that uses jar file dependancies.

Leave a Reply


7 − = five



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books