| Author |
Java API for hardware interaction
|
mozammil muzza
Greenhorn
Joined: Dec 22, 2011
Posts: 29
|
|
Hi All,
Do we have any java API to interact with hardware like c, c++ ?
|
Khuda Haafiz Muzza 4 Java
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
JNI (or JNA, the Java wrapper for it) has already been available for quite a long time. With JNI you write native methods in Java, use javah to create headers for it, then implement the functions inside it with C or C++.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
mozammil muzza
Greenhorn
Joined: Dec 22, 2011
Posts: 29
|
|
Rite Rob,
But using JNI again we have to write the native code in some native language (like c, c++), but i am asking for some core Java API for such (hardware) things.
Muzza
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
It all depends on the hardware involved. For some things there may already be an API (like hard disks), for other there may not be.
|
 |
Alexander Kober
Ranch Hand
Joined: Aug 05, 2011
Posts: 32
|
|
mozammil muzza wrote:Hi All,
Do we have any java API to interact with hardware like c, c++ ?
There's three things that come to mind:
1) Most hardware devices will come with a DLL/so/dylib. You can use the beforementioned JNA project to access them. Unless you absolutely require the last bit of performance (which would require you to use JNI), JNA is perfectly suitable for most applications and, as you requested, pure java.
2) Check out rxtx for working with serial/parallel ports. A lot of devices will emulate a serial port and can be accessed with this tool, too.
3) For directly accessing USB devices, take a look at libusbjava.
Other specialized hardware may actually require some C level code though.
|
 |
 |
|
|
subject: Java API for hardware interaction
|
|
|