When I said that Java was write once, run anywhere, there is a caveat, and that is iOS.
There is no officially Apple-blessed JVM for iOS. They want you to use Swift.
That said, there are ways you can use Java with your iPhone or iPad:
- Using a Java to Objective-c translation tool - These take existing production code and convert it into an iOS app.
- OpenJDK for iOS - A few projects have managed to run the OpenJDK on the iOS platform and can compile and run Java code natively on the device. The most successful of these are iPad-based IDEs.
- Java to iOS Developer/Build System - A tool such as Codebase One can target iOS as one of its development platforms and create apps coded using Java.
Let's take a look at the options ...
iOS Based IDEs
CodeBrew is a free app with paid upgrades. You get to try it out with limited 'runs' to see if it is right for you, or if you just want to test out something rather than commit.
There are a few neat examples to show what it can do.
CodeApp is $6.99 or £6.99 and supports not just Java but other languages too:
Code App is a MIT-licensed desktop-class code editor for iPadOS with built-in Node.js, Python, C, C++, PHP and Java runtime.
...
A robust, high-performance text editor (Monaco Editor from Visual Studio Code)
Of course it includes C/C++ too:
iOS App + Cross-Compile
A hybrid option is to take the CodeApp codebase from Github and use it to compile-in your Java code.
This is a similar approach for how you can take your Pythonista iOS Python apps and upload them to the iOS app store.
Cross-Compile
There are several projects that give you various levels of cross-compilation to allow you to do the bulk or all of your code in Java.
MobiVM is a plugin for IntelliJ and Eclipse that allows you to pre-compile your Java code for Linux, Mac and iOS:
Codename One offers a boilerplate project and a toolkit so that you can target essentially every popular platform including iOS:
Keep in mind each of them will support different levels of cross-compilation, with J2ObjC having zero GUI support ...
Kotlin
Kotlin is the main tool for Android development going forward, and it is a really cool language.
While it runs on the Java VM, when it comes to iOS it actually gets compiled natively, allowing it to pass the App Store strict rules gracefully.
This is what a basic GUI app looks like in Kotlin. Quite different but also not too difficult to get your head around, and with some nice quality of life conveniences.
import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
@Composable
@Preview
fun App() {
var text by remember { mutableStateOf("Hello, World!") }
MaterialTheme {
Button(onClick = {
text = "Hello, Desktop!"
}) {
Text(text)
}
}
}
fun main() = application {
Window(onCloseRequest = ::exitApplication) {
App()
}
}
I never got into mobile development and it's a while since I did any Java. You need good tools for it. I expect you have to adapt apps for each of the platforms.
Sometimes, varying amounts, there are always compromises :)
It's something I'd play with if I had time, but I'd be looking for simple options. I don't have any Apple devices anyway.
I focus majority on web, command line and a little on desktop as I don’t see all that much need to develop mobile apps personally. Android has a much smoother developer experience due to being able to “side load” I think
I do Python stuff for work that is all desktop and drivers for hardware. I do some Python scripts on Hive stuff for my own amusement. All the software I've written for a living has been for commercial purposes, so not had to deal with the 'public'. I think that makes life easier.