views:

233

answers:

8

Just a basic question about Java (haven't really done anything with it personally yet):

Is it possible to write a Java program that runs in a web browser (via JRE) on the client machine? Is something like Groovy or JavaFX really a wrapper for something that technically could be written in Java? I assumed that JavaFX at least was intended for the browser. However when I ran a sample JavaFX app from Netbeans, its a stand-alone app - not something running in the browser. In general, in the long run, or web browsers going by the wayside.

+5  A: 

That's probably Applet you're looking for. Though its usually ugly and too restricted.

Vladimir Dyuzhev
You implying that in comparison to something like flash, Java (or javafx) in the browser is not very popular? What is the primary use for Java these days?
Mark
When Java first came out it was intended for use in the browser, and a fight between Microsoft and Netscape botched that up so good that Java applets *still* have a reputation for running poorly in the browser. Flash is more popular these days, though its main use is for garishly ugly advertising.
Carl Smotricz
These days, most Java coding runs on servers, i.e. Java creates (some) content that you see on the Web and does a lot of business-related code in back-end servers. However, there are also some Java applications that run directly on user's PCs as GUI applications; they look OK and run well. You don't *have* to run Java in a browser.
Carl Smotricz
Flash has generally replaced applets due to faster start-up and better/easier graphical features, but there are a couple of situations in which applets might be a better choice. One is if you want to do some reasonably heavyweight processing, the other is if you want to open a secure socket connection.
Dan Dyer
A: 

It is called an applet.

dacracot
Hey, too all I appreciate it. I'm glad it was such a softball question for everybody.I'm assuming then the Java Plug In is distinct from the Java Runtime Environment (JRE) with the former actually runs in the browser).So then Java, JavaFX, and Groovy all run in either the Java Plug In or the JRE, correct? And JavaFX and Groovy and Java are compiled to byte code, and JavaFX and Groovy have a comparable relationship to Java as as say, MXML (Flex) has to AS3?
Mark
If anybody could confirm the above it would help me to nail this down conceptually.
Mark
The JRE and a browser option to allow Java is necessary on the client machine.
dacracot
Sorry if this is confusing. To run a Java applet in a browser, you need the plugin, but the plugin is more or less just plumbing to fit together the applet, the browser and the JRE, which is still required for applets too. Those languages all run in the JRE, with or without support from the plugin. Groovy is compiled to bytecode, for JavaFX I'm not sure. AS3? Not my world, sorry. Hope you can piece the story together from that.
Carl Smotricz
An applet is written in Java and compiled to byte code. There is no plug-in for the applet in the browser. The browser is either Java enabled or disabled via its preferences. Some browsers have an embedded JRE, but most use the JRE installed in the operating system.
dacracot
Yes that does help. AS3 is Actionscript 3. It is part of the flash world. Really, it seems indistiguishable from Java, in that it is extremely similar to C++, garbage collected, pretty efficient, etc. It seems clear at this point that as far as web devlopment no one would claim that Java is superior in anyway.
Mark
(responding to Carl Smotricz)
Mark
+1  A: 

Have you never heard of java applets? Really?

gnud
No need to be rude.
dacracot
Well according to Valdimir below, applets or ugly and restricted, so it looks like I wasn't missing anything. Just trying to get a handle on what Java is most used for.
Mark
But I'm not clear on why Java would be restricted in the browser. Is the Java Plug in slow or lacking in capabilites in comparison to Flash Player for example?
Mark
apologies for typos.
Mark
@Mark: Java is restricted in the browser because it's a security risk to run somebody else's code on your own PC. Normally, applets are loaded from remote Web sites, so they're untrustworthy unless proven otherwise (by signature). They're not often used locally so most people never hit the situation we're talking about.
Carl Smotricz
Java applets are not ALWAYS restricted on the browser, you can give them permissions. The big problem that I remember (it's been years) is that the applet behaves differently based on which browser launches it. We ran into more browser incompatibilities than platform incompatibilities.
Bill K
I didn't mean to come off as rude, more as astonished. Java applets have been around since 1995 - just as long as scripting in the browser.
gnud
A: 

While I did more in the past, I've only done a little Java recently, and never JavaFX or Groovy. However, I can echo others and say that you can run a Java program called an applet through a browser.

What I haven't seen said is that if you download the Java Development Kit (JDK) you can run an applet directly on your desktop with the appletviewer program that comes with the JDK. Generally this is only done during development and testing in my experience.

It is not, however, required to write Java programs as applets. Instead, you can write a Java application and run it locally on your system.

In general, in the long run, or web browsers going by the wayside.

Do you mean "are browsers going by the wayside"? No way. Now, if you mean for Java work, it seems other technologies have largely replaced Java applets as means to running programs through the browser.

GreenMatt
+3  A: 

FWIW, You can run the same JavaFX program in a web-browser if you change the "Execution Mode" in the project properties under "Run". It does essentially run as an applet.

Eric Wendelin
A: 

JavaFX is kind of competing against Adobe AIR. Its used to create applications that use Web Services. The best way to describe JavaFX is like a custom browser for a website. They have a lot of Twitter examples since they have a pretty easy to use API.

If you want to run a Java App in a regular browser like FireFox you can use a Java Applet.

You can also develop Web App with Java too! Google App Engine just added support for Java!

Hope that helps.

Bernie Perez
See, my thinking would be that Adobe AIR would be flash's attempt to more closely compete with Java by expanding the use of Actionscript from just the browser to Desktop app development.And it seems pretty clear that JavaFX was Java's attempt to more closely compete with flash as far as web apps, possibly with a smaller footprint than Java, and less loading time etc. JavaFX was intended by Sun to replace Groovy, I think.
Mark
But if the JRE takes a couple of minutes to install, and if that's necessary to run an applet, no wonder applets never took off. The Flash Player takes 2 seconds to install off the web.
Mark
A: 

As other people have answered, applets is the way to execute java in the browser. Applets were one of the main reasons Java got so much attention back in the late 90's. All of a sudden it was possible to write cool application on the web. That was really exciting back then!

svenningsson
A: 

The Applet is dead. Long live Java Web Start.

More on this subject:

BalusC