Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java API for hardware interaction

 
mozammil muzza
Ranch Hand
Posts: 32
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Do we have any java API to interact with hardware like c, c++ ?
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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++.
 
mozammil muzza
Ranch Hand
Posts: 32
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic