I have just installed Kotlin version 1.7.0 and the bin folder has the following runnables.
kotlinckotlin-jvmkotlin
After quick check found that kotlinc and kotlin-jvm are used to compile code to bytecode just like javac in Java. Why there are 2 commands for kotlin compilation. Is there any significant difference?
And, should I use java command to run the bytecode or kotlin command to run the bytecode. Any tradeoffs in terms of performance.
The official docs don't say too much about those command-line tools. And while you can call them with
-help, that merely describes the other options they accept.However, I can tell you what happens on my system (macOS, where Kotlin is installed using HomeBrew). I don't know how much of the below applies to other platforms, but I suspect that at least Windows and Linux would be very similar.
Those executables are wrapper scripts, and so it's possible to see some of what they do. (They end up running Kotlin programs, which limits what you can see…)
Compiling:
kotlinc-jvmis a very simple wrapper script which merely callskotlinc— so there's clearly no effective difference between them!That shows Kotlin/JVM is the default compilation target, at least on my system. (
kotlinc-jsalso callskotlinc, but only after setting the$KOTLIN_COMPILERenvironment variable, which changes the program thatkotlincends up running.) Maybekotlinchas a different default on other systems — or at least they wanted to allow for the possibility.Running:
AIUI, running
kotlinis effectively equivalent to runningjava, except thatkotlinadds the Kotlin runtime classes to the classpath.You can of course add them manually when running
java(e.g. in the$CLASSPATHor in a-cpparameter); but you would then need to know where they are, or have some way to find them. (On my system they're in…/libexec/lib/. The only essential one is the relevantkotlin-stdlibjar, though some code also needskotlin-reflectand maybe others too. Or if you have a full Kotlin installation, I think you can simply addkotlin-runner.jar, which pulls in the others for you.)I don't think there's any other benefit to using
kotlin.Note that if you build a ‘fat’ .jar/.war file, which includes the Kotlin runtime libs, then most systems will use
javato run that anyway.