6800c75ee9939

6800c75eecf60
1 Guest is here.
 

Topic: Can you run J2SE code on Android? Read 2159 times  

6800c75eed6caRocketMan

6800c75eed734
I know the answer is not natively but what I'm really asking is if there's a way to do it via some VM or emulator or compiler or whatever.  It would have to support J2SE, not just J2ME, including AWT and swing.  I've heard of stuff like JBED but apparently that does not support J2SE.  There's probably a good reason nobody (few?) people have attempted this but in my ignorance it seems odd that nobody has, given the similarities between Android and Java.

As a part 2 to my question, suppose someone were to port the code into the Android language (of which I have 0 knowledge).  Assuming I have a decent enough grasp of Java, and assuming that the GUI would be the main thing being ported (the rest of the code is pretty much a copy/paste and is mostly math and logic), is it easy enough for me to update the ported code by myself without too much trouble or is it a difficult language to work with if I want to debug or add features?

6800c75eeda80sarge945

6800c75eedad8
Java is a pretty difficult language in some ways, and the limited experience I've had with Android's weird version seemed very error prone.

The two main pitfalls I found were:

1. Unreliable activities. Creating an activity at the wrong time would instantly crash the application with no warning. Order and timing was very important
2. Async. Almost everything in Android is asynchronous, which is fantastic for doing lots of tasks easily, but I wouldn't wish doing async conditional code on my worst enemy.



I only work with "traditional" Java and even then it's only server software, no AWT/Swing etc. I doubt it would work very well out of the box on an Android phone because the user interfaces were really not designed with touch in mind. It's why the Linux phone projects are such terrible ideas. I also assume a lot of things just wouldn't work at all or badly, as things like file access are handled differently on Android than on a traditional Java application. It's like Unity vs a .NET application - they both use c# but all the core functions are completely different. Java uses windows, Android uses activities. File access has to go through Androids permission system. I highly highly doubt you can port much of the code, if any, and you might be better off simply rewriting it. I get that Java is specifically designed to work on all devices, but that's always been oversold as an idea and Android doesn't follow the rules.

I've never ported a Java application to Android. I doubt it would be a good time, especially for someone who isn't already good at developing Java or Android applications.

Might I ask what application you need? There might already be something similar that does the job. That's absolutely your best bet

6800c75eedd06RocketMan

6800c75eedd51
Sure.  I don't need an application so much as I'm inventing one.  It's a program that tells you how long to put a piece of meat in the oven.  The vast majority of the code is just run of the mill stuff that I think is literally 1:1 copy/paste:

double calculateNusseltNumber(double Re, double Pr, double T, ....dadadadada) {

// math spilling off the end of this page

}

pages and pages of it.  The interface is laughable and any idiot who learned Android over the summer could probably look at my PC app and reproduce it from scratch in 1 hour or less.  That's why I'm not too worried about it.  I just don't want to learn another language because I think it would take me longer than it's worth instead of just porting or emulating it.  And since porting will cost me some money, I'll do that later.  For now it's in my better interests to have something I can try out on a phone for other diagnostic reasons and port it when I'm REALLY happy with it.  That's why I'm trying to find a VM/Emulator... but I guess there are none?

Edit:  Long time ago I downloaded this 10MB thing for my WM6 PDA and I still have it and use it.

https://osdn.net/projects/mysaifujvm/downloads/46208/jvm.0.4.8-bin.zip/

It's a J2SE VM running on 624 MHz on Windows Mobile 6.  It runs all my previous applications and GUI just fine... like  a mini version of how they appear on my PC.  I figure if this guy can do it on WM6 in 10 MB, somebody could have done it on Android.  I guess the whole windows look and feel is so unappealing to mobile users that there is that little demand for it.
« Last Edit: 24. November 2021, 03:20:03 by RocketMan »
6800c75eedff7
I would suggest to use some kind of framework/engine which let's you write code in your prefered language and lets you build for all the platforms you want to use.
Sure, you would need to learn how to do everything for this. But it beats having to learn all the native stuff for various platforms.
It goes a bit against the java goes for all approach, but with everyone having their own implementation you would need to create different versions for each platform anyway.

