DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • How to Submit a Post to DZone
  • How to LINQ Between Java and SQL With JPAStreamer
  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • An Overview of Kubernetes Security Projects at KubeCon Europe 2023
  1. DZone
  2. Coding
  3. Languages
  4. What is the JavaScript Equivalent of Java Bytecode?

What is the JavaScript Equivalent of Java Bytecode?

Axel Rauschmayer user avatar by
Axel Rauschmayer
·
Jan. 31, 11 · Interview
Like (0)
Save
Tweet
Share
11.25K Views

Join the DZone community and get the full member experience.

Join For Free
The browser is slowly turning into a great platform. Part of the allure of the Java platform is that it has a core that goes beyond “Java the language”: The Java Virtual Machine (JVM). There are now many languages that target the JVM, for example: Groovy, JRuby, Fantom, Jython, Scala, ABCL, Clojure, and Gosu. Java class files store JVM programs as Java bytecode, a compact binary format that source code is compiled to. Does JavaScript have something similar?
Short answer: No. The situation is as follows.
  • Compiling to JavaScript: JavaScript engines have become so fast that it is viable to compile other languages to JS source. That is, we have virtual machines that are fed source code! Thus, for the purpose of storing and exchanging programs, JavaScript source code corresponds to Java bytecode. Parsing JavaScript is fast, so it does not present too much of a problem as an intermediate step. There are also examples of compiling JavaScript (or something very similar) to JavaScript: the Closure Compiler, Qooxdoo, CoffeeScript. Lastly, GWT even compiles a static language (Java) to a dynamic one (JavaScript).
  • Minifying JavaScript source: Minification can be used to reduce the size of source code. The simplest kind of minification is to remove comments. But further compression can be achieved. Take, for example, the following source code [source: N. C. Zakas].
        function sum(num1, num2) {
            return num1 + num2;
        }
    
    This is reduced by YUI Compressor to
        function sum(A,B){return A+B;}
    
    Zakas gives more details.
  • Core JavaScript: Being the interface to JS engines, it helps that JavaScript is a relatively simple language. But what if it were even simpler? There could be a “Core JavaScript”, a subset of JS that all other languages are compiled to. That would include more sophisticated JavaScript language features and future JS versions. As an aside, compiling to a core language is a common technique in the Lisp community.
  • Binary exchange format: I don’t think we could get JavaScript engines to agree on a common binary format, because there is no common ground: Firefox, Safari and Internet Explorer each use different bytecode, Google’s V8 compiles directly to machine code. Thus, it is obvious why there is no common binary format and why JavaScript has no direct analog to Java class files. But Core JavaScript could serve the same purpose. For faster loading, compactness, and possibly obfuscation, the abstract syntax tree could be used (an extreme way of minification, if you will).
To summarize: The motto “source code is the new binary” and not minding the parsing on the web is a surprising development. Source code minification is also interesting, but a logical consequence of this motto.

Related reading:

  • Proper tail calls in Harmony


From http://www.2ality.com/2011/01/what-is-javascript-equivalent-of-java.html

 

JavaScript Java (programming language)

Opinions expressed by DZone contributors are their own.

Trending

  • How to Submit a Post to DZone
  • How to LINQ Between Java and SQL With JPAStreamer
  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • An Overview of Kubernetes Security Projects at KubeCon Europe 2023

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: