bujbot
Posts: 4
Joined: Sun Sep 13, 2015 1:19 pm

Running Java not through a web browser?

Sun Sep 13, 2015 1:59 pm

Hello, I'm sorry if this is a simple questions (or a stupid one), but I need some help. I have googled and searched this forum without luck ... possibly because I'm on a completely lower level than most people talking about Java.

I have an HTML5 program that I want to run on my Pi 2. I have the program hosted on the Pi and can pull it up using any web browser but it is a bit too slow this way. It's my understanding that this HTML5 program is essentially java. So my question is: is it possible to run the java outside of a web browser? I'm not familiar enough with Java to know if this is a bad question ... maybe Java is only usable through a web browser?

Thanks in advance. If anyone has any other ideas, please let me know. I have tried changing between Oracle 7, 8 and 9. 7 being the best results but all being about the same. I have also tried loading Windows 10 IoT on the Pi and uploaded the program as a Windows Univseral app, only to learn that the program may run in the background but no UI is available with Java on Windows 10 IoT ... only C++ and C#.

This is my main setup:
Pi 2; running Ubuntu Mate, slightly overclocked, firefox as the web browser (Chromium hangs and locks up).

I also have another SD card running Raspbian with similar results to the Ubuntu Mate.

Thank you again

User avatar
xranby
Posts: 540
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: Running Java not through a web browser?

Sun Sep 13, 2015 6:23 pm

bujbot wrote: I have an HTML5 program that I want to run on my Pi 2. I have the program hosted on the Pi and can pull it up using any web browser but it is a bit too slow this way.

It's my understanding that this HTML5 program is essentially java.
If your HTML5 page is served by a "java server" then you are right that the program is essentially java.
It is very common to have a java server producing HTML pages.
Please explain better how someone else can setup and run your project, that would make it clearer how we can help you.
bujbot wrote: So my question is: is it possible to run the java outside of a web browser? I'm not familiar enough with Java to know if this is a bad question ... maybe Java is only usable through a web browser?
It is easy to run java outside the browser.
If you have a java program such as the HelloWorld.java containing

Code: Select all

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello, World");
    }

}
then you can compile it using
javac HelloWorld.java

and run it using
java HelloWorld
bujbot wrote: Thanks in advance. If anyone has any other ideas, please let me know. I have tried changing between Oracle 7, 8 and 9. 7 being the best results but all being about the same. I have also tried loading Windows 10 IoT on the Pi and uploaded the program as a Windows Univseral app, only to learn that the program may run in the background but no UI is available with Java on Windows 10 IoT ... only C++ and C#.
Thank you for describing that it is possible to run java on the Windows 10. If you really can run java in the background without UI then you should be able to invent your own UI library using Java because java can talk to low level system library's using JNI, the Java Native Interface.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

bujbot
Posts: 4
Joined: Sun Sep 13, 2015 1:19 pm

Re: Running Java not through a web browser?

Sun Sep 13, 2015 9:42 pm

xranby wrote:
bujbot wrote: I have an HTML5 program that I want to run on my Pi 2. I have the program hosted on the Pi and can pull it up using any web browser but it is a bit too slow this way.

It's my understanding that this HTML5 program is essentially java.

If your HTML5 page is served by a "java server" then you are right that the program is essentially java.
It is very common to have a java server producing HTML pages.
Please explain better how someone else can setup and run your project, that would make it clearer how we can help you.


Hi Xranby and thank you for the response.
Now I'm going to go and embarrass myself ... because it's actually javascript not java. Which is (again to my limited understanding) only web based.

xranby wrote:
bujbot wrote: So my question is: is it possible to run the java outside of a web browser? I'm not familiar enough with Java to know if this is a bad question ... maybe Java is only usable through a web browser?


It is easy to run java outside the browser.
If you have a java program such as the HelloWorld.java containing

Code: Select all

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello, World");
    }

}
then you can compile it using
javac HelloWorld.java

and run it using
java HelloWorld
[/size]

Knowing about javac is useful, but like mentioned above I'm an idiot.

xranby wrote:
bujbot wrote: Thanks in advance. If anyone has any other ideas, please let me know. I have tried changing between Oracle 7, 8 and 9. 7 being the best results but all being about the same. I have also tried loading Windows 10 IoT on the Pi and uploaded the program as a Windows Univseral app, only to learn that the program may run in the background but no UI is available with Java on Windows 10 IoT ... only C++ and C#.


Thank you for describing that it is possible to run java on the Windows 10. If you really can run java in the background without UI then you should be able to invent your own UI library using Java because java can talk to low level system library's using JNI, the Java Native Interface.


This is useful information as well. Well beyond my league but could be useful to someone in the future who is searching for some answers. Thanks again Xranby.

So now that I've gone and learned what I needed, I guess replace "java" with "java script" in my original post. Any hope there? They say javascript is very similar to C++ maybe I can convert js to C++?

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: Running Java not through a web browser?

Sun Sep 13, 2015 10:43 pm

I seem to remember that node.js will run javascript locally, maybe you could try that?
There are 10 types of people: those who understand binary and those who don't.

User avatar
xranby
Posts: 540
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: Running Java not through a web browser?

Mon Sep 14, 2015 7:18 am

