News for hackers. Stuff that matters.
Re:Google j2objc, a Java to iOS Objective-C translation tool... by swanson on Friday October 24, 2014 @09:58AM (#8503644)
I used this tool 2-3 years ago (back when it was still hosted on Google Code!). It does what it says on the box (converts code from Java to Obj-C) - the problem is all about expectations.

In a way, this being an "official" tool from Google makes it more confusing for non-technical folks. When you read that Google has released a tool for converting Java to Obj-C, many assume it's now trivial to get an Android app converted to iOS. This tool will not translate an Android app into iOS code. It won't really even help that much unless you've made a deliberate effort to isolate code so that a conversion could happen. Most of the time, the business logic for mobile apps is fairly simple so you aren't saving much time.

In my experience, the difficulty in shipping cross platform mobile apps is dealing with platform specific conventions (e.g. what is the iOS equivalent of a Fragment?) and libraries (RestKit on iOS, Retrofit on Android, etc); not the conversion of basic Java class into their Obj-C equivalents.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by on_and_off on Friday October 24, 2014 @02:30PM (#8505135)
Well, it does say so on the main page :) . I suspect that this warning is here so that devs can show it to the eager product managers ...

I am still not that convinced by this approach either though. Sure, that way you are sure that all your apps handle the business logic in the same way but since the platforms are so different, the cost of extracting the business logic can be pretty high for a low return.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by resca79 on Friday October 24, 2014 @05:33AM (#8502846)
While I appreciate the tecnological background of this project, I don't like this kind of traslators.

It could be useful if you need to execute Java code in Objective-c runtime, but not if you want develop iPhone/iPad app.

Obj-C is simple, the problems are the iOS frameworks that you need to learn to delivery an iOS App. If you are Java skilled, anyway you need to learn these frameworks, and you will spend your time to traslate the examples(stackoverflow) from obj-c to java

I'm not a xcode fans, but it is a great tool when you use the StoryBoard and all features to test, performance, memory .. etc.

Another point is that with the introduction of the Swift language this traslator loses other value

Re:Google j2objc, a Java to iOS Objective-C translation tool... by cromwellian on Friday October 24, 2014 @05:39AM (#8502858)
The purpose of j2objc is not to address a single platform. It's not to write code in Java in order to deliver an iOS only app. It's to share logic across multiple platforms.

If you combine j2objc and GWT together, you can share code between Web, native Android, and native iOS, while writing the UI in JS, Objective-C with InterfaceBuilder/Xcode, or native Android Views.

If you want to share non-UI code across all three platforms you have these kinds of choices:

* js everywhere (WebView wrapper or embedded JS interpreter on iOS) * C everywhere (emscripten/NaCl on WEB) * Java everywhere (GWT->js for Web, j2objc for iOS)

I can only speak from experience, but option three worked fantastically.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by matthewmacleod on Friday October 24, 2014 @05:51AM (#8502884)
I've often heard this idea about 'sharing logic across multiple platforms'.

I agree that it's a noble goal, but I'm curious about places where that sort of logic is actually common enough to justify the overhead of maintaining a cross-platform library.

Most of the applications on my phone are ultimately native UI skins over web services. There might be some logic in there to handle other features, but in most cases it's tied into OS-native features anyway.

I can see cross-platform libraries being useful for games using GL, maybe for media applications that require formats not supported by the OS, and for applications that do heavy image or audio processing – in short, the sort of thing where the value-add is specifically high-performance processing. Maybe that's enough to justify the existence of these tools, though I'd imagine it's almost always a better option to write your library in C in the first place.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by MarkMc on Friday October 24, 2014 @08:50AM (#8503379)
I think you're underestimating the amount of platform-independent code in a typical app.

Looking though a random sample of non-game apps on my iPad, I'd guess that about half would have a significant chunk of code which is not OS-specific, including: Gmail, Spotify, Anki, Google Maps, Facebook, Twitter, Penultimate.

I also don't think that the choice between C and Java as the common language is so clear cut. C would get you some speed benefit but Java has GWT for porting Java to Javascript, and and a huge range of other tools and libraries. In the end I think it would come down to how comfortable your development team was in each language.

(Disclaimer: I'm a Java developer)

Re:Google j2objc, a Java to iOS Objective-C translation tool... by RussianCow on Friday October 24, 2014 @11:01AM (#8503999)
> C would get you some speed benefit but Java has GWT for porting Java to Javascript

You can compile C to JavaScript with emscripten[0].

[0]: https://github.com/kripken/emscripten

Re:Google j2objc, a Java to iOS Objective-C translation tool... by cromwellian on Friday October 24, 2014 @11:45AM (#8504202)
Emscripten's good for games, but I don't think it's good for an app like Inbox.
Re:Google j2objc, a Java to iOS Objective-C translation tool... by cromwellian on Friday October 24, 2014 @06:26AM (#8502963)
Case in point: Inbox by Gmail. It is not just a thin skin over AJAX calls, but actually a fairly sophisticated client side application.
Re:Google j2objc, a Java to iOS Objective-C translation tool... by akrymski on Friday October 24, 2014 @07:42AM (#8503154)
> a fairly sophisticated client side application is it actually an full blown IMAP client? Most likely it uses AJAX to fetch JSON from Google's proprietary APIs
Re:Google j2objc, a Java to iOS Objective-C translation tool... by cromwellian on Friday October 24, 2014 @12:01PM (#8504270)
It works offline, that should give you a clue that it is not just a request/response app. Yes, it does make requests to Google's servers, but it can run completely offline with no connection as well.
Re:Google j2objc, a Java to iOS Objective-C translation tool... by betteringred on Friday October 24, 2014 @07:16AM (#8503084)
Does Google Inbox use J2ObjC? You seem to be alluding to that but not explicitly saying it.
Re:Google j2objc, a Java to iOS Objective-C translation tool... by bookwormAT on Friday October 24, 2014 @10:24AM (#8503786)
Google Inbox is indeed written in J2ObjC:

See https://groups.google.com/forum/#!topic/j2objc-discuss/5lMZN...

Re:Google j2objc, a Java to iOS Objective-C translation tool... by suchire on Friday October 24, 2014 @08:53AM (#8503394)
Dropbox has some mobile apps that have some fairl complex client-side logic with multithreading (https://tech.dropbox.com/2014/04/building-carousel-part-i-ho...), so they use a cross-platform C++ library with bindings to Obj-C and Java with their Djinni library (https://github.com/dropbox/djinni/)
Re:Google j2objc, a Java to iOS Objective-C translation tool... by king_jester on Friday October 24, 2014 @10:21AM (#8503766)
A lot of apps are just API consumers, but apps with any kind of moderately advanced functionality will require some kind of entity model and business rules that need to be captured. Having those things go out of sync between platforms can be a source of bugs or slower development. For shops invested in Java or with a lot of Java engineers, something like this can be be useful so that the entity model and business rules can be encapsulated in a single code base.
Re:Google j2objc, a Java to iOS Objective-C translation tool... by resca79 on Friday October 24, 2014 @05:53AM (#8502887)
Sharing the business logic makes sense, but I'm not confident that sharing code on web and mobile devices is a good point in terms of performance.

The UI in JS is simple to develop, but you have a lack of performance also

Re:Google j2objc, a Java to iOS Objective-C translation tool... by m_mueller on Friday October 24, 2014 @06:09AM (#8502918)
From my experience with servers-side JS code, if your JS is fast enough to run with every server request, it's also fast enough to run on today's mobile processors. Obviously for Client-side code this isn't true, but then again if you want your apps accessible from mobile browsers, you need to have it reasonably optimized anyway.
Re:Google j2objc, a Java to iOS Objective-C translation tool... by robmccoll on Friday October 24, 2014 @06:12AM (#8502925)
> Obj-C is simple

Yeah you just need to know C, possibly C++, and smalltalk and be comfortable using the syntaxes for all three simultaneously. For the record though I'm a big fan of C and C++, and I don't really care for Java. I can just see why people who already know Java well would want to use Obj-C as little as possible.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by duaneb on Friday October 24, 2014 @04:09PM (#8505682)
I would say smalltalk has little to do with LEARNING objective-c. The gist is:

* Message passing between objects. * A nil object that can accept messages without failing. * Duck typing. * A really shitty call syntax.

What more needs to be known?

Re:Google j2objc, a Java to iOS Objective-C translation tool... by tonysuper on Friday October 24, 2014 @10:31AM (#8503824)
I'd consider that fusion of paradigms to be a huge strength of the language.
Re:Google j2objc, a Java to iOS Objective-C translation tool... by resca79 on Friday October 24, 2014 @06:21AM (#8502950)
You don't need to learn 3 languages to be skilled in Obj-c

Just for one reason, there are many iOS developers in the world, and at the same time C++ and C developers are few today.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by andyjohnson0 on Friday October 24, 2014 @07:35AM (#8503140)
"... C++ and C developers are few today."

In a web/js/Ruby/mobile echochamber that may be true. But in the real world C/C++ is very far from being a minority skillset. Take a look at [1][2][3]. C, C++, and Java are the main languages in use today.

[1] http://www.tiobe.com/index.php/content/paperinfo/tpci/index....

[2] http://langpop.com

[3] http://lifehacker.com/the-top-programming-languages-ranked-b...

Re:Google j2objc, a Java to iOS Objective-C translation tool... by resca79 on Friday October 24, 2014 @07:49AM (#8503173)
You need look at the growing data. Maybe the number of people that know c or c++ are more for the ages of the languages itself. Try to look any statistics about github[1] [2]

[1] http://redmonk.com/dberkholz/2014/05/02/github-language-tren...

[2]http://sogrady-media.redmonk.com/sogrady/files/2014/02/repos...

Re:Google j2objc, a Java to iOS Objective-C translation tool... by kator on Friday October 24, 2014 @08:58AM (#8503408)
The bulk of Java/C/C++ source will never see the light of day as they power systems owned by corporations who see them as an asset.

Looking at public repos for stats is like counting the number of tables on planet earth by looking at satellite photos. You never see inside the buildings, just whats outside in parks etc.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by fwilliams on Friday October 24, 2014 @12:17PM (#8504365)
Let's take a brief moment to talk about systems software, and infrastructure.

It powers your OS, your VM instance running your flashy new CRUD app, your network protocols, your game engines, your browser, the interpreter or compiler you use to run your high level languages, and much, much more.

Programs such as these need high performance, low level access to hardware, or the ability to manage resources in a custom way. Languages like C, and C++ are very well suited for this. Sure, I wouldn't write a web-app in C++, but then again, I wouldn't write a javascript jit-compiler in javascript (okay maybe in asm.js for kicks).

Personally, when I see the growth of higher-level languages like these, I don't attribute it to the fall of low-level languages, but instead to the availability of new languages good for certain tasks.

In 2014, we have the luxury of being able to write applications at higher levels of abstraction, and this is a good thing. But tools like C, and C++ are still, and will be widely used by anybody who needs to develop something with requirements such as those I have mentioned. Layers of abstraction need to be built on top of something, and that something needs to work efficiently and quickly.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by pjmlp on Friday October 24, 2014 @07:16AM (#8503085)
If your imagine of the world is USA, maybe true.
Re:Google j2objc, a Java to iOS Objective-C translation tool... by sehugg on Friday October 24, 2014 @09:24AM (#8503493)
I'm using RoboVM for production apps, which uses LLVM and the Android runtime to compile Java into native iOS apps. Also binds easily to Objective-C frameworks (and the libGDX game framework).

http://www.robovm.com/

Re:Google j2objc, a Java to iOS Objective-C translation tool... by cromwellian on Friday October 24, 2014 @11:43AM (#8504194)
We've been working on Inbox for years, and RoboVM didn't exist when we started. I'm sure if it was as polished as it is now, we might have considered it.
Re:Google j2objc, a Java to iOS Objective-C translation tool... by philbarr on Friday October 24, 2014 @10:52AM (#8503941)
Agree RoboVM is awesome. I literally just opened my app up on a Mac, right click, run on simulator and it worked. Amazing!
Re:Google j2objc, a Java to iOS Objective-C translation tool... by sehugg on Friday October 24, 2014 @03:19PM (#8505413)
I've written up a few things about my experiences with RoboVM, including how to use native bindings:

http://blog.puzzlingplans.com/post/100847610651/building-a-c...

Re:Google j2objc, a Java to iOS Objective-C translation tool... by WoodenChair on Friday October 24, 2014 @01:07PM (#8504670)
I get it - Java people want to work in Java. However, this tool seems only targeted at the M in the MVC paradigm. You still need to write your views and controllers in Objective-C. Unless your app has a large number of very complex model objects, it's probably quicker to just retype your model classes in Objective-C. Of course if your app does have a lot of very complex model objects (as Google probably does) and you want to always have them in sync across platforms without having to retype anything then this makes a ton of sense. But for the majority of apps, it does not.
Re:Google j2objc, a Java to iOS Objective-C translation tool... by inDigiNeous on Friday October 24, 2014 @06:22AM (#8502951)
Just wanting to share a similar use case for such a project:

Used to work at a company where they were developing mobile games for 50+ different mobile phones, back when there was still more diversity in the market, just when iPhone was still rising to take over the markets.

The method they used at that time for developing their games was to write the project once with Java, then convert with an inhouse build tool to Objective-C++ when targetting iPhone. They even had builtin carbage collection and everything in the converter runtime, it seemed crazy that they would go to such trouble.

But they were releasing about 50+ games a year, a pretty big company, so I guess it paid back in writing the project once and porting to multiple platforms.

Took maybe 25 minutes to compile the whole thing, first from Java to Objective-C++ and then compiling that whole mess of a project in Xcode. It kinda worked, but the performance it produced on the iPhone was far from optimal. Debugging was also horrible.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by cromwellian on Friday October 24, 2014 @06:29AM (#8502975)
Sounds like the XMLVM hack which basically transplate Java bytecode into a stack machine emulator in C++ by using bytecode->XML and then XSLT stylesheets -> C++. As expected, this is slow. This is not what j2objc does, and j2objc doesn't try to emulate garbage collection either, instead it generates ARC compatible code, and you use @Weak annotations in Java to fix cycles.
Re:Google j2objc, a Java to iOS Objective-C translation tool... by anon4 on Friday October 24, 2014 @07:04AM (#8503049)
You seriously expect me to break cycles myself?

Edit: Furthermore, you expect me to carefully read the source of every single third-party library I use and patch it to break any potential cycles? This is madness!

Re:Google j2objc, a Java to iOS Objective-C translation tool... by cromwellian on Friday October 24, 2014 @11:46AM (#8504209)
Inbox is a huge app and very very few cycles need to be broken. J2ObjC provides an automated tool for finding them (https://code.google.com/p/j2objc/wiki/CycleFinderTool)

It's really no different than programming in ObjC itself where you can run into cycles.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by blisterpeanuts on Friday October 24, 2014 @10:22AM (#8503773)
Really nice tool. I haven't tried it on any non-trivial code yet but it worked well for a couple of small utility functions I use all the time. I know Java and I'm an ObjC learner, but I have to get some stuff working quickly and this might help short cut the process. I only worry that it will be a crutch to keep me from learning ObjC well.
Re:Google j2objc, a Java to iOS Objective-C translation tool... by thewarrior on Friday October 24, 2014 @05:19AM (#8502817)
Sounds good but suppose I need to make a network request on iOS. How would that work since there is no common Java library to do it on iOS as well as Android?

If we're only going to write the very limited business logic in Java I don't really see the benefit.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by cromwellian on Friday October 24, 2014 @05:34AM (#8502850)
If you only have trivial business logic, then yes, no benefit. But you can create common libraries that interface with native Cocoa frameworks.

Google's new Inbox by Gmail was delivered on three platforms simultaneously. It was not written from scratch 3 times.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by duaneb on Friday October 24, 2014 @04:11PM (#8505698)
> It was not written from scratch 3 times.

No, but did it also use java translation? That would involve writing wrappers for many of the native libraries. They would also have to do View/Controllers in objective-c (or some equivalent translator). And finally, they would have to special-case operating systems everywhere. This framework would not at all suffice to do multi-platform development; xamarin, robovm, cordova, and titanium all get much closer to this goal.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by thewarrior on Friday October 24, 2014 @06:24AM (#8502960)
Is there any way to use this to write the entire data handling layer ?
Re:Google j2objc, a Java to iOS Objective-C translation tool... by ZitchDog on Friday October 24, 2014 @11:10AM (#8504058)
My guess is you'd write j2objc wrappers around sqlite and HTTPUrlConnection/NSURLConnection and expose API for business logic elements.

edit: here is an example: https://groups.google.com/forum/#!topic/j2objc-discuss/8u2Si...

Re:Google j2objc, a Java to iOS Objective-C translation tool... by talloaktrees on Friday October 24, 2014 @05:33AM (#8502847)
For something like that you can use RoboVM. It's a java bytecode (which means clojure, scala, et al are also usable) to native code compiler
Re:Google j2objc, a Java to iOS Objective-C translation tool... by pikachu_is_cool on Friday October 24, 2014 @04:23AM (#8502641)
Is there a tool out there that does the opposite?
Re:Google j2objc, a Java to iOS Objective-C translation tool... by conradev on Friday October 24, 2014 @04:35AM (#8502684)
Re:Google j2objc, a Java to iOS Objective-C translation tool... by ivanche on Friday October 24, 2014 @05:40AM (#8502861)
Would be interesting to compare performance/memory footprint of native Android app, and that same app after going through Java -> j2objc -> apportable -> Android...
Re:Google j2objc, a Java to iOS Objective-C translation tool... by pavlov on Friday October 24, 2014 @08:20AM (#8503263)
The roundtrip version might be faster in some cases because it's not Java anymore, but native code. AFAIK, Apportable uses GNUStep libraries and the Android NDK, so the translated version would be an ARM binary on Android.

Of course you can't do that for a real app because they use the Android APIs, not just the foundation libraries supported by j2objc.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by paul7beusterien on Friday October 24, 2014 @03:37PM (#8505494)
Actually, Apportable's Foundation is now built on Apple's open sourced CFLite. It is available at https://github.com/apportable/Foundation. And it is used for a lot of real apps including those at http://www.apportable.com/customers
Re:Google j2objc, a Java to iOS Objective-C translation tool... by MarkMc on Friday October 24, 2014 @08:54AM (#8503401)
Does Google's new Inbox app use this tool?
Re:Google j2objc, a Java to iOS Objective-C translation tool... by phanster on Friday October 24, 2014 @09:25AM (#8503504)
Re:Google j2objc, a Java to iOS Objective-C translation tool... by MarkMc on Friday October 24, 2014 @07:01PM (#8506447)
Thanks - also looks like Google Sheets and Google Drive use it too:

https://github.com/google/j2objc/wiki/Projects-that-use-J2Ob...

Re:Google j2objc, a Java to iOS Objective-C translation tool... by krosaen on Friday October 24, 2014 @11:18AM (#8504094)
The tooling for this and gwt are impressive and no doubt useful to the teams at google managing cross platform code.

Just unfortunate that the starting point is Java source code (note: not bytecode, you can't use clojure or other jvm platform langs) - I just have no interest in coding in java when there are so many other better languages available all across the spectrum.

Re:Google j2objc, a Java to iOS Objective-C translation tool... by heavenlyhash on Friday October 24, 2014 @11:57AM (#8504248)
RoboVM, an alternative to j2obc already mentioned in a sibling comment, DOES consume bytecode. You might wanna check that out :)

I'll personally vouch for it's capacity to handle non-java; I've even gone so far as to feed it weird bytecode crafted from a personal fork of Apache JavaFlow... and it handled it 100% correctly, first try.

http://www.robovm.com/

Re:Google j2objc, a Java to iOS Objective-C translation tool... by ExpiredLink on Friday October 24, 2014 @05:46AM (#8502876)
Does it support all of Java SE?