Java’s Magic the Bytecode” The key that allows Java to solve both the security and the portability problems just described is that the output of a Java compiler is not executable code. Rather, it is bytecode.
Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system, which is called the Java Virtual Machine (JVM). That is, in its standard form, the JVM is an interpreter for bytecode.
This may come as a bit of a surprise. As you know, C++ is compiled to executable code. In fact, most modern languages are designed to be compiled, not interpreted-mostly because of performance concerns.
However, the fact that a Java program is executed by the JVM helps solve the major problems associated with downloading programs over the Internet. Here is why.
JAVA’S MAGIC THE BYTECODE:-
Translating a Java program into bytecode helps makes it much easier to run a program in a wide variety of environments. The reason is straightforward: only the JVM needs to be implemented for each platform.
Once the run-time package exists for a given system, any Java program can run on it. Remember, although the details of the JVM will differ from platform to platform, all interpret the same Java bytecode.
If a Java program were compiled to native code, then different versions of the same would have to exist for each type of CPU connected to the Internet. This is the program of course, not a feasible solution.
Thus, the interpretation of bytecode is the easiest way to create truly portable programs.
The fact that a Java program is interpreted also helps to make it secure. Because the execution of every Java program is under the control of the JVM, the JVM can contain the program will see, safety is also enhanced by certain restrictions that exist in the Java language.
When a program is interpreted, it generally runs substantially slower than it would run if compiled to executable code. However, with Java, the differential between the two is not so great.
The use of bytecode enables the Java run-time system to execute programs much faster than you might expect. and prevent it from generating side effects outside of the system. As you
ALTHOUGH JAVA WAS DESIGNED FOR INTERPRETATION:-
there is technically nothing about Java that prevents the on-the-fly compilation of bytecode into native code. Along these lines, Sun supplies its Just In Time JIT) compiler for bytecode, which is included in the Java 2 release.
When the JIT compiler is part of the JVM, it compiles bytecode into executable code in real-time, on a piece-by-piece, demand basis. It is important to understand that it is not possible to compile an entire Java program into executable code all at once because Java performs various run-time checks that can be done only at run time. Instead, the JIT compiles code as it is needed, during execution.
However, the just-in-time approach still yields a significant performance boost. Even when dynamic compilation is applied to bytecode, the portability and safety feature still apply, because the run-time system (which performs the compilation) still is in charge of the execution environment.
Whether your Java program is actually interpreted in the traditional way or compiled on-the-fly, its functionality is the same.
THE JAVA BUZZWORDS:-itwords.org
No discussion of the genesis of Java is complete without a look at the Java buzzwords. Although the fundamental forces that necessitated the invention of Java are portability and security, other factors also played an important role in molding the final form of the language. The key considerations were summed up by the Java team in the following list of buzzwords:
- High performance.
Two of these buzzwords have already been discussed: secure and portable. Let’s examine what each of the others implies.
Java was designed to be easy for a professional programmer to learn and use effectively. Assuming that you have some programming experience, you will not find Java hard to master.
If you already understand the basic concepts of object-oriented programming, learning Java will be even easier. Best of all, if you are an experienced C++ programmer, moving to Java will require very little effort.
Because Java inherits the C/C++ syntax and many of the object-oriented features of C++, most programmers have little trouble learning Java. Also, some of the more confusing concepts from C++ are either left out of Java or implemented in a cleaner, more approachable manner.
Beyond its similarities with C/C++, Java has another attribute that makes it easy to learn: it makes an effort not to have surprising features. In Java, there are a small number of clearly defined ways to accomplish a given task.