Bck2Brwsr

From APIDesign

(Difference between revisions)
Jump to: navigation, search
(TODO)
Current revision (04:38, 1 October 2021) (edit) (undo)
 
(111 intermediate revisions not shown.)
Line 1: Line 1:
 +
[[Bck2Brwsr]] [[VM]] is a [[Java]] [[VM|virtual machine]] which is capable to take [[bytecode]] and convert it (either ahead-of-time e - e.g. during compilation - or just-in-time, e.g. in a browser) into appropriate [[JavaScript]] code which does the same thing. As a result one can write in [[Java]], compile with [[JavaC]], process it with [[Bck2Brwsr]] (usually via its [[Maven]] plugin, but possibly also directly via [[Bck2BrwsrJavadoc|programmatic APIs]]) into a [[JavaScript]] file(s) that can be executed in any modern browser (IE 10 at least, please).
 +
 +
The easiest way to start is to play with a [[DEW]] - the Development Environment for Web. Just visit http://dew.apidesign.org/dew and edit, compile, run in a browser without installing anything or using (now banned) [[Java]] plugins.
 +
 +
The [[Bck2Brwsr]] project supports the generic and portable [[Html4Java|HTML/Java APIs]] as defined by [[NetBeans]]. Use them to run your application on [[FXBrwsr|desktop]] as a standalone application, as a [[HTML|NetBeans or Eclipse]] plugin or in a browser, via [[Bck2Brwsr]] [[VM]].
 +
 +
== Motivation ==
 +
