3

I already have Android Studio, but not Eclipse.

Do I have to install Eclipse in order to test some simple Java code? Or is it possible using Android Studio?

What is the difference between both?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Seung Joo Noh
  • 81
  • 1
  • 2
  • 6
  • 1
    Just for testing so you don't need to start your app? Use JUnit tests! – cherry-wave Jul 03 '16 at 11:02
  • You could always use IntelliJ, the IDE that Android Studio is based on. If you install the Android plugins, you will have a nice way or doing both using a single IDE. – spaaarky21 Aug 15 '17 at 00:15

5 Answers5

7

The cool thing about Android Studio is that it delegates the build process to Gradle. And with Gradle, building a plain Java application is a matter of adding the necessary plugin to the build.gradle file.

apply plugin: 'application'

mainClassName = "com.your.package.MainClassName"

And you don't need to go through the new project wizard. Just make a project directory, create a build.gradle file in it with the script above. Put your java source code is in 'src/main/java'.

In Android Studio click 'Import Project (Eclipse, Gradle, etc.)', open the project directory and select the build.gradle file. Choose OK to configure Gradle wrapper. When the import is finished press RUN and let the plugin do the rest.

Note, that the 'application' plugin also implicitly applies the Java plugin.

More about these plugins here: https://docs.gradle.org/current/userguide/application_plugin.html and here: https://docs.gradle.org/current/userguide/java_plugin.html

dev.bmax
  • 8,998
  • 3
  • 30
  • 41
2

I haven't tested it yet.But this is the first thing i found when i googled it:

Tested on Android Studio 0.8.6 - 1.2.2

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.

1.Click File > New Module. Select Java Library and click Next.

2.Fill in the package name, etc and click Finish. You should now see a Java module inside your Android project.

3.Add your code to the Java module you've just created.

4.click on the drop down to the left of the run button. Click Edit Configurations...

5.In the new window, click on the plus sign at the top left of the window and select Application

6.A new application configuration should appear, enter in the details such as your main class and classpath of your module. Click OK.

7.Now if you click run, this should compile and run your Java module.

and you might wanna check This Thread.

Community
  • 1
  • 1
Anirudh Sharma
  • 7,968
  • 13
  • 40
  • 42
0

What is the difference?

Android Studio is built by intellij for googles Android framework. It is specifically made for making App's (APK is made out of it). Now intellij also has their own IDE (Integrated development environment) that looks a lot similar but is designed to build things other than apps like JAR's and website pages.

Eclipse is also an IDE and will essentially do what intellij's IDE does. Eclipse also can build APK's (although google recommends and only supports Android Studio now). In terms of difference for IDE's it is between its generally up to users preference for coding in.

From my own experience; I would only use Android Studio for writing app's and another IDE for any other type of program.

Chris
  • 460
  • 8
  • 16
0

Please open the below link. It shows how to run an normal java code in android studio. https://github.com/libgdx/libgdx/wiki/Gradle-and-Intellij-IDEA#running-your-project

Referenced from the link:Running Java application in Android Studio

Community
  • 1
  • 1
DroidAks
  • 327
  • 2
  • 9
-1

From this way you can check Java modules in Android studio.This is easy way to compile and run Java Code in Android studio.

First of all Open your Android project in Android Studio. If you do not have any then create one project.

Click File > New Module.Select Java Library and click Next.

Write your package name, etc and click Finish. You should now able to see a Java module inside your Android project.

Add your code or any program in java language 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,You'll see a + sign,click on the plus sign at the top left of the window and select Application

A new application configuration must be appear,enter in the details such as your main class and java classpath of your module.

Click on OK button. Now if you click run, this will compile and run your Java code which you written.