How do I explain what a bytecode is? [closed]


Closed. It is impossible to give an objective answer to this question . Answers to it are not accepted at the moment.

Want to improve this question? Reformulate the question so that it can be answered based on facts and quotations.

Closed 5 months ago.

Improve the question

I tried to explain to novice engineers what bytecode is (as part of an explanation of the principles of executing Java programs). So, I'm trying to it is standard to explain, they say, that this is something between compilation and interpretation, such as each command of Java byte code, it is like several assembly commands, but they look at me and say-it is not clear! They are not programmers, they do not know what compilation, interpretation, or assembler is, I tried to explain it to them on my fingers, and it seems that something came to them, but how can you explain the principle of bytecode using life examples on your fingers?

Author: fori1ton, 2013-05-18

7 answers

And you need to explain it very simply. Using their position. To begin with, we show these engineers a program in Java. For example, the classic HelloWorld. And we ask - is it clear? They'll probably say no. We explain that the special program that executes the java code is also not clear. To do this, you need to "disassemble the bones".

Now we make a "pseudo-translation" - as for a typist (secretary). For HelloWorld, it will be like this.

  • configure the environment (in the code of this no, but it's automatic) - prepare the paper, check the catridges.
  • take the line "hello world"from memory.
  • by pressing the buttons, enter the date in letters (a loop appeared here:)).
  • clean everything after yourself and take the paper to the customer.

Formally , this is a simple bytecode. Only this is a human bytecode. And if you standardize all the operations in it and number them, then everything can be reduced to a set of numbers. Now go to the real bytecode simply.

Portability will also be easy to explain. If a person (secretary) learns all the operation codes, then she will be able to perform any work, as long as there is a sequence of codes. And engineers can try to solder-to construct a device that will perform this.

 23
Author: KoVadim, 2013-05-18 20:58:34

@vanyamelikov I don't think you understand what Java bytecode is :)

Java bytecode is a machine instruction for a non-existent Java machine, often referred to as a Java Virtual Machine.

What is the power of the brother? And the power of the game is that you write for a certain Java machine (someday someone will make a physical Java machine). What is the portability of Java code: it's just a matter of implementing a Java machine on some real machine, etc.

 6
Author: Barmaley, 2013-05-19 18:03:32

I would try to explain something like this:

Computers "think" with the simplest instructions, and when you write a program in, say, C, it is converted into a set of primitive machine instructions. For example, there was an expression in the programming language

a = 42 * spam

It is roughly transformed into a sequence of instructions

достать значение из spam
умножить его с 42
положить результат в a

Since computers are different, the instructions they use are also not always the same.

So we came up with a layer above these the most machine instructions are bytecode. Your code written in languages such as java and python is converted first into it and then into machine instructions. Why is this necessary? The same byte code will work the same way on different computers. Roughly speaking, bytecode is a "wrapper" over machine instructions, which increases the portability of programs.

I will be happy to hear criticism about this explanation^_^

 4
Author: gg4me, 2013-05-19 21:08:13

I understand the question is how to explain what a bytecode is without having to explain the rest of the context. It seems to me that it is impossible to explain what bytecode is without explaining what a machine language and a programming language are, because it is not in itself, it is a layer between them - that is, to understand what the layer does, you need to understand what it lies between.

 1
Author: Maxim Kamalov, 2013-05-18 20:49:17

The best way is practical:

  1. show the basics of programming (primitive types, arrays, loops, I / O)
  2. let everyone write an emulator of a certain (virtual) computer: each student has his own command system, you can give a very brief overview of the classes of architectures: stack machine, RISC with 8-16 registers, CISC a la Z80 (register-battery and memory-battery commands), 3-address machine of the memory-memory-memory type; Harvard/fonneiman (1 or 2 array for code/data). At the same time, you will show the concepts of machine code, code/data encoding, memory organization, input / output - all this is also included in the basic training program for those specialties. And all this is clear, you can screw the GUI, and even in the minimal console version, the student can add a log of the execution of any command, or memory changes.
  3. " And here is машинный код of your виртуальной ЭВМ, which you have stored in the PROM array -- and there is a bytecode: all its difference from machine code is only that, that it is not executed by the real processor, but by your interpreter program. Your interpreter program -- виртуальная машина. If you are interested, in the book [DragonBook] you can find algorithms and methods for converting your bytecode into real machine code and executing it on a real processor -- this is what JIT-компилятор Java does. "
  4. Bytecode is also промежуточным представлением программы [DragonBook] -- between a JAVA program and machine code. Since when developing the Java language, it was assumed that Java programs should to be executed on any computer with a previously unknown processor type, instead of compiling (to machine code), the format of distributing programs in the form of files with bytecode was chosen. The format of this bytecode, the command system, and the memory organization are standardized, and are described in the виртуальной машины JVM specification. Also, реализации JVM were written for common computers, such as PCs, and mobile phones - these are programs that do what you did: interpret bytecode, and some implementations are able to it is compiled in RAM directly during the execution of bytecode (JIT), which greatly increases the speed of program execution.
  5. Several Java processors have also been developed that execute bytecode in hardware, meaning that it is machine code for them. But they did not get widespread, as it turned out to be cheaper to use widely distributed cheap processors, a JIT compiler and 100500 ready-made libraries (including operating systems) written in C and Fortran.
  6. And now we take item 2, put ANTLR, and write a compiler for a simple programming language (and show how to parse text data - for engineers, a necessary thing, you can write an assembler as a course paper)
 1
Author: Dmitry Ponyatov, 2016-12-03 23:18:09

Bytecode is a command system of a certain processor. Do they know that every processor has a command system? Have you seen an assembler program for x86? If not, then show it. Then, a program in any command system can be executed in hardware, it can be executed programmatically (by an interpreter), and it can be translated into another command system, and then executed in hardware, software, or ... It so happens that java bytecode is interpreted or translated, and x86 is executed in hardware. But the reasons are here economic, not principled. Java processors exist, but are not widely used. On other planets, maybe the opposite is true.

 0
Author: rfq, 2013-05-20 04:26:26

Why did you invent the bytecode? In the beginning, there were interpreters that simply executed code from text, but since the efficiency in constant parsing of strings is not good, they came up with working with bytes, and not as with the source code of strings, that is, the program converts the source syntax of YAP-a into bytecode where there are instructions and labels, etc. almost like in ASM, hence the name virtual machine, and not an interpreter, for example, in Java, this is JVM. So here everything is simple, the virtual machine at loading the bytecode executes it. But this is not all, for greater performance, we introduced JIT, that is, compiling bytecode into native code on the run, thereby not much getting the competitiveness of programs to compiled YAP-am.

 -2
Author: Robocop, 2015-04-29 12:04:15