3

I am trying to compare JVM Bytecode and Java as programming languages.

Can you think of any example Bytecode class that could not be rewritten in Java, not even when using lots of (Java-) Boilerplate code? Maybe any construct that other JVM languages like Scala use?

[Edit] I am not talking about a comparison of instructions or the possibility to create a certain algorithm. Let me rephrase the question: "Could there be any 'pattern' that another JVM language could use but Java doesn't?". [/Edit]

[Edit2] Maybe it's easier if I explain what this question really is about. I am working with a source code transformation system, and asked myself the question if there is any pattern or construct that might be useful but cannot be added to a Java class just by transforming plain Java code but requires modification of the Bytecode itself. [/Edit2]

muffel
  • 7,004
  • 8
  • 57
  • 98
  • you could take a large codebase (the jdk?), list all the instructions used and compare it with the list of all available instructions (not sure how complicated that would be). – assylias Mar 05 '14 at 18:47
  • I'm not sure what you're asking. Java, like most languages, is Turing-complete so anything *COULD* be implemented in Java. Maybe not efficiently, maybe not easily. The analogy is precisely the same as between assembler and higher-level languages. – keshlam Mar 05 '14 at 18:48
  • 1
    What type of comparison are you trying to make. This is the classic "assembly" (i.e. machine) language code versus higher level language arena. If you treat the JVM bytecode as a machine, then you probably could compile most languages into JVM bytecode. – ErstwhileIII Mar 05 '14 at 18:50
  • Are you trying to ask if there is a byte code instruction that no current Java to Byte Code compiler outputs? – NESPowerGlove Mar 05 '14 at 18:50
  • @keshlam I am not talking about algorithms but constructs in common, e.g. what about "first-class continuations"? – muffel Mar 05 '14 at 18:51
  • First class in which language? If you want to implement a language with first class continuations that compiles into Java bytecodes, you can almost certainly do it.... – keshlam Mar 05 '14 at 18:54
  • @keshlam you are right, the formulation of my question and the example I made weren't that good. I tried to add some remarks to my question to clarify this – muffel Mar 05 '14 at 19:04
  • Have you seen this page yet? http://docs.oracle.com/javase/7/docs/technotes/guides/vm/multiple-language-support.html – Gábor Bakos Mar 05 '14 at 19:13

2 Answers2

4
  • In Java you cannot have two methods with the same names that differ only with return type - Java Bytecode allows to do that
  • Bytecode allows to create instance of class without calling constructor
  • Bytecode allows to directly use GOTO, which isn't allowed in plain Java

Update: Simillar question has been answered here

Community
  • 1
  • 1
barteks2x
  • 1,275
  • 12
  • 24
0

Also I want to add that you cannot use type information at runtime. So if you wanted to transform C#, which keeps generic information at runtime, to JVM bytecode, you cannot do it 1:1. Type erasure: Java vs C#

Community
  • 1
  • 1
user3001
  • 3,437
  • 5
  • 28
  • 54