Using this method you can have Java modules and Android modules in the same project and also have the ability to compile and run Java modules as stand
alone Java projects.
Open your Android project in Android Studio. If you do not have one, create one.
Click File > New Module. Select Java Library and click Next.
Fill in the package name, etc and click Finish. You should now see a Java module inside your Android project.
Add your code to the Java module you've just created.
Click on the drop down to the left of the run button. Click Edit Configurations...
In the new window, click on the plus sign at the top left of the window and select Application
A new application configuration should appear, enter in the details such as your main class and classpath of your module.
Click OK.
Now if you click run, this should compile and run your Java module.
My usage case: My Android app relies on some precomputed files to function. These precomputed files are generated by some Java code. Since these two
things go hand in hand, it makes the most sense to have both of these modules in the same project.