src/main/javadoc/overview.html
author Jaroslav Tulach <jtulach@netbeans.org>
Wed, 12 Nov 2014 10:48:12 +0100
branchgc
changeset 870 77bff7390451
parent 852 e5723aecdaff
child 892 de02b7c13379
permissions -rw-r--r--
No longer needed model instances can be garbage collected
     1 <!--
     2 
     3     DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     4 
     5     Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
     6 
     7     Oracle and Java are registered trademarks of Oracle and/or its affiliates.
     8     Other names may be trademarks of their respective owners.
     9 
    10     The contents of this file are subject to the terms of either the GNU
    11     General Public License Version 2 only ("GPL") or the Common
    12     Development and Distribution License("CDDL") (collectively, the
    13     "License"). You may not use this file except in compliance with the
    14     License. You can obtain a copy of the License at
    15     http://www.netbeans.org/cddl-gplv2.html
    16     or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    17     specific language governing permissions and limitations under the
    18     License.  When distributing the software, include this License Header
    19     Notice in each file and include the License file at
    20     nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    21     particular file as subject to the "Classpath" exception as provided
    22     by Oracle in the GPL Version 2 section of the License file that
    23     accompanied this code. If applicable, add the following below the
    24     License Header, with the fields enclosed by brackets [] replaced by
    25     your own identifying information:
    26     "Portions Copyrighted [year] [name of copyright owner]"
    27 
    28     Contributor(s):
    29 
    30     The Original Software is NetBeans. The Initial Developer of the Original
    31     Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
    32 
    33     If you wish your version of this file to be governed by only the CDDL
    34     or only the GPL Version 2, indicate your decision by adding
    35     "[Contributor] elects to include this software in this distribution
    36     under the [CDDL or GPL Version 2] license." If you do not indicate a
    37     single choice of license, a recipient has the option to distribute
    38     your version of this file under either the CDDL, the GPL Version 2 or
    39     to extend the choice of license to its licensees as provided above.
    40     However, if you add GPL Version 2 code and therefore, elected the GPL
    41     Version 2 license, then the option applies only if the new code is
    42     made subject to such option by the copyright holder.
    43 
    44 -->
    45 <!DOCTYPE html>
    46 <html>
    47     <head>
    48         <title>HTML for Java APIs</title>
    49         <meta charset="UTF-8">
    50         <meta name="viewport" content="width=device-width, initial-scale=1.0">
    51     </head>
    52     <body>
    53         <p>
    54          Use Java to write application logic; Use HTML5 to render the UI; 
    55          {@link net.java.html.json.Model Animate an HTML page from Java}
    56          (see <a target="_blank" href="http://dew.apidesign.org/dew/#7212206">Duke being rotated</a> by CSS);
    57          Use {@link net.java.html.json.OnReceive REST} or
    58          <a href="net/java/html/json/doc-files/websockets.html">WebSockets</a>;
    59          interact with <a href="net/java/html/js/package-summary.html">JavaScript</a>;
    60          Get the best of both worlds!
    61          
    62          The goal of these APIs is to use full featured Java runtime 
    63          (like real <a href="http://wiki.apidesign.org/wiki/HotSpot">HotSpot VM</a>), 
    64          but still rely on a very lightweight rendering technology 
    65          (so it can potentially fit 
    66          <a href="http://bck2brwsr.apidesign.org">Bck2Brwsr</a> and definitely
    67          to various types of phones). What can be more lightweight 
    68          (from a browser perspective) than 
    69          <a href="http://wiki.apidesign.org/wiki/HTML">HTML</a>!?
    70          By default we use {@link net.java.html.boot.fx JavaFX's WebView} 
    71          component to display the <a href="http://wiki.apidesign.org/wiki/HTML">HTML</a>. 
    72          We eliminate the need to manipulate the DOM directly, 
    73          there is a special {@link net.java.html.json Java to Knockout.js binding}. 
    74          As a result the <a href="http://knockoutjs.com">HTML uses Knockout.js syntax</a>, 
    75          yet the application code can be written in Java.
    76         </p>
    77         
    78         <h3>What's New in Version 1.1?</h3>
    79         
    80         <p>
    81             Memory model when using Knockout bindings has been improved
    82             (required additions of two new methods:
    83             {@link org.netbeans.html.json.spi.PropertyBinding#weak()} and
    84             {@link org.netbeans.html.json.spi.FunctionBinding#weak()}) and
    85             now the Java {@link net.java.html.json.Model models} can garbage collect,
    86             when no longer used.
    87         </p>
    88         
    89         <h3>What's New in Version 1.0?</h3>
    90         
    91         <p>
    92             {@link net.java.html.json.Property#array() Array properties} are now
    93             mutable from the <a href="http://knockoutjs.com">knockout.js</a>
    94             point of view (required {@link org.netbeans.html.json.spi.Proto.Type#replaceValue one SPI change}).
    95             The page lookup mechanism can use {@link net.java.html.boot.BrowserBuilder#locale(java.util.Locale) locale}
    96             to load localized a page with appropriate suffix.
    97             All SPI were moved under the NetBeans namespace - e.g.
    98             {@link org.netbeans.html.boot.spi},
    99             {@link org.netbeans.html.context.spi},
   100             {@link org.netbeans.html.json.spi},
   101             {@link org.netbeans.html.sound.spi}, and also
   102             {@link org.netbeans.html.json.tck}. Methods annotated
   103             with {@link net.java.html.js.JavaScriptBody} annotation and
   104             without fallback Java code now throw {@link java.lang.IllegalStateException}
   105             with a message suggesting to switch to proper
   106             {@link net.java.html.BrwsrCtx#execute browser context} to
   107             prevent endless debugging when one forgets to do so.
   108         </p>
   109         
   110         <h3>What's New in Version 0.9?</h3>
   111         
   112         <p>
   113             System can run in {@link net.java.html.boot.BrowserBuilder#classloader(java.lang.ClassLoader) Felix OSGi container} (originally only Equinox).
   114             {@link net.java.html.json.ComputedProperty Derived properties}
   115             now deeply check changes in other {@link net.java.html.json.Model model
   116             classes} they depend on and recompute their values accordingly.
   117             <a target="_blank" href="http://knockoutjs.com">Knockout.js</a> library has been updated
   118             to version 3.2.0.
   119         </p>
   120         
   121         <h3>What's New in 0.8.x Versions?</h3>
   122         
   123         <p>
   124             Setters or array properties on classes generated by {@link net.java.html.json.Model}
   125             annotation can be accessed from any thread. {@link org.netbeans.html.sound.spi.AudioEnvironment}
   126             can be registered into {@link net.java.html.BrwsrCtx}. There is
   127             a {@link net.java.html.json.Models#parse(net.java.html.BrwsrCtx, java.lang.Class, java.io.InputStream, java.util.Collection)  method}
   128             to parse a JSON array and convert it into 
   129             {@link net.java.html.json.Model model classes}.
   130             Improved behavior of <code>enum</code> values in 
   131             {@link net.java.html.json.Model knockout bindings}.
   132         </p>
   133         
   134         <p>
   135             Few bugfixes for better portability. 
   136             New API for {@link net.java.html.boot.script.Scripts headless execution}
   137             on top of <em>Nashorn</em> - does not run <em>knockout for Java</em>
   138             fully yet 
   139             (reported as <a href="https://bugs.openjdk.java.net/browse/JDK-8046013">JDK-8046013</a>),
   140             however even in current state it is quite 
   141             {@link net.java.html.boot.script.Scripts useful for testing}
   142             of 
   143             {@link net.java.html.js Java/JavaScript interactions}.
   144         </p>
   145         
   146         <p>
   147             {@link net.java.html.boot.fx.FXBrowsers} has been extended
   148             with new helper methods to make it easier to use HTML+Java
   149             API in existing JavaFX applications.
   150             The annotation processor is made
   151             more robust with respect to errors in callback syntax of
   152             {@link net.java.html.js.JavaScriptBody} body parameter.
   153             Javadoc of {@link net.java.html.BrwsrCtx#execute} method
   154             has been improved based on a failure of its usability study.
   155             There can be additional parameters to methods annotated by
   156             {@link net.java.html.json.OnReceive} that allows one to
   157             pass state when a JSON call is made and use it when it finishes.
   158             The mechanism of discovery of sibling HTML page has been
   159             extended to work on systems that don't support
   160             {@link java.lang.Class#getProtectionDomain}.
   161         </p>
   162         
   163         <p>
   164             The first argument of method annotated by
   165             {@link net.java.html.json.OnReceive} annotation has to
   166             be the associated {@link net.java.html.json.Model model class}.
   167         </p>
   168         
   169         <p>
   170             {@link net.java.html.json.OnReceive} annotation now accepts
   171             {@link java.util.List} of data values as second argument
   172             (previously required an array).
   173         </p>
   174         
   175         
   176         <h3>What's New in Older Versions?</h3>
   177         
   178         <p>
   179             {@link net.java.html.js.JavaScriptBody} annotation has new attribute
   180             {@link net.java.html.js.JavaScriptBody#wait4js()} which allows
   181             asynchronous execution. Libraries using
   182             {@link net.java.html.js.JavaScriptBody} are urged to use this
   183             new attribute as much as possible, as it can speed up execution
   184             in certain environments.
   185         </p>
   186         
   187         <p>
   188             Use {@link net.java.html.BrwsrCtx#execute(java.lang.Runnable)} in
   189             multi-threaded environment to execute your code on the browser thread.
   190             See example 
   191             {@link net.java.html.BrwsrCtx#execute(java.lang.Runnable) using Java timer}.
   192         </p>
   193         
   194         <h3>Interesting Entry Points</h3>
   195         
   196         <p>Learn how to {@link net.java.html.json.Model animate an HTML page from Java}
   197             without referencing single HTML element from the Java code.
   198         </p>
   199         <p>Use {@link net.java.html.json.OnReceive JSON} to communicate
   200             with REST based server API.
   201         </p>
   202         <p>Use <a href="net/java/html/json/doc-files/websockets.html">WebSockets</a>
   203             and JSON.
   204         </p>
   205         <p>Call JavaScript methods from Java and vice versa, via
   206             <a href="net/java/html/js/package-summary.html">JavaScriptBody</a>.
   207         </p>
   208 
   209         <h3>Getting Started</h3>
   210 
   211         There are <a href="http://wiki.apidesign.org/wiki/DukeScriptInNetBeans">many ways</a> 
   212         to start developing 
   213         <a href="http://html.java.net">Html for Java</a> application. 
   214         However to be sure one chooses the most recent setup, it is recommended
   215         to switch to good old command line and use a 
   216         <a href="http://wiki.apidesign.org/wiki/Knockout4Java">Maven archetype</a>
   217         associated with every version of this project. Make sure at least 
   218         <em>JDK7</em> is your installed Java and type:
   219         <pre>      
   220 $ mvn archetype:generate \
   221  -DarchetypeGroupId=org.apidesign.html \
   222  -DarchetypeArtifactId=knockout4j-archetype \
   223  -DarchetypeVersion=0.8 <em># or newer version, if available</em>
   224         </pre>
   225         Answer few questions (for example choose myfirstbrwsrpage as artifactId) 
   226         and then you can:
   227         <pre>
   228 $ cd myfirstbrwsrpage
   229 $ mvn process-classes exec:java
   230         </pre>
   231         In a few seconds (or minutes if 
   232         <a href="http://wiki.apidesign.org/wiki/Maven">Maven</a>
   233         decides to download the whole Internet of dependencies) you should 
   234         see a sample Hello World application rendered in a 
   235         <a href="http://wiki.apidesign.org/wiki/JavaFX">JavaFX</a>
   236         web view component (that of course requires your JDK to come
   237         with <a href="http://wiki.apidesign.org/wiki/JavaFX">JavaFX</a>; 
   238         <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">JDK7 
   239             and JDK8 from Oracle</a> contain everything that is needed). 
   240         The generated application is built around one 
   241         Java source (uses the {@link net.java.html.json.Model} annotation to
   242         auto-generate another <code>Data.java</code> class during compilation)
   243         and one HTML file (uses the <a href="http://knockoutjs.com">Knockout</a>
   244         syntax to <code>data-bind</code> the HTML elements to the 
   245         generated <code>Data</code> model):
   246         <pre>
   247 $ ls src/main/java/**/DataModel.java
   248 $ ls src/main/webapp/pages/index.html
   249         </pre>
   250         That is all you need to get started. Play with the sources, 
   251         modify them and enjoy
   252         <a href="http://html.java.net">Html for Java</a>!
   253         
   254         <h2>IDE Support</h2>
   255         
   256         <p>
   257             This API is part of <a target="_blank"
   258             href="http://netbeans.org">NetBeans.org</a> project and as such
   259             it works naturally with the <a target="_blank"
   260             href="https://netbeans.org/features/index.html">NetBeans IDE</a>.
   261             On the other hand, the API is using nothing NetBeans specific,
   262             it builds on standard Java6 APIs and as such it shall work fine
   263             in any IDE.
   264         </p>
   265         
   266         <p>
   267             A lot of work is done by 
   268             <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">
   269             annotation processors</a>
   270             that generate various boiler plate code during compilation. This
   271             is a standard part of Java since JDK6, but for example Eclipse
   272             is known not to deal with processors well and developers using
   273             it need to be careful. IntelliJ users hasn't reported any issues
   274             and of course, NetBeans IDE support for 
   275             <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">processors</a>
   276             is outstanding.
   277         </p>
   278         
   279         <p>
   280             When using {@link net.java.html.js.JavaScriptBody} annotation, it is
   281             useful to do a bit of post processing of classes. There is a
   282             <a href="http://wiki.apidesign.org/wiki/Maven">Maven</a> 
   283             plugin for that.
   284             NetBeans IDE will invoke it when doing a build. Other IDEs may 
   285             need some hint to do so. 
   286             Anyway: If one does not see all (generated) sources or is getting
   287             {@link java.lang.LinkageError}s when executing the application, 
   288             switch to command line and do clean build
   289             from there:
   290         </p>
   291         <pre>$ mvn clean install</pre>
   292         <p>
   293             If that succeeds, your IDE of choice will hopefully
   294             pick the generated sources up and present the result of the build 
   295             properly. If not, 
   296             <a href="https://netbeans.org/downloads/">download NetBeans</a>, 
   297             you will be pleasantly 
   298             surprised - for example with our excellent 
   299             <a href="net/java/html/js/package-summary.html#debugging">Java/JavaScript 
   300             debugging</a> support.
   301         </p>
   302         
   303         <a name="deploy">
   304         <h2>Deploy Your Application</h2>
   305         </a>
   306         
   307         <p>
   308         It is not goal of this documentation to list all possible ways
   309         to package and deploy applications which use this API. However it is 
   310         important for new comers to see the benefits of using the
   311         <a href="http://html.java.net">HTML for Java</a> API and as such
   312         let's list at least few bundling options, known to work at the time of writing 
   313         this documentation.
   314         </p>
   315         
   316         <p>
   317         First of all, this is a <em>client technology</em>. You write client applications
   318         with it which may, but need not connect to a server. You don't need
   319         Tomcat or WebLogic to deploy 
   320         <a href="http://html.java.net">HTML for Java</a> applications.
   321         </p>
   322         
   323         <p>
   324             <img src='resources/javafx_logo.jpg' width="64"
   325                  height="64" align="left"/>
   326             The sample project generated by
   327             <code>org.apidesign.html knockout4j-archetype</code> is configured
   328             to use <a href="http://wiki.apidesign.org/wiki/JavaFX">JavaFX</a>
   329             as the rendering technology. This setup is primarily suitable for 
   330             development - it needs no special packaging, starts quickly and
   331             allows you to use classical HotSpot VM debuggers. A final 
   332             artifact from the build is also a ZIP file which you can use
   333             and distribute to your users. Good for desktop applications.
   334         </p>
   335         
   336         <p>
   337             <img src='resources/netbeans_logo.jpg' width="64"
   338                  height="64" align="right"/>
   339             <img src='resources/eclipse_logo.png' width="64"
   340                  height="64" align="right"/>
   341             All the <a href="http://html.java.net">HTML for Java</a> libraries
   342             are packaged as <a href="http://wiki.apidesign.org/wiki/OSGi">OSGi</a>
   343             bundles and as such they can easily be run in NetBeans as well as
   344             in Eclipse. As a result one can use 
   345             <a href="http://wiki.apidesign.org/wiki/OSGi">OSGi</a>
   346             and have a common module system for both platforms. In addition to that 
   347             one can render using
   348             HTML and have a common UI in both platforms. In such case
   349             your application would be packaged as a set of
   350             <a href="http://wiki.apidesign.org/wiki/OSGi">OSGi</a> bundles.
   351             Read 
   352             <a href="http://wiki.apidesign.org/wiki/HTML">more</a>...
   353         </p>
   354         
   355         <p>
   356             <img src='resources/chrome_logo.png' width="64"
   357                  height="64" align="left"/>
   358             <img src='resources/safari_logo.png' width="64"
   359                  height="64" align="left"/>
   360             <img src='resources/ie_logo.png' width="64"
   361                  height="64" align="left"/>
   362             <img src='resources/firefox_logo.png' width="64"
   363                  height="64" align="left"/>
   364             
   365             There is more and more attempts to execute Java bytecode
   366             in a browser, without any special Java plugin installed.
   367             The <a href="http://html.java.net">HTML for Java</a> is
   368             carefully designed to produce lightweight, well performing
   369             applications even on such restricted environments. It uses
   370             no reflection calls and that allows to statically pre-compile
   371             the applications into JavaScript. One of such environments
   372             is called <a href="http://wiki.apidesign.org/wiki/Bck2Brwsr">Bck2Brwsr</a>, 
   373             another <a href="http://wiki.apidesign.org/wiki/TeaVM">TeaVM</a>. Both support the
   374             {@link net.java.html.js.JavaScriptBody} annotation. Read 
   375             <a href="http://wiki.apidesign.org/wiki/Bck2BrwsrViaCLI">more</a> or play
   376             a minesweeper game packaged for your browser 
   377             (of course <a target="_blank"
   378                 href="http://source.apidesign.org/hg/html~demo/file/ea79b73d590a/minesweeper/src/main/java/org/apidesign/demo/minesweeper/MinesModel.java">
   379                 written</a> in Java):
   380         </p>
   381         
   382         <script type="text/html" id="field">
   383             <table class="field">
   384                 <tbody>
   385                     <!-- ko foreach: rows -->
   386                     <tr>
   387                         <!-- ko foreach: columns -->
   388                         <td data-bind="css: style, click: $parents[1].click" >
   389                             <div data-bind='html: html'></div>
   390                         </td>
   391                         <!-- /ko -->
   392                     </tr>
   393                     <!-- /ko -->
   394                 </tbody>
   395             </table>
   396         </script>
   397 
   398         <div data-bind="template: { name : 'field', if: fieldShowing }"></div>
   399 
   400         <!-- boot bck2brwsr -->
   401         <script type="text/javascript" src="resources/teavm.js"></script>
   402         <script>
   403             var vm = new VM();
   404             vm.loadClass('org.apidesign.demo.minesweeper.MainBrwsr');
   405         </script>
   406 
   407         <p>
   408             <img src='resources/ios_logo.jpg' width="64"
   409                  height="64" align="right"/>
   410             <img src='resources/android_logo.jpg' width="64"
   411                  height="64" align="right"/>
   412             
   413             Now when we have seen that the 
   414             <a href="http://html.java.net">HTML for Java</a> applications 
   415             can run on any modern browser, we can ask whether they can also
   416             fit into a phone!? Yes, they can and especially to phones 
   417             that can execute Java code already! Just by changing your
   418             packaging you can create an APK file and deploy it to your
   419             Android phone. 
   420             Read <a target="_blank" href="http://wiki.apidesign.org/wiki/DlvkBrwsr">more</a>...
   421             In case you'd like your application to reach out to second biggest
   422             group of smartphone users, don't despair: It 
   423             seems the set of devices that can execute
   424             <a href="http://html.java.net">HTML for Java</a> applications 
   425             has been extended to <em>iPads</em> and <em>iPhones</em>. Get the 
   426             <a target="_blank" href="http://wiki.apidesign.org/wiki/IBrwsr">details here</a>
   427             and deploy everywhere!
   428         </p>
   429         <p>
   430             Convinced it makes sense to use 
   431             <a href="http://html.java.net">HTML for Java</a>
   432             APIs for writing applications that are 
   433             <em>written once, displayed anywhere</em>? Or do you have an
   434             environment which is not supported? In such case you can bring
   435             <a href="http://html.java.net">HTML for Java</a>
   436             to your environment yourself. Just implement your own
   437             {@link org.netbeans.html.boot.spi.Fn.Presenter}!
   438         </p>
   439         
   440         <h2>Other Resources</h2>
   441         
   442         <img src="net/java/html/json/doc-files/DukeHTML.png" width="256" height="184" alt="Duke and HTML5. Together at last!" align="right"/>
   443         
   444         The javadoc for latest and previous versions is also available
   445         online:
   446         <ul>
   447             <li>Current <a target="_blank" href="http://bits.netbeans.org/html+java/dev/">development</a> version
   448             <li>Version <a target="_blank" href="http://bits.netbeans.org/html+java/0.8.3">0.8.3</a>
   449             <li>Version <a target="_blank" href="http://bits.netbeans.org/html+java/0.8.2">0.8.2</a>
   450             <li>Version <a target="_blank" href="http://bits.netbeans.org/html+java/0.8.1">0.8.1</a>
   451             <li>Version <a target="_blank" href="http://bits.netbeans.org/html+java/0.8">0.8</a>
   452             <li>Version <a target="_blank" href="http://bits.netbeans.org/html+java/0.7.5">0.7.5</a>
   453         </ul>
   454         
   455 <style type="text/css">
   456 table.field td {
   457     padding: 4px;
   458     width: 18px;
   459     height: 18px;
   460     font-size: 1.5em;
   461     border: 1px solid black;
   462 }
   463 table.field td.UNKNOWN {
   464     background-color: #D6E4E1;
   465     cursor: pointer;
   466 }
   467 table.field td.EXPLOSION {
   468     background-color: #A31E39;
   469 }
   470 table.field td.DISCOVERED {
   471     background-color: #9DB2B1;
   472 }
   473 </style>        
   474     </body>
   475 </html>