+ 1

Why does Kotlin need a JDK when it has its own compiler?

Also, if I download the JRE instead, how will that affect my development

19th Nov 2019, 7:54 AM
Godric Oscar Dolphine
Godric Oscar Dolphine - avatar
5 odpowiedzi
+ 2
If we're talking Kotlin/JVM (which is what most people use), Kotlin needs the JDK because the JDK isn't just the Java compiler. The JDK contains a bunch of useful libraries (think of lists, time management, threading, etc.) which Kotlin developers can use. It would be redundant to reimplement it all with Kotlin if it's already available with the JDK. The second reason is that Kotlin/JVM, as implied by the name, runs on the JVM. The JVM is included as part of the JDK, and also requires libraries within it (java.lang.Thread, for instance) to function properly. In short, Kotlin/JVM uses the JVM and libraries in the JDK.
21st Nov 2019, 2:37 PM
LunarCoffee
LunarCoffee - avatar
+ 4
The JDK includes a JRE with it (there might be an option to opt out, not sure), but you need the JDK to actually compile things. Kotlin doesn't actually need the JDK, only Kotlin/JVM does, since it runs on the JVM and doesn't have a huge standard library (so it uses Java's). Kotlin/JS and Kotlin/Native do not require the JDK. Kotlin/JS compiles to JavaScript, while Kotlin/Native compiles to native targets.
19th Nov 2019, 12:21 PM
LunarCoffee
LunarCoffee - avatar
+ 2
You misinterpreted between JDK and JRE. android studio has its own JRE (Java runtime environment) which includes the environment for running a simple app. But you need to install JDK(java development kit) because the code which is written in Java or KOTLIN doesn't matter it's need to be compile it can't be compile using JRE alone it needs JDK for that which is not included in android studio. :)
19th Nov 2019, 8:33 AM
Chirag Kumar
Chirag Kumar - avatar
+ 1
I'm not getting what you're saying please. With android studio out of your explanation, does kotlin need the JDK (JRE, JVM etc) even when it has its own compiler?
19th Nov 2019, 10:51 AM
Godric Oscar Dolphine
Godric Oscar Dolphine - avatar
0
Java or KOTLIN both need a sperate JDK downloaded in your computer to compile and there is no need to download seprate JRE because in android studio JRE is pre install.
19th Nov 2019, 11:25 AM
Chirag Kumar
Chirag Kumar - avatar