views:

50

answers:

3

I've been tasked with creating software that needs to work on Macs and PCs.

The software needs to talk to some USB hardware that does bits and bobs.

To prevent having to maintain two pieces of software, I thought about the possibility of writing a Java applet, I'm pretty new to Java but am OK at C# and C, and did do a bit of Java at university so I should be ok with it, but my question is, can a Java applet communicate with an API for some USB hardware, or is this not possible due to security reasons?

A: 

I think security is going to cut you off. Does your software HAVE to be browser based? A lot of people associate "Applet" with Java naturally, but you CAN just make a full-blown application in Java as well. That would have access to the local hardware.

Curtis
+5  A: 

Yes you can by using native library via JNI. This is platform-dependent so you would have to write code that abstracts this away. Also applet would need to be signed.

http://www.javaworld.com/javaworld/jw-10-1998/jw-10-apptowin32.html

Peter Knego
+1  A: 

I would also look at using webstart rather than an applet. It's a lot more flexible and just works better. This explains the security features and signed jar files:

http://download.oracle.com/javase/tutorial/deployment/webstart/security.html

I should add this only applies if you're starting the application from a remote web site. If you just want to run a java program locally, then you don't have to worry about all this.

JOTN
JWS (or a JWS configured applet in a Plug-In 2 JRE) will simplify this task in that JWS can install the natives.
Andrew Thompson