Java contains the tool jjs that allows you to run javascript using the java virtual machine.

example if you have a test.js file that is using remote javascript librarys and some logic .. like this:

Code: Select all

load('http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js');

var odds = _.filter([1, 2, 3, 4, 5, 6], function (num) {
    return num % 2 == 1;
});

print(odds);  // 1, 3, 5
then you can run this .js file using the java jjs tool.
jjs test.js

and it will output
1,3,5

jjs uses the Nashorn javascript engine, for more information how you can use Nashorn thake a look at the following tutorial:
http://winterbe.com/posts/2014/04/05/ja ... -tutorial/
this tutorial explain how you can mix java and javascript inside the same application.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Running Java not through a web browser?

Mon Sep 14, 2015 8:42 am

@bujbot
Please keep in mind that Java and JavaScript are two different things ( which can be mixed , but for that you need to be able to keep them apart first !)
Also , JavaScript used to be a client-only language to be run inside browsers , which is not
the case anymore with server-side JS with node.js or io.js.

Lastly , do not forget that JavaScript on a node.js server will not execute inside a browser directly ( which is the point of the whole operation anyway).
You need to establish a means of communication between server-side JS and the the client-side JS for that first , perhaps with websockets.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

User avatar
clicky
Posts: 455
Joined: Thu Oct 25, 2012 7:34 am

Re: Running Java not through a web browser?

Mon Sep 14, 2015 12:33 pm

I know it is a digression but it begs being posted here:

http://imgur.com/MilKmny

Apologies in advance to all that doesn't find it funny! ;)

bujbot
Posts: 4
Joined: Sun Sep 13, 2015 1:19 pm

Re: Running Java not through a web browser?

Tue Sep 15, 2015 1:38 am

Thanks everyone. I'll give the ideas a shot and let you know how it goes. Part of the problem is that I was just given the code and asked to get it running on the raspberry pi, so I'm not intimately familiar with it.

I did try compressing the javascript and that actually sped it up a bit ... but not enough to fix this issue.

Clicky, yeah this is a relevant place to put that. A few days ago I wouldn't have gotten the joke :p

User avatar
xranby
Posts: 540
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: Running Java not through a web browser?

Tue Sep 15, 2015 8:12 am

bujbot wrote:I was just given the code and asked to get it running on the raspberry pi
If the code is public domain or free software then you can publish it.
If you are unsure then ask the author to license the code under a public domain or a free software license.
If you cant get a public domain or a free software license then i would suggest you to stop working on the code and create something from scratch because you will be legally bound to the serve limitations of the code if you continue to work on it.

A program is free software if the program's users have the four essential freedoms:
The freedom to run the program as you wish, for any purpose (freedom 0).
The freedom to study how the program works, and change it so it does your computing as you wish (freedom 1). Access to the source code is a precondition for this.
The freedom to redistribute copies so you can help your neighbor (freedom 2).
The freedom to distribute copies of your modified versions to others (freedom 3). By doing this you can give the whole community a chance to benefit from your changes. Access to the source code is a precondition for this.
http://www.gnu.org/philosophy/free-sw.html

public domain (with sourcecode) is free software as well
http://www.gnu.org/philosophy/categories.html

You will get better support if you publish the code so that other people can examine, and use it.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

bujbot
Posts: 4
Joined: Sun Sep 13, 2015 1:19 pm

Re: Running Java not through a web browser?

Thu Sep 17, 2015 2:38 am

xranby wrote:
bujbot wrote:I was just given the code and asked to get it running on the raspberry pi
If the code is public domain or free software then you can publish it.
If you are unsure then ask the author to license the code under a public domain or a free software license.
If you cant get a public domain or a free software license then i would suggest you to stop working on the code and create something from scratch because you will be legally bound to the serve limitations of the code if you continue to work on it.

A program is free software if the program's users have the four essential freedoms:
The freedom to run the program as you wish, for any purpose (freedom 0).
The freedom to study how the program works, and change it so it does your computing as you wish (freedom 1). Access to the source code is a precondition for this.
The freedom to redistribute copies so you can help your neighbor (freedom 2).
The freedom to distribute copies of your modified versions to others (freedom 3). By doing this you can give the whole community a chance to benefit from your changes. Access to the source code is a precondition for this.
http://www.gnu.org/philosophy/free-sw.html

public domain (with sourcecode) is free software as well
http://www.gnu.org/philosophy/categories.html

You will get better support if you publish the code so that other people can examine, and use it.
Hi Xranby. I think I've made this sound sketchier than it is. A friend and I are working on a game/display piece for a local show coming up. I'm good with construction so have made the box that it's going in. He wrote the game in a program called Fusion 2.5 which can spit out an HTML5 code. The box I made runs a raspberry pi and I'm more familiar with them then he is so I'm trying to get it working on it.

I do appreciate any and all the help you've given so far, as well as everyone else who's offered ideas.

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Running Java not through a web browser?

Thu Sep 17, 2015 8:20 am

HTML5 most propably means JavaScript , not Java at all. Try the Minimal Kiosk Browser
(kweb) for running the code. Make sure that you read the manual that comes with kweb.

Why isn't your friend here ? He propably knows what you need.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Return to “Java”