Quick revision
The short answer
Kotlin, Scala, Groovy and Clojure are JVM languages: their compilers produce ordinary JVM bytecode, so they run on the same runtime, can call Java libraries, and can be called from Java with varying ease. invokedynamic, added in Java 7 through JSR 292, lets a language decide at run time how a call site is linked, which helped dynamic languages first; Java itself later used it for lambdas and string concatenation. All these languages share HotSpot's JIT and garbage collectors.
What to remember
In this answer, we saw that JVM languages such as Kotlin, Scala, Groovy and Clojure compile to ordinary bytecode, so they share the JVM's JIT and garbage collectors and can call Java libraries, while Java calling them works with varying ease. We also saw that invokedynamic, from JSR 292 in Java 7, lets a language link call sites at run time through bootstrap methods and method handles, and that Java now uses it for lambdas, string concatenation and more.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Kotlin, Scala, Groovy and Clojure are JVM languages: their compilers produce ordinary JVM bytecode, so they run on the same runtime, can call Java libraries, and can be called from Java with varying ease. invokedynamic, added in Java 7 through JSR 292, lets a language decide at run time how a call site is linked, which helped dynamic languages first; Java itself later used it for lambdas and string concatenation. All these languages share HotSpot's JIT and garbage collectors.
Why this question is asked
Many teams run Kotlin or Groovy next to Java without thinking about why that works at all. Understanding it explains a lot: why a Kotlin service can use Spring and Hibernate, why Java code calling Kotlin sometimes looks strange, and why lambdas compile to a curious instruction instead of an inner class. Interviewers ask this to check that we see the JVM as a platform, not only as the place where Java runs. In this answer, we will recap what bytecode is, look at the main JVM languages, see how they interoperate with Java, and then explain invokedynamic and how Java itself came to use it.
1A Quick Recap: The JVM Runs Bytecode, Not Java
The JVM does not understand Java source code. It runs class files, which contain bytecode, a set of instructions for the JVM's virtual machine, plus descriptions of classes, fields and methods. javac is just one compiler that produces class files. Any other compiler that writes valid class files can target the same JVM.
That is the whole idea behind JVM languages. The language designer writes a compiler, the output is ordinary bytecode, and from then on the JVM treats it like any other code: it loads the classes, verifies them, JIT-compiles hot methods and garbage-collects their objects. So a Kotlin or Scala program gets HotSpot's C2 compiler, G1 or ZGC, JFR and the rest for free.
2The Main JVM Languages
Kotlin, from JetBrains, is statically typed and close to Java in model, with null safety in its type system, data classes and coroutines; it is the main language for Android and is widely used with Spring. Scala is statically typed with a strong functional side and a powerful type system, used heavily in data tools such as Apache Spark. Groovy is dynamically typed with optional static compilation, known from Gradle build scripts and the Spock testing framework. Clojure is a Lisp, dynamically typed and focused on immutable data structures.
| Language | Typing | Typical use | Calling it from Java |
|---|---|---|---|
| Kotlin | static, null-safe types | Spring services, Android | easy; some annotations help |
| Scala | static, rich type system | data processing, Spark, Akka | possible, but Scala features look odd |
| Groovy | dynamic, optional static | Gradle scripts, Spock tests | easy for simple classes |
| Clojure | dynamic, Lisp | data-oriented services | through clojure.java.api.Clojure |
3How They Work With Java
Because everything ends up as classes and methods, a JVM language can call any Java library directly, and Java can call code written in the other language. The ease varies, because each language has features that Java has no syntax for, and its compiler has to express them as plain classes and methods.
Notice that the Kotlin function sits in a generated class named after the file, and that Kotlin's default argument is invisible to Java unless we add @JvmOverloads, which generates the extra overloads. Scala's traits, implicits and companion objects create similar puzzles in Java. Calling from the other languages into Java is almost always smooth, which is why they can use Spring, Jackson and JDBC drivers unchanged.
4What invokedynamic Added
Before Java 7, the JVM had four call instructions: invokestatic, invokevirtual, invokeinterface and invokespecial. All of them link a call to a method by fixed rules that suit Java. A dynamic language such as Groovy or JRuby, where the method to call may depend on run-time types or on methods added while the program runs, had to work around this with reflection or generated helper classes, which were slow and hard for the JIT to optimize.
JSR 292, delivered in Java 7, added a fifth instruction: invokedynamic. When the JVM reaches an invokedynamic call site for the first time, it calls a bootstrap method, which is code supplied by the language runtime. The bootstrap method decides what the call should do and returns a CallSite object holding a MethodHandle, a typed, directly callable reference to a method. From then on, the call goes straight to that target. The language can also re-link the call site later if the situation changes, and the JIT can inline through method handles, so dynamic calls can become nearly as fast as static ones.
5 messages in order. Play them, or step through them one at a time.
Linking happens once per call site; the language decides how.
5Java Itself Uses invokedynamic
Ironically, Java became one of invokedynamic's biggest users. Since Java 8, a lambda compiles to an invokedynamic instruction whose bootstrap method is LambdaMetafactory, which creates the functional object at run time, so javac does not need to write an inner class file per lambda. Since Java 9 (JEP 280), string concatenation with + compiles to invokedynamic with StringConcatFactory, which lets the JDK improve concatenation strategies without recompiling our code. Records use it for their generated toString, equals and hashCode, and pattern matching for switch uses it for type tests.
Other JVM languages use it too: recent Kotlin versions compile lambdas through invokedynamic by default, and Groovy uses it for its dynamic method calls; check your language version for the defaults.
6Follow-up questions
Do JVM languages run slower than Java?
Statically typed ones such as Kotlin and Scala compile to bytecode much like Java's, so their performance is usually the same, apart from features that allocate more, such as some collection operations or boxing. Dynamic languages pay for run-time dispatch, though invokedynamic and the JIT reduce that cost a lot. All of them use the same JIT and collectors.
Why did Java switch lambdas to invokedynamic instead of generating inner classes?
Inner classes meant one class file per lambda, more class loading and a fixed translation strategy forever. With invokedynamic, the bytecode only says create a functional object for this method, and the JDK decides how at run time, so it can change and improve the strategy in later releases without recompiling existing code.
Can a Java project use a Kotlin library without the Kotlin compiler?
Yes. The library is just a jar of class files, so javac compiles against it like any other jar. The project does need the Kotlin standard library at run time, because Kotlin code calls into it, and the Java code may need to use the generated class names such as FileNameKt.
7Conclusion
In this answer, we saw that JVM languages such as Kotlin, Scala, Groovy and Clojure compile to ordinary bytecode, so they share the JVM's JIT and garbage collectors and can call Java libraries, while Java calling them works with varying ease. We also saw that invokedynamic, from JSR 292 in Java 7, lets a language link call sites at run time through bootstrap methods and method handles, and that Java now uses it for lambdas, string concatenation and more.
Open with
The JVM does not run Java source, it runs bytecode in class files, so any language whose compiler writes class files can run on it. The common ones are Kotlin, which is statically typed with null safety and is popular with Spring and Android; Scala, with a strong functional side and a rich type system; Groovy, which is dynamic and known from Gradle and Spock; and Clojure, a Lisp.
Then, if they want more
Because they all end up as classes and methods, they can call Java libraries directly, which is why a Kotlin service can use Spring and Hibernate.
Calling them from Java works too, but with varying ease: a Kotlin top-level function ends up in a class named after the file, and default arguments need @JvmOverloads. invokedynamic came with JSR 292 in Java 7.
The first time the JVM hits an invokedynamic call site, it calls a bootstrap method supplied by the language runtime, which returns a CallSite with a MethodHandle as the target, and after that the call is linked directly and the JIT can inline it. That let dynamic languages avoid slow reflection.
Java later used it itself: lambdas since Java 8 through LambdaMetafactory, string concatenation since Java 9, and record methods. And since all these languages run on the same JVM, they all benefit from the same JIT and garbage collectors.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 7, Java 8, Java 9
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Name some JVM languages, explain how they run on the JVM, and what invokedynamic added...": https://scrivio-interview-library.netlify.app/java/jvm-architecture/1ebd9c4220/