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.
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.
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.
I guess it only convert the java code u write, but it cant convert the android API. still need a little bit touching up manually to fully convert to Obj-C. But better than nothing for the moment.
I am having a completed java projet. and i downloaded j2objc also. i has some folders like include, lib, man and two j2objc file
How can I start with this
Good explanation. Do we have videos for the same?