tried to explain to beginner engineers what a bytecode is (as part of the explanation of the principles of Java programs). So, I try to standardly explain, they say that there is something between the compilation and interpretation, such as each team of the Javov codes, it’s like a few assembler command, but they look at me and say – not clear! They are not programmers, do not know what neither compilation, nor interpretation, nor assembler, I tried to explain it on my fingers, and something like something came out, but how can I use lifecode’s life examples on your fingers?
Answer 1, Authority 100%
And you need to explain very simple. Using their position. To begin with, we show this engineer to Java. For example, classic HelloWorld. And ask – is it clear? Most likely they will say no. We explain that both the special program that executes the code is also not clear. To do this, you need to “disassemble the bones.”
Now we make “pseudo-creating” – as for typistics (secretaries). For HelloWorld’a it will be like this.
- set up the environment (there is no code in the code, but it automatically) – cook paper, check out the cartridges.
- Take from the memory of the “Hi World” string.
- Pypsy the buttons, scorching the deadline (the cycle appeared here :)).
- Clean everything and attribute the paper to the customer.
formally – this is a simple bytecode. Only this is a human bytecode. And if it is standardized to standardize all operations and enumerate, then everything can be reduced to the set of numbers. Now to the real Baitcode just go.
will easily explain and tolerance. If a person (secretary) learn all the codes of operations, it will be able to fulfill any work, the main thing that was the sequence of codes. And engineers can try to unwind-construct a device that will be executed.
Answer 2, Authority 29%
@vanyamelikov In my opinion, you yourself do not understand what the Java Baitcode is 🙂
Baitcode Java These are machine instructions for a non-existent Java machine, which is often called Java Virtual Machine.
What is the power of the brother? And the strength brother is that you write for some Java machine (someday someone will make the physical Java car). What is a Java code portability: this is just a matter of implementing a Java machine on some real car, etc.
Answer 3, Authority 17%
I would try to explain something like this:
Computers are “thinking” by the simplest instructions, and when you write a program for example, it is converted to a set of primitive machine instructions.
For example, it was an expression in programming language
a = 42 * spam
It is roughly transformed into the sequence of instructions
get a value from spam multiply it from 42 put the result in a
Since computers are different and the instructions that they use also not always alone.
Therefore, invented a layer above these most machine instructions – byte code.
Your code written in such languages such as Java and Python is transformed first into it and then in machine instructions. Why do you need it? The same byte code will be the same to work on different computers. Roughly speaking byte code This is a “spinning” over machine instructions, increasing portability of programs.
I will be glad to be able to criticize about this explanation ^ _ ^
Answer 4, Authority 4%
I understand, the question is how to explain what a byte code is not resorting to the explanation of the rest of the context. It seems to me that it will not be possible to explain what a byte code is, not explaining what machine language and programming language, because it is not by itself, it is a layer between them – i.e. To understand what the layer makes, you need to understand, between what it lies.
Answer 5, Authority 4%
The best practical way:
- Show the basics of programming (primitive types, arrays, cycles, input / output)
- Let everyone write Emulator some (virtual) computer: each student has its own team system, you can give a very brief overview of architectural classes: stack machine, RISC C 8-16 registers, CISC a la Z80 (command register battery and memory battery), 3Had-based machine-memory machine-memory machine; Harvard / Fonnaman (1 or 2 array under code / data). At the same time, show the concepts of the machine code, coding code / data, the organization of memory, I / O is everything is also included in the basic training program on the special appliances. And all this clearly, you can fasten the GUI, and even in the minimum console version, the student can add a log of any command, or change memory.
virtual computer, which is stored in the Prom array – and there is a byte code: all his differences from the machine code is only that it is done not a real processor, but by your program-interpreter. Your program interpreter –
Virtual machine. If you are interested in the book [DragonBook] you can find algorithms and methods how to convert your bytes code in this machine code and perform it on the real processor – this is engaged in
- byte code is also
by intermediate view of theprogram [DragonBook] – between the program on the yav and the machine code. Since when developing the Java language, it was assumed that Java programs should be executed on any computer with a predetermined processor type, instead of compiling (in the machine code), the program distribution format was selected as files with byte code. The format of this byte code, the command system and the memory organization are standardized, and are described in the
Specifications of the JVMVirtual Machine.
implementations of JVMfor common computers, for example, for PCs, and mobile phones are programs, these are programs that you do what you did: interpret the byte code, and some implementations can compile it in RAM directly In the process of performing byte-code (JIT), which greatly improves the speed of the program.
- also developed several Java processors that run byte code hardware, that is, it is a machine code for them. But they did not receive distribution, as it turned out cheaper to use widespread cheap processors, a JIT compiler and 100,500 ready-made libraries (including operating systems) written on C and Fortran.
- And now we take item 2, set ANTLR, and write a simple programming language compiler (and show how to parse text data – for engineers the thing is necessary, you can write an assembler as a course)
Baitcode is a system of commands of a certain processor. Do they know that each processor has a command system? The program on the assembler for x86 was seen? If not, then show. Then, the program in any command system can be performed by hardware, can be programmatically (interpreter), and you can translate to another command system, and then execute hardware, software, or … So it happened that Java-bytecode Interpret or translate, and x86 perform hardware. But the reasons are economic, and not fundamental. Java processors exist, but are not very common. On other planets, maybe, the opposite is the opposite.
Why did the byte code come up with? At the beginning there were interpreters who simply performed the code from the text, but since the effectiveness in constant analysis of the lines is not good, came up with working with bytes, and not as with the source code of the strings, that is, the program converts the source syntax of the Yap-A to the byte code where There are instructions and tags, etc. Almost both in ASM, hence the name of the virtual machine, and not an interpreter, for example in Java it is JVM. So everything is simple, the virtual machine when loading byte-code executes it. But this is not all, for greater performance Introduced Jit, that is, the compilation of the byte code into a native code on the run of execution, thereby not much to get the competitiveness of programs to the compiled yap-am.