File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Features new in Java 7 and the fly likes Java API for hardware interaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "Java API for hardware interaction " Watch "Java API for hardware interaction " New topic
Author

Java API for hardware interaction

mozammil muzza
Ranch Hand

Joined: Dec 22, 2011
Posts: 32

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: 19670
    
  18

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
mozammil muzza
Ranch Hand

Joined: Dec 22, 2011
Posts: 32

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: 19670
    
  18

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java API for hardware interaction