When you install an application on your Androidsmartphone, you hardly think about what language it is written in. Meanwhile, behind the majority of popular apps - from Instagram to bank clients - there is Javaa programming language, which for more than 15 years has remained one of the main tools for software development. But why him? After all, today there are so many alternatives - the same Android. But why him? After all, today there are so many alternatives - the same Kotlinthat Google officially recommends as a priority.
In this article we will analyze what is Java in the context of Androidhow it interacts with the operating system, and why, despite the emergence of new technologies, it remains in demand. You will learn what problems this language solves, how it differs from its competitors, and you will be able to evaluate whether it is worth learning to create your own applications. And if you have already tried to write code, you will understand why some projects still cling to Javadespite all its shortcomings.
Spoiler: itโs not just about inertia. U Java there are unique features that make it indispensable in certain scenarios - for example, when working with legacy code or in corporate development. But first things first.
What is Java and how is it related to Android
Java is an object-oriented programming language created by the company Sun Microsystems in 1995. Its key feature is cross-platform thanks to the JVM (Java Virtual Machine), which allows you to run Java apps on any device where this machine is installed. It is this property that made the language an ideal candidate for Androidwhere applications must run on thousands of different devices with different hardware.
When Android only appeared in 2008, Google chose Java as the main language for development for several reasons:
- ๐ Large community: by that time Java was already popular among developers, which means it was easier to find specialists and training materials.
- ๐ Memory management: Java uses automatic garbage collection (Garbage Collection), which simplifies working with resources - critical for mobile devices with limited memory.
- ๐ ๏ธ Ready libraries: by 2008, the Java ecosystem already included thousands of libraries for working with the network, databases, graphics, etc.
However, there is a nuance: Android does not use the standard one JVM. Instead, applications run on ART (Android Runtime) โan optimized environment that compiles Java bytecode into machine code directly when installing the application (technology AOT-compilation). This speeds up the launch of apps and reduces battery consumption.
Java vs Kotlin: why Google switched to a new language, but did not abandon the old one
In 2017 Google announced that Kotlin becomes the official language for development under Android along with Java. And in 2019, the company went further - it announced Kotlin preferred language. Why Java has not been retired yet?
The fact is that both languages โโhave strengths and weaknesses. Let's compare them in key aspects:
| Criteria | Java | Kotlin |
|---|---|---|
| Syntax | More cumbersome, requires more boilerplate code | Concise, reduces the amount of code by 30-40% |
| Security | Frequent NullPointerException due to lack of protection against null |
Built-in support for nullable types, fewer errors |
| Compatibility | Full backwards compatibility with legacy code | 100% compatible with Java, but not all Java libraries are optimized for Kotlin |
| Performance | Same at the bytecode level, but Java may be faster in some cases | Same, but Kotlin compilation sometimes takes longer |
| Google support | Full, but without active development of new features | Priority, new tools appear first for Kotlin |
The main reason why Java is still alive - this millions of lines of legacy code. Many large companies (banks, telecom operators, government services) have applications written in Java 10 years ago. Rewriting them on Kotlin is expensive and risky. In addition, some low-level libraries (for example, for working with NDK) are still written in Java or C++.
Kotlin is the future of Android development, but Java will remain relevant for at least another 5-10 years due to the huge number of legacy projects and corporate solutions.
How Java works in Android: from code before launching on a smartphone
To understand how Java interacts with Android, let's look at the application's path from writing code to launching on the device:
- Writing code: A developer writes a app in Java in Android Studio (or other IDE), using Android SDK.
- Compilation: The code is compiled into bytecode for JVM (files
.class). - Conversion to DEX: Using a tool
dx(ord8in new versions) the bytecode is converted into.dex-files (Dalvik Executable), optimized for Android. - Packaging in APK:
.dex-files along with resources (pictures, XML markup) are packaged in.apk. - Installing and compiling ART: When installed, Android Runtime (ART) compiles
.dexinto machine code (AOT compilation), which speeds up launch. - Execution: The application runs in an isolated gerbil (sandbox) with its own instance ART.
An important point: Android does not use the standard JVM, which means that not all Java libraries will work out of the box. For example, if the library is fully dependent on AWT or Swing (graphical frameworks for desktops), it is not suitable for mobile development. Instead, Android uses its own classes for the UI - View, Activity, Fragment and others.
Why does the APK weigh more than the source code?
When compiled, not only your classes are added to the APK, but also parts of the Android SDK, resources for different screen resolutions, and metadata. For example, a simple "Hello World" app in Java can weigh 2-3 MB due to dependencies.
Advantages of Java for Android development
Despite the fact that Kotlin is in trend today, Java has significant advantages that make its attractiveness for certain tasks:
- ๐๏ธ Stability and predictability: Java has been around for more than 25 years, its behavior is well documented, and its bugs have long been fixed. This is critical for banking applications or medical software, where bugs can cost millions.
- ๐ฅ Large community: On Stack Overflow more than 1.5 million questions by tag
android-java. Finding a solution to a problem or hiring a developer is easier than for niche languages. - ๐ง Tools and debugging: Android Studio originally designed for Java. The debugger, memory profiler, performance analysis tools work with Java as stably as possible.
- ๐ฆ Multi-platform: The same backend code in Java can be used both in the Android application and in the server part (for example, on Spring Boot).
Another unobvious plus is Java often becomes the first language for beginners due to its strict typing and clear structure. Many universities teach it, which means graduates can immediately start Android development without additional retraining. training. Java is often the first language for beginners due to its strong typing and clear structure. Many universities teach it exactly, which means that graduates can immediately start Android development without additional retraining.
If you are just starting to learn development for Android, start with Java - this will help you better understand how OOP and memory management work. Then you can easily switch to Kotlin.
The disadvantages of Java in Android: what you will have to face
Of course, Java there are also disadvantages that force developers to look for alternatives. Here are the main ones:
- ๐ข A lot of โtemplateโ code: Simple tasks (such as null handling) require writing a lot of helper code. For example, checking for null in Kotlin takes one line, and in Java - 3-4.
- ๐ Problems with null:
NullPointerExceptionis one of the most common mistakes in Java. In Kotlin, this problem is solved at the language level. - ๐ Slow compilation: Large Java projects take longer to compile than similar ones in Kotlin, especially if annotations are used (Dagger 2, Room).
- ๐ Android Runtime limitations: Not all features of standard Java available in Android. For example, there is no full support for JavaFX or some collections from Java 8+.
Another problem is performance in some scenarios. For example, working with coroutines (asynchronous tasks) in Kotlin is implemented more efficiently than with Thread or AsyncTask in Java. This can be critical for applications where smooth animation or processing of large data in the background is important.
Are you using legacy code that is complex? port?|Are there experienced Java developers on the team?|Do you need maximum stability (for example, for fintech)?|Do you plan to use multi-platform (backend + mobile application)?|Are you ready to put up with longer code for the sake of compatibility?-->
Code examples: what Java looks like in a real Android application
To better understand how Java is used in Android, let's look at some typical code examples. For comparison, here are similar fragments on Kotlin.
1. Creating an Activity (the main application screen)
// Javapublic class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = findViewById(R.id.textView);
textView.setText("Hello, Android with Java!");
}
}
// Kotlinclass MainActivity: AppCompatActivity {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textView.text ="Hello, Android with Kotlin!"
}
}
2. button
// JavaButton button = findViewById(R.id.myButton);
button.setOnClickListener(new View.OnClickListener {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,"Button clicked!", Toast.LENGTH_SHORT).show;
}
};
// KotlinmyButton.setOnClickListener {
Toast.makeText(this,"Button clicked!", Toast.LENGTH_SHORT).show
}
3. Working with the network (request via Retrofit)
// JavaRetrofit retrofit = new Retrofit.Builder
.baseUrl("https://api.example.com/")
.addConverterFactory(GsonConverterFactory.create)
.build;
ApiService service = retrofit.create(ApiService.class);
Call<User> call = service.getUser(1);
call.enqueue(new Callback<User> {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if (response.isSuccessful) {
User user = response.body;
Log.d("API","User name:" + user.getName);
}
}
@Override
public void onFailure(Call<User> call, Throwable t) {
Log.e("API","Error:" + t.getMessage);
}
};
As can be seen from the examples, Kotlin really allows you to write more compact code, especially in cases with event handlers or asynchronous tasks. Java remains fully readable and predictable, which is important for supporting large projects.
If you work with Java in Android Studio, use Alt + Enter to quickly fix common problems (for example, adding null checks or converting code to lambdas).
When to choose Java for Android project in 2026
Despite the fact that Google recommends Kotlinthere are scenarios where Java remains a reasonable choice:
- Support for legacy projects: If you already have a large Java application, rewriting it in Kotlin could take months and bring new bugs. In such cases, it makes more sense to gradually introduce Kotlin into new modules, leaving the old code in Java.
- Enterprise Development: Banks, insurance companies and government agencies often use strict coding standards, where Java remains the preferred language due to its predictability and extensive documentation.
- Training and Mentoring: If you're teaching newbies, Java will help them better understand the basics of OOP, memory management, and multithreading before moving on to more modern languages.
- Multi-platform projects: If your Android app is part of a larger ecosystem (e.g. together with a backend on Spring Boot), using Java will make it easier to share code between teams.
- Limited resources: In small teams where it is not possible to hire experienced Kotlin developers, Java may be a more practical choice.
However, if you are starting a new project from scratch, especially if it involves the active use of modern features (Jetpack Compose, coroutines, Flow), it is worth considering Kotlin. It will allow you to code faster and with fewer errors.
Java in 2026 is not about innovation, but about stability. It is worth choosing when the priority is reliability, compatibility and ease of support, rather than speed of development.
FAQ: Frequently asked questions about Java in Android
Is it possible to use Java 17 or 21 for Android development?
Yes, but with reservations. Starting from Android Studio Giraffe (2023) i AGP 8.0, Java 17 is supported. However, not all features of the new Java are available due to limitations ART. For example, some modules from JavaFX or java.awt do not work. Before using a new version of Java, check official documentation for compatibility.
Is it true that Java applications are slower than Kotlin?
No, that's a myth. At the bytecode level (.dex), the performance of Java and Kotlin is the same, since both compile to the same intermediate format. The difference may appear in specific scenarios, for example, when working with coroutines (in Kotlin they are implemented more efficiently) or when using lambdas (in Java they can create unnecessary objects). But in most cases the difference is insignificant.
Is it worth learning Java in 2026 if I want to do Android development?
Yes, but with a focus on practice. Java will help you understand the basics that will also be useful in Kotlin (OOP, multithreading, working with memory). However, donโt get hung up on it: after mastering the basics, move on to Kotlin - this will increase your chances in the labor market. Many jobs today require knowledge of both languages.
Is it possible to use both Java and Kotlin in one project?
Yes, Android Studio fully supports mixed projects. You can write new modules in Kotlin and leave the old ones in Java. The main thing is to correctly configure compatibility in build.gradle:
android {compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget ='1.8'
}
}
What popular Android applications are written in Java?
Among the well-known examples:
- Twitter (partially, legacy code)
- Uber (historically large Java codebase)
- Signal (uses Java for cryptographic modules)
- Many banking applications (due to security and stability requirements)
However, most modern applications (for example Trello, Evernote) are actively migrating to Kotlin or using it for new features.