6800c75eee0eaRocketMan

6800c75eee134
Just so I understand what you're saying, you mean there's a VM/Compiler/Studio/Whatever that you write your code in and you can write it in whatever language you want and then you pick the output language you want and it compiles in that language? So I have a big text window and I write my Java code in it (or in this case copy code into it) and pick Android as my output and hit a few buttons and I get an Android app? 

I feel I may have misunderstood what you mean, since you said I would have to "learn how to do everything for this".
6800c75eee258
Yeah, something like that.
And with what I mean with you have to learn for that.
Think about catching the touch input, there probably is some API for each target platform so you know where the screen was touched.
But for each platform it is different so you have to create that part for each platform. If you are lucky you have a library that already does all that for you.
If you have some framework/engine you would need how to do it for that, but that is only doing it once, instead of for each indvidual platform.

6800c75eee37eRocketMan

6800c75eee3ca
But if I have "normal code" (if then statements, methods, variable declaration, math), Swing (make a window, fill it with text fields and a couple buttons), and Actionlisteners (to make the buttons execute some code), that sort of thing would be supported natively?

Got an example of such a program that does what you're describing?  It sounds like something I would want to use in the future.

Far as touch goes, the Mysaifu app for WM6 I mentioned above, worked with my stylus just like any other app.  I suspect that the touch API was some part of WM6 that just worked on top of my code and didn't care what I was running.  So my Java app had some text fields for example.  Rather than clicking on them with a mouse, I tapped inside the field with my stylus and it gave me a cursor just as I would have expected on a PC so somehow the OS is handling the touch location for me.  I don't know if Android would be the same but it would make sense if it did.
6800c75eee4fe
I don't have any examples for typical app development as I mostly work with game engines for mobile development. And everything else I write natively for the target platform.

I just did a quick search online and found https://www.codenameone.com/ which is something I've described.
There might be free alternatives.

6800c75eee5d4RocketMan

6800c75eee61f
If it "just works" I might be willing to pay for something like this.  Thanks!
6800c75eee73b
If your project is reasonable small it's for free. So you can test it out.
Most frameworks don't support Java, so this was the best I came up with, without spending too much time digging.

6800c75eeea37sarge945

6800c75eeea8c
I would suggest to use some kind of framework/engine which let's you write code in your prefered language and lets you build for all the platforms you want to use.
Sure, you would need to learn how to do everything for this. But it beats having to learn all the native stuff for various platforms.
It goes a bit against the java goes for all approach, but with everyone having their own implementation you would need to create different versions for each platform anyway.

Please don't. Frameworks are the reason programming is in such a bad state right now. Nobody should ever use them.

I guess if you're just throwing something together they can be fine, like this specific case, but for any sufficiently large application they always cause massive problems 100% of the time.


Also if you just need to do thermodynamics related calculations, will this do the job?

https://play.google.com/store/apps/details?id=com.sis.tdcalc

6800c75eeeb8cRocketMan

6800c75eeebe0
Not really because I'm trying to create something new for others to use, not for me to use.

If I had to guess I'd say your reasoning is similar to why Google translate often sucks at translating.  Without the human factor auditing everything, computers aren't smart enough to convert things efficiently like languages or code, right?

In my case since I just want to demo this thing on a phone, it might be ok though, just to get a rough impression so I know how I'm progressing.  It might be better for prototyping than anything else I imagine.

6800c75eeee38sarge945

6800c75eeee8e
If I had to guess I'd say your reasoning is similar to why Google translate often sucks at translating.  Without the human factor auditing everything, computers aren't smart enough to convert things efficiently like languages or code, right?

The problem isn't code translation. It's related to dependencies
1 Guest is here.
"Yeah, about the gold ... sorry?"
Contact SMF 2.0.19 | SMF © 2016, Simple Machines | Terms and Policies
FEEP
6800c75eeef82