We've just published Sanjay Dasgupta's new article Simplify Native Code Access with JNA. In this article, Sanjay describes the path through which Java developers can apply Java Native Access to directly interact with native operating system APIs, presenting several working examples that access Microsoft Windows native APIs, and also delving into the complexities of memory mapping and alignment issues.
Sanjay has packaged up his examples into a single zip file that you can download and unpack into a directory. His package includes the jna.jar file, a build.bat file that you execute from within a Windows command window, and individual *.bat files that you run from within a Windows command window to launch the individual applications.
The applications include a "Hello World" app that signals "Hello World" in Morse code using the Windows kernel's Beep() function; a Java implementation of the Windows LockWorkStation() function; a program that brings into Java the Windows list of available logical drives; and an app that applies TWAIN to connect to a scanning or image device.
I may have greater interest in "low-level" issues than many developers. After all, I started out counting bits and bytes passed over RS-232 serial wires and GPIB cables in the late 1970s and early 1980s. I also spent plenty of time and effort working on the type of memory issues that come into play when you try to integrate someone's legacy library written in a language other than the one that your controlling system is written in, where you have to control and manage their software from a different language.
So, the latter portion of Sanjay's article, where he describes and analyzes memory alignment issues that can arise when you attempt to link Java to native Windows API functions via JNA -- I guess I find that discussion both interesting and comforting. Because in that section, Sanjay makes clear the type of not-obvious problems you may have to deal with when you interface what are basically "alien" languages (Java and a native operating system API). Operating systems and their APIs assume things regarding bits and bytes. And different systems and languages, choosing among the possible options, implement things differently.
Memory is fundamental to operating systems and languages. If you have a memory block that is subdivided into various elements, what are the rules for those subdivisions? Should each element start at a "word" boundary? But, then, what's a "word"? The definition can differ for different OSs. Do you pad with unused bytes if one element ends at a memory location that is not a natural boundary? Or do you start the next element in the middle of that memory "word"? But wouldn't it be weird to do that? Well, to some language and OS designers, that seemed weird, to others it didn't (why waste memory?).
The fact that someone had to make these decisions for each OS and language, and the fact that a toss of the coin was sometimes as good a means of making a choice as anything else (since what's "best" really isn't clear), means that communications between "aliens" (like Java and a native OS API) can be fraught with misinterpretation due to differing assumptions about memory boundaries, memory application, and memory alignment.
I really like Sanjay's treatment of these issues! It's one of the clearest presentations I've seen.
If you need to interface Java with APIs from a native OS, for example, Windows -- or if you're just curious about how you'd go about accomplishing this -- take a look at Sanjay Dasgupta's Simplify Native Code Access with JNA. It's an excellent presentation of the relevant issues!
TransactionSynchronizationRegistry is the way to go - you don't have to worry about the existence of multiple thread pools. However it only works inside a transaction. If you need to pass the context from the web layer (before a transaction is initiated), to the EJB container, where the transaction actually starts, you cannot use TransactionSynchronizationRegistry...
One of the things we're the most proud of in the OpenDS project is the simplicity of installation and initial configuration, thanks to the Java Web Start QuickSetup installer. We say that you can download, install and configure OpenDS to run on your machine in less than 3 minutes and 6 clicks...
Java EE 6 improves on developer productivity features, breaks the "one size fits all"
approach with Profiles, adds extensibility, and more. This webinar will
get you developing with Java EE 6 today and will cover:
Attended and presented at my first NLJUG's JFall conference earlier today. NLJUG is the Java User Group of Netherlands. It's a non-profit organization that try to get out the maximum out of content sharing with all of its members. An annual subscription to the JUG is 35.50 Euros and allows the members to attend its two annual conferences - JSpring and JFall and also provide a year long subscription to a local Java magazine...
forceTen has gotten the first public release and it's now possible to download it both as a binary application and as a project to compile from sources (in addition to the cloning of the source repository). Also, I've set up the mailing lists, a user's forum and the issue tracker. I don't like the graphics of the new web site (it seems I'm suffering from a lack of fantasy for the clip art), but they are a reasonable starter...
In the Forums, ojerrag has a problem with JXta Connecting to a Rendevous Peer with a fix ip from a peer behind Firewl: "I am building a jxts P2p system and since i am new in Jxta , i am having some problems. I Hava Rendezvou_relay Peer which is running with a fixed Ip address. Trying to connect to the Rendevous Peer using Tcp functions with no problem if the Peer..."
btasdemir has a Combobox problem in lwuit blackberry impl....: "Hi, I use thorsten's lwuit bb impl. I create a combobox with default vector constructor. On the form, when I want to change selected item , I got null pointer exception. So I try to use same combobox with String [] items constructor, I got..."
mikezang asks How to let TextArea scrollUp auto?: "I appended a append() to TextArea which can append one line to TextArea. I hope the TextArea will scroll up automatically when contents beyond TextArea height, what can I do? do you have any idea?"
Our current Spotlight is Geertjan Wielenga's post Financial Applications on the NetBeans Platform: "Experian and Société Générale both have invested in the NetBeans Platform, by using it as the basis of one or more of their applications. And these two are not exactly small organizations. Experian is a global leader in consumer and business credit reporting and marketing services and a constituent of the United Kingdom's FTSE 100 index, with revenues in excess of US$4 billion, while Société Générale is France's second-largest bank by market value. How do I know that these organizations are using the NetBeans Platform? By looking in the dev@openide.netbeans.org mailing list..."
Registered users can submit event listings for the java.net Events Page using our events submission form. All submissions go through an editorial review before being posted to the site.
Archives and Subscriptions: This blog is delivered weekdays as the Java Today RSS feed. Also, once this page is no longer featured as the front page of java.net it will be archived along with other past issues in the java.net Archive.