Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How JVM distinguish between Scala bytecode and Java bytecode?

As Scala also produces bytecode and executed by JVM. I am wondering How JVM distinguish between Scala bytecode and Java bytecode. Can anyone please explain?

 Scalac Myprogram.scala
 java Myprogram

So this statements are perfectly fine?

like image 522
Thanga Avatar asked Mar 17 '16 15:03

Thanga


2 Answers

I am wondering How JVM distinguish between Scala bytecode and Java bytecode.

It doesn't. There is no such thing as Scala bytecode. The Scala compiler compiles to JVM bytecode. Just like the Java compiler also compiles to JVM bytecode.

The JVM doesn't know anything about Scala. It doesn't know anything about Java, either. Nor does it know anything about Groovy, Clojure, Kotlin, Ceylon, Fantom, Ruby, Python, ECMAScript, or any of the other ~400 programming languages for which there are implementations on the JVM.

The JVM only knows about one language: JVM bytecode.

Note that this is really no different from any other machine, virtual or not. The CLR only knows about CIL, it knows nothing about C#, VB.NET, or F#. An Intel Core CPU knows only about AMD64 and x86 machine code, it knows nothing about C, C++, Objective-C, Swift, Go, Java, Python. The CPython VM only knows about CPython bytecode, it knows nothing about Python.

like image 136
Jörg W Mittag Avatar answered Sep 30 '22 19:09

Jörg W Mittag


It doesn't. Scala compiles to the same bytecode as Java.

like image 30
Eugen Hotaj Avatar answered Sep 30 '22 19:09

Eugen Hotaj