How to insert Java code in html?

0

Hello everyone, I would like to know if it is possible to insert Java code in html, since I am trying to do a Java encryption program myself and put it inside the html.

I'm asking here why I have not found anywhere about whether it's possible and how to put it.

    
asked by anonymous 20.05.2016 / 21:59

1 answer

5

Before now yes .

Until recently my answer would be:

  

You need to use an applet for this because you can not insert the   Java directly in HTML. Applets are getting more and more   restricted and soon I think there will be no support for Java applets   (they are very insecure).

But ... a project I met recently changed my answer to:

  

Yes is possible and using JavaScript!

This project is JavaPoly.js more information at link .

This is a library that allows you to have Java (JVM) support in browsers.

As an example you can do this in HTML:

<!-- Include the Polyfill -->
<script src="https://www.javapoly.com/javapoly.js"></script><!--WriteyourJavacode--><scripttype="text/java">
  package com.demo;
  import com.javapoly.dom.Window;

  public class Greeter
  {
    public static void sayHello(String name)
    {
      Window.alert("Hello " + name + ", from Java!");
    }
  }
</script>

<!-- Invoke your Java code from Javascript -->
<script type="text/javascript">
  com.demo.Greeter.sayHello("world");
</script>

Yes, this is Java in HTML!

Give up to import libraries:

<!-- Include the Polyfill -->
<script src="https://www.javapoly.com/javapoly.js"></script><!--IncludeyourfavoriteJavalibraries(jarfiles)--><scripttype="text/java" src="http://www.yourdomain.com/jimboxutilities.jar"></script><scripttype="text/java" src="http://www.yourdomain.com/guava.jar"></script><scripttype="text/java" src="http://www.yourdomain.com/apache-commons.jar"></script><!--Or,includeindividual.classfiles--><scripttype="text/java" src="http://www.yourdomain.com/com/yourpackage/Foo.class"></script><scripttype="text/java" src="http://www.yourdomain.com/com/yourpackage/Noise.class"></script><!--Orjustincludethesourcedirectly--><scripttype="text/java" src="http://www.yourdomain.com/com/yourpackage/Bar.java"></script><scripttype="text/java" src="http://www.yourdomain.com/com/yourpackage/Girls.java"></script>

Note:NeverconfuseJavawithJavaScript link .

Note 2: I have never used it, it seems to me to be something recent and I do not know the support yet. But before we respond that it does not, I think it's good to know that there are people thinking about it.

Here's the result of Try It Yourself that's on the guys' website.

    
20.05.2016 / 22:09