During my duties at [[JavaOne2012]] my feeling (primed by observing various [[RSS]] feeds full of posts about something which ends '''.js''') that [[Java]] is no longer as [[good|cool]] as it used to be straightened. It always starts by loosing interest of newcomers, targeting just a piece of the technology segment and soon once [[Good Technology]] becomes new [[COBOL]]. Can that happen to [[Java]]? Just read [http://mashable.com/2012/11/12/javascript/ Is JavaScript the Future of Programming?] and (if you like [[Java]]), you'll get scared. I decided to do something about that. I'd like to return my favorite programming language [[Bck2Brwsr]].
During my duties at [[JavaOne2012]] my feeling (primed by observing various [[RSS]] feeds full of posts about something which ends '''.js''') that [[Java]] is no longer as [[good|cool]] as it used to be straightened. It always starts by loosing interest of newcomers, targeting just a piece of the technology segment and soon once [[Good Technology]] becomes new [[COBOL]]. Can that happen to [[Java]]? Just read [http://mashable.com/2012/11/12/javascript/ Is JavaScript the Future of Programming?] and (if you like [[Java]]), you'll get scared. I decided to do something about that. I'd like to return my favorite programming language [[Bck2Brwsr]].
 +
 +
== Licensing ==
 +
 +
The code of [[Bck2Brwsr]] is heavily derived from [[OpenJDK]] source code (especially the libraries part, not the [[HotSpot]] part). [[Bck2Brwsr]] thus needs to match the [[OpenJDK]] licensing and be compatible with it. The licensing goal is however the same as in case of [[OpenJDK]]:
 +
 +
* if you write your application and execute it against standard [[JDK]] libraries - use the [[GPLwithClassPathException#.22CLASSPATH.22_EXCEPTION_TO_THE_GPL_VERSION_2|classpath exception]]
 +
* if you hack the [[Bck2Brwsr]] [[VM]] itself - follow the [[GPL]]v2 license
 +
 +
This kind of setup should give [[Java]] developers freedom to build their applications and distribute them under conditions of their choose, while making sure modifications, enhancements and improvements of the [[Bck2Brwsr]] [[VM]] code itself remain publicly available.
== Goals ==
== Goals ==
-
Create '''small''' [[Java]] capable to boot fast and run in 100% of modern browsers including those that have no special support for [[Java]].
+
Create '''small''' [[Java]] (check the [[Bck2BrwsrJavadoc]]) capable to boot fast and run in 100% of modern browsers including those that have no special support for [[Java]].
Demonstrate that [[Java]] has benefits over [[JavaScript]] when creating larger [[HTML]]5 applications.
Demonstrate that [[Java]] has benefits over [[JavaScript]] when creating larger [[HTML]]5 applications.
-
Unlike other similar efforts, the goal of this project is '''not''' to execute any existing [[Java]] library. It is expected that libraries for the new, limited environment need to be specially designed.
+
Unlike other similar efforts, the goal of this project is '''not''' to execute any existing [[Java]] library. It is expected that libraries for the new, limited environment need to be specially designed. For example one cannot start new threads (as of [[Bck2Brwsr 0.13]] even there is a [[Bck2BrwsrThreading|proposal]] to do something with it).
== Demo ==
== Demo ==
-
Right now there are two compilator demos. One is generating the [[JavaScript]] during compile phase ([http://hudson.apidesign.org/hudson/job/bck2brwsr/lastSuccessfulBuild/artifact/javaquery/demo-calculator/target/classes/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml try here]). That is no longer the most interesting one.
+
The current flagship demo is [[MineSweeper]] running in the browser: http://xelfi.cz/minesweeper/bck2brwsr/
 +
 
 +
As a memento it makes sense to keep in mind the little [http://xelfi.cz/calc calculator demo] showing the first application that [[User:JaroslavTulach|I]] managed to get running in the browser. The application is packaged in a [[JAR]] file and the [[Bck2Brwsr]] [[VM]] loads necessary classes and transforms them into [[JavaScript]] on the fly.
 +
 
 +
There is/was (relatively) enhanced [[Twitter]] demo showing various technologies including [[JSON]]P communication with the server. However as [[Twitter]] abandoned its authorization free [[API]] in May 2013, the communication with the server is broken.
 +
 
 +
For [[JavaOne2013]] I developed a [http://xelfi.cz/JavaOneChess chess application] showing use of [[knockout.js]] from a [[Java]] code. See [[Knockout4Java]].
 +
 
 +
To demonstrate my geolocation API, I created another [http://xelfi.cz/kde/ Where are you?] demo.
 +
 
 +
We also managed to port [[JavaFX]] to [[Bck2Brwsr]] and here is a [http://xelfi.cz/fishsim proof of that]. There is an overhead to load [[JavaFX]] scene graph [[API]], so excuse slight delay when downloading and booting the app. When finally running, the performance should be OK.
 +
 
 +
 
 +
{{#ev:youtube|8_ctzB0UQwM}}
 +
 
 +
[[Category:Video]]
 +
 
 +
== [[Bck2BrwsrViaCLI|Try It Yourself]]! ==
 +
 
 +
It is simple to try [[Bck2Brwsr]]! The project skeleton is provided as [[Maven]] archetype. Follow steps described at [[Bck2BrwsrViaCLI]] or [[Knockout4Java]] tutorial.
 +
 
 +
== What is in New Releases? ==
 +
 
 +
=== Next Version [[Bck2Brwsr 0.55|0.55]] Will ... ===
 +
 
 +
{{:Bck2Brwsr 0.55}}
 +
 
 +
=== Version [[Bck2Brwsr 0.54|0.54]] ===
 +
 
 +
{{:Bck2Brwsr 0.54}}
 +
 
 +
=== Version [[Bck2Brwsr 0.53|0.53]] ===
 +
 
 +
{{:Bck2Brwsr 0.53}}
 +
 
 +
=== Version [[Bck2Brwsr 0.52|0.52]] ===
 +
 
 +
{{:Bck2Brwsr 0.52}}
 +
 
 +
=== Version [[Bck2Brwsr 0.51|0.51]] ===
 +
 
 +
{{:Bck2Brwsr 0.51}}
 +
 
 +
=== Version [[Bck2Brwsr 0.50|0.50]] ===
 +
 
 +
{{:Bck2Brwsr 0.50}}
 +
 
 +
=== Older Releases ===
 +
 
 +
See the full [[Bck2BrwsrChangeLog]] for historical information about older releases.
 +
 
 +
== Wishlist ==
-
There is also a demo that is using classes packaged in [[JAR]] files. That is in my opinion more interesting as it shows how easy it is to reuse (simple) libraries in your browser as well as on your server. [http://xelfi.cz/bck2brwsr/ Try it here]!
+
The [[Bck2Brwsr]] system is capable to run and execute meaningful applications. Anyway there remains things to be improved and fixed. Any help is welcomed. Just let me know if something interests you:
-
== TODO ==
+
* [[Debugger]] of [[Java]] (and not [[JavaScript]]) using properly generated source maps would be good
-
Although the system is capable to run and execute trivial applications, there remains tons of things to improve and fix. Any help is welcomed. Just let me know if something interests you:
+
== Resources ==
-
* Throwing and catching exceptions - ''Tomáš Z.'' volunteered
+
* [http://github.com/jtulach/bck2brwsr Project page] at GitHub
-
* Speed (e.g. rewrite to register based system) - ''Ľubomír'' is working on the [http://hudson.apidesign.org/hudson/job/bck2brwsr.registers/ prototype]
+
* [mailto:bck2brwsr@apidesign.org Mailing list] and its [https://groups.google.com/d/forum/bck2brwsr archive]
-
** different variables for different types
+
* As of January 2017 [[I]] am moving the development to [https://github.com/jtulach/bck2brwsr GitHub] - (the original [http://source.apidesign.org/hg/bck2brwsr repository] remains read-only).
-
* Speed - benchmark and infrastructure to measure it in various environments - ''Martin Š.'' investigating
+
* [https://maven.java.net/content/repositories/releases/org/apidesign/bck2brwsr/ Maven Repository at java.net]
-
** Run with ''-Dbck2brwsr.runBenchmarks.browsers=firefox,chromium-browser'' (or any other browsers you want to test)
+
* [[Bck2BrwsrJavadoc|Javadoc]]
-
* Speed - use [http://openjdk.java.net/projects/graal/ Graal's] flow analyzer
+
-
** look into the '''GraphBuilderPhase''' class and see how it creates SSA form (using '''FrameStateBuilder''')
+
-
** '''BciBlockMapping''' class that is used for creating structured control flow from byte codes.)
+
-
* More precise number support (int32, int64, float, etc.)
+
-
* [[API]] for drawing on the canvas
+
-
* Convertor from [[GWT]]'s native code to [[Bck2Brwsr]]'s ''@JavaScriptBody''
+
-
* Method overriding with various modifiers
+
-
* Compatibility tests
+
-
* Basic reflection support (e.g. [[Bck2Brwsr]] throws {{JDK|java/lang|SecurityException}} when allowed),
+
-
** '''Done''': Class.newInstance() works.
+
-
** '''Done''': Class.getMethods() works and parameterless methods can be invoked.
+
-
** '''Done''': Annotations of classes and methods
+
-
* Debugger of [[Java]] (and not [[JavaScript]] would be good)
+
-
* [[Maven]] archetype for creating the calculator like demos
+
-
** with translation in the browser
+
-
'''Done:'''
 
-
* Support for converting [[ByteCode]] in the browser
+
[[Category:Bck2Brwsr]]
 +
[[Category:OpenSourceContribution]]

Current revision

Bck2Brwsr VM is a Java virtual machine which is capable to take bytecode and convert it (either ahead-of-time e - e.g. during compilation - or just-in-time, e.g. in a browser) into appropriate JavaScript code which does the same thing. As a result one can write in Java, compile with JavaC, process it with Bck2Brwsr (usually via its Maven plugin, but possibly also directly via programmatic APIs) into a JavaScript file(s) that can be executed in any modern browser (IE 10 at least, please).

The easiest way to start is to play with a DEW - the Development Environment for Web. Just visit http://dew.apidesign.org/dew and edit, compile, run in a browser without installing anything or using (now banned) Java plugins.

The Bck2Brwsr project supports the generic and portable HTML/Java APIs as defined by NetBeans. Use them to run your application on desktop as a standalone application, as a NetBeans or Eclipse plugin or in a browser, via Bck2Brwsr VM.

Contents

Motivation

During my duties at JavaOne2012 my feeling (primed by observing various RSS feeds full of posts about something which ends .js) that Java is no longer as cool as it used to be straightened. It always starts by loosing interest of newcomers, targeting just a piece of the technology segment and soon once Good Technology becomes new COBOL. Can that happen to Java? Just read Is JavaScript the Future of Programming? and (if you like Java), you'll get scared. I decided to do something about that. I'd like to return my favorite programming language Bck2Brwsr.

Licensing

The code of Bck2Brwsr is heavily derived from OpenJDK source code (especially the libraries part, not the HotSpot part). Bck2Brwsr thus needs to match the OpenJDK licensing and be compatible with it. The licensing goal is however the same as in case of OpenJDK:

  • if you write your application and execute it against standard JDK libraries - use the classpath exception
  • if you hack the Bck2Brwsr VM itself - follow the GPLv2 license

This kind of setup should give Java developers freedom to build their applications and distribute them under conditions of their choose, while making sure modifications, enhancements and improvements of the Bck2Brwsr VM code itself remain publicly available.

Goals

Create small Java (check the Bck2BrwsrJavadoc) capable to boot fast and run in 100% of modern browsers including those that have no special support for Java.

Demonstrate that Java has benefits over JavaScript when creating larger HTML5 applications.

Unlike other similar efforts, the goal of this project is not to execute any existing Java library. It is expected that libraries for the new, limited environment need to be specially designed. For example one cannot start new threads (as of Bck2Brwsr 0.13 even there is a proposal to do something with it).

Demo

The current flagship demo is MineSweeper running in the browser: http://xelfi.cz/minesweeper/bck2brwsr/

As a memento it makes sense to keep in mind the little calculator demo showing the first application that I managed to get running in the browser. The application is packaged in a JAR file and the Bck2Brwsr VM loads necessary classes and transforms them into JavaScript on the fly.

There is/was (relatively) enhanced Twitter demo showing various technologies including JSONP communication with the server. However as Twitter abandoned its authorization free API in May 2013, the communication with the server is broken.

For JavaOne2013 I developed a chess application showing use of knockout.js from a Java code. See Knockout4Java.

To demonstrate my geolocation API, I created another Where are you? demo.

We also managed to port JavaFX to Bck2Brwsr and here is a proof of that. There is an overhead to load JavaFX scene graph API, so excuse slight delay when downloading and booting the app. When finally running, the performance should be OK.


Try It Yourself!

It is simple to try Bck2Brwsr! The project skeleton is provided as Maven archetype. Follow steps described at Bck2BrwsrViaCLI or Knockout4Java tutorial.

What is in New Releases?

Next Version 0.55 Will ...

Bck2Brwsr 0.55

Version 0.54

  • Support Class.getPackage() - #45
  • Better lambda support - #49
  • Ability to process pre-JDK1.6 class files - d2100cf02

Version 0.53

  • Bugfix for the Heartbeat support to use it only when connecting to localhost via HTTP

Version 0.52

  • Fastforward seven years and updating Closure compiler to version v20210601 - required bunch of fixes of unused variables, wrong code, etc.
  • Checking ClassCastException before calling lambda methods
  • Using importScripts when Bck2Brwsr is used in a Worker

Version 0.51

Version 0.51 of Bck2Brwsr VM is even better than Bck2Brwsr 0.50:

  • Important bugfixes for Gradle --continuous mode
  • Improved emulation of java.util.function and java.util.stream packages

Version 0.50

The Bck2Brwsr project has been updated to work with 2021 technologies:

No more RetroLambda. Instead of RetroLambda there is now an abstract IndyHandler interface with two implementations:

The removal of RetroLambda is a good thing - the system was fragile. It relied on reflection and internal behavior of JDKs. However, replacing it with homemade implementation is a request for regressions - finding and supporting all the corner cases is going to take some time. Thanks to Johan Vos, who managed to compile JavaFX with Bck2Brwsr transpiler and reported quite a few bugs. The likehood Bck2Brwsr 0.50 is going to work is now higher!


The easiest way to report an error is to enhance one of existing test-cases:

Thanks in advance for trying and helping Bck2Brwsr to get better!

Older Releases

See the full Bck2BrwsrChangeLog for historical information about older releases.

Wishlist

The Bck2Brwsr system is capable to run and execute meaningful applications. Anyway there remains things to be improved and fixed. Any help is welcomed. Just let me know if something interests you:

Resources

Personal tools
buy