In this post, we feature a comprehensive article about Android App Development: Kotlin vs Java.
In this post, we look at how to develop Android Apps with Android Studio using Kotlin and Java. Eclipse setup for Android is also included in this article. Kotlin vs Java analysis is explained with the pros and cons of each programming language.
Table Of Contents
- 1. Overview
- 2. Android App Development: Kotlin vs Java
- 3. Conclusion
- 4. Download the Source Code
Java 8 is required on the Linux, windows or mac operating system. Eclipse Oxygen can be used for this example. Android Studio 3.4.2 is used for the creation of Java and Kotlin applications. Gradle 5.4.1 is used by the Android studio for building the code. Eclipse 4.7 (Oxygen) can be used for Android development.
You can download Java 8 from the Oracle web site . Eclipse Oxygen can be downloaded from the eclipse web site. Android Studio can be downloaded from the android studio link. Gradle is bundled with Android studio.
2.3.1 Java Setup
You can set the environment variables for JAVA_HOME and PATH. They can be set as shown below:Java Setup
JAVA_HOME=”/jboss/jdk1.8.0_73″ export JAVA_HOME PATH=$JAVA_HOME/bin:$PATH export PATH
2.3.2 Gradle Setup
The environment variables for Gradle are set as below:Gradle Setup
GRADLE_HOME="/opt/gradle/gradle-5.4.1/bin" export GRADLE_HOME=$GRADLE_HOME\bin\ export PATH=$PATH:$GRADLE_HOME
2.3.3 Android Studio Setup
Download the Android studio from the website based on your operating system. Install the android studio and launch the android studio.
2.3.4 Eclipse Setup
The ‘eclipse-java-oxygen-2-macosx-cocoa-x86_64.tar’ can be downloaded. The tar file is opened by double click. The tar file is unzipped by using the archive utility. After the unzipping, you will find the eclipse icon in the folder. You can move the eclipse icon from the folder to applications by dragging the icon.
You can check the version of the gradle by using the command gradle –version. The command for running Gradle is as below:Run Command
The output of the executed command is shown below.
You can click on the Android Studio icon to launch Android Studio. Android studio screen pops up. The screen shot below shows the Android studio screen.
You can click on the eclipse icon to launch eclipse. The eclipse screen pops up as shown in the screen shot below:
You can select the workspace from the screen which pops up. The attached image shows how it can be selected.
You can see the eclipse workbench on the screen. The attached screen shot shows the Eclipse project screen.
2.6.1 Android Plugin setup on Eclipse
Go to Help menu and click on Software Updates. In the form, click on the Available software. Type the website details for ADT Plugin in the screen presented in the field work with.
Click on the next icon. It will launch the next screen as shown below:
Once it is complete, click on the next icon. It will show another screen as shown below:
The license screen pops up. The license agreement is accepted as shown below:
Security warning pops up. Click on Install Anyway button. The screenshot below shows the security warning.
Message to restart the eclipse pops up as shown below. Click on the button Restart now. The setup is complete.
You can start creating a new project in Android Studio by clicking on new project on Android Screen. It shows a new window as shown below:
Project details are filled out in the screen which comes up after clicking the next icon. The screen shows the project details:
Build process is invoked from the screen which comes up. The popped up screen is shown below:
From the menu, click on the Run app. It shows the device setup for the emulator. The screenshot is attached below which shows the device setup.
Android x86 option is selected for the virtual device. The screen shot below shows the android x86 setup.
The android sdk license screen pops up. The agreement for the license is accepted. Once the sdk is setup. It shows the message done. The screenshot below shows the “Done” message on component installer screen.
After the completion of the setup, emulator screen pops up after running the app. The screen shot shows the emulator screen.
You can start creating a new project in Android Studio by clicking on new project on Android Screen. It shows a new window which is in the screen shot below:
Kotlin Project details are filled out in the screen which comes up after clicking the next icon. Kotlin Language is selected. The screen shows the project details:
Kotlin Project Build process is invoked from the screen which comes up. The popped up screen is attached below:
From the menu, click on the Run app. It shows the device setup for the emulator. The screenshot is attached below which shows the device selection form.
Android Accelerated x86 device is selected for the emulator. Android x86 Emulator screen pops up after running the app. The screen shot shows the emulator screen.
Developers need to maintain good code quality by using different architectural patterns such as MVP, MVVM, and MVM. Unit testing needs to be done for every android app. Functional UI tests need to be developed and added to the tests repository. Performance needs to be factored while writing the code. APK size can be reduced as the footprint of the mobile app is very important. Internationalization can be handled by using strings.xml.
Java and Kotlin are statically typed languages used for programming. Android apps can be developed in any programming language. They can be executed on JVM.
2.11.1 Advantages using Kotlin
- Kotlin is Java Virtual Machine compatible language. Kotilin, when compiled, generates bytecode in java.
- Kotlin can be used to generate markup such as HTML and XML. Anko is UI library based on Kotlin for creating UI components.
- Kotlin performs better than Java.
- Kotlin has features such as lambdas to support inline functions.
- In Kotlin, creating extensions is very easy.
- Coroutines in Kotlin help in managing multiple threads.
- Creating classes with properties and getters & setters for them is very easy in this language.
- Class delegation in Kotlin helps in having multiple inheritance
- Primitive typed variables are objects in this language.
- Kotlin has good support for smart casting.
2.11.2 Advantages using Java
- Java has good support for checked exceptions.
- Implicit conversions is possible in Java.
- Multiple inheritance in java can be achieved through interfaces.
- Non-private and public properties can be created for classes in java.
- Java can handle static types and members.
- Java has a ternary operator.
- Wildcard types can be handled in Java.
- Annotation processing framework is an advanced feature which is available in java.
- Java has huge community support in terms of the number of developers. Java issues can be easily solved from different forums. Java questions in Stack Overflow are over 1.52 million. Java is ranked number 1 according to TIOBE index.
2.12.1 Disadvantages using Java
- Java does not provide support for inline functions.
- In java, object types and primitive types are different.
- Before casting in java, you need to verify the type.
- Java mobile apps performance is not good compared to Kotlin.
2.12.2 Disadvantages using Kotlin
- Kotlin has no features such as checked exceptions.
- All types are non nullable in kotlin.
- There are no null pointer exceptions.
- Kotlin has no support for static members.
- Kotlin does not have a ternary operator.
- Annotations are missing in this language.
- Kotlin is a new programming language and few members in the community. Kotlin questions are around 21,096 as of March 2019. Beginners might have a tough time in getting answers to their issues. Kotlin is at very low rank 43 on TIOBE index.
Java can be used for general programming needs. First time programmer in Android can start with Java to get started. Kotlin is useful for rapid prototyping mobile applications in Android. Kotlin and Java are interoperable and Java code can be invoked from Kotlin. You can use java frameworks in Kotlin.
You can download the full source code of this example here: Android App Development: Kotlin vs Java