Java magic
By: aathishankaran in Java Tutorials on 2007-02-01
Java's Magic: The Byte code
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 byte code, byte code is a highly optimized set of instructions designed to be executed by the java runtime system, which is called the java virtual machine (JVM). That is, in its standard form, the JVM is an interpreter for byte code, 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.
Translating a java program into bytecode helps makes it much easier ot run a program in a wide variety of environments. The reason is straightforward: only the JVM needs to be implemented for each platform, all interpret the same java bytecode. If a java program were compiled to native code, the different versions of the same program would have to exist for each type of CPU connected to the Internet. This is, 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 and prevent it from generating side effects outside of the system. As you 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.
Although java was designed for interpretation, there is technically nothing about java that prevents on-the-fly compilation of bytecode into native code. Along these lines, Oracle 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 features 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.
Add Comment
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
- Data Science
- Android
- React Native
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Read a file having a list of telnet commands and execute them one by one using Java
Open a .docx file and show content in a TextArea using Java
Step by Step guide to setup freetts for Java
Of Object, equals (), == and hashCode ()
Using the AWS SDK for Java in Eclipse
DateFormat sample program in Java
concurrent.Flow instead of Observable class in Java
Calculator application in Java
Sending Email from Java application (using gmail)
Comments