Use GAWK as native function in Java (JNI) - java

I'm trying to build the GAWK library (c language) as a dll file so I could access it directly from my Java code, without needing to execute an external process (as a "native" function).
As it's easy to do the "helloWorld" JNI, it's quite complicated to do it with GAWK source code, especially for one who isn't familiar with C language.
I need help with 2 things:
How to properly build the complication environment
How to recognize
the place in the code where I should write my "doAwk" function (I
got lost in their code)
Or, if you're familiar with a place where I can find an already working version of it - that would be the best :)
Thanks!

Related

Google VR Java and C++?

I just saw the open source project on this in github (googlevr) and my question is how is it possible for C++ work with Java? I can understand that Java is for android stuff and C++ is for graphic, memory and tracking but how does two different compiled language work together?
In C and C++ you can create shared libraries. They are handled a bit differently for each platform, but do roughly the same thing.
Windows creates a .dll
Mac creates a .dylib
Linux creates a .so
These represent executable code that can be called by any process. This means that java code, matlab code, python code, etc can call code written in C/C++. Java uses a feature called JNI (Java Native Interface) to do this. JNI is notoriously tricky to setup and manage, so a lot of people use a library like Swig which essentially manages everything you need related to JNI in order to make calling precompiled C++ code from Java easier.
The key here is "precompiled". Someone, at some point, maybe even you, had to take the source code and compile it into a dll, dylib, or so and you have to have that shared library set up where the code that needs to use it (in this case your java app) can see it so that when the java app starts it can load the shared library and make calls into it.
For java one consideration is that java code is inherently cross-platform. C++ code needs to be compiled against each platform. So when you distribute your java app, you need to make sure you have a shared library available that is accessible for whichever platform it is being run on.

Combine C-Code(32-bit) with Java

I have method/function to get the drive info using Visual C++ of Microsoft Visual Studio. The method only return the type of drive. But it is become difficult when I'm trying to get more information about the drive. This difficulty gets resolved by Java's existing package. Furthermore, few codes are also there which is easy to handle with C platform. So, I'm thinking, if there is any efficient process which can include a native C code with in Java so that the functionality of both the language can be used in meaningful way.
Can anyone help me in this regard?
Java Native Access (JNA) is a way you can access C libraries from Java code. Its advantage over Java Native Interface (JNI) is that the library glue code is written in Java, not C, making it more maintainable.
(I've used JNA a lot at work. If I get permission from work, I may be able to post the JNA stuff I've written, as examples for you to work with.)

Package them all! Perl, python, java for naive users (in windows)

I have several scripts written in perl, python, and java (wrapped under java GUI with system calls to perl & python). And I have many not-tech-savy users that need to use this in their windows machines (xp & 7).
To avoid users from installing perl,python,and java and to avoid potential incompatibility between various versions of these interpreters, I'd like to make a local copy of these interpreters in a folder and then calling them. I'd zip the whole folder (which would also contain my code) and send it away.
I'd have to worry about environment variables and make calls to the correct interpreter (especially when other versions of python,java,perl may exists in their current system), but not sure what other problems I may face. Any better ideas?
I never used jython and do not know the overhead of moving to it. I also suspect a complex python system, with many files and 3rd party modules will have problems. Same with perl scripts and I don't know a robust perl interpreter callable from java.
Thank you, in advance.
Try Portable Python and Portable Perl. You can unzip them into your application tree and they should work.
Why don't you try migrating your perl/python code into java and then packagin everything into a nice webstart application? What do perl/python offer that java doesn't support?
For perl you can use something like perl2exe and for python py2exe so you can have 2 exes (which would include all the necessary interpreter bits) and invoke them as resources from within java? Or unzip them inside user's home directory and call them again as normal external programs (ProcessBuilder ?) ?

Convert Java jar file in to cpp

I have a java code and created a jar file.
I need to create an Qt application. Can I use this code in that application?
Please help me how can i use that jar file.
Thanks,
Nagaraju.
You could take a look at the capabilities of GCC/GCJ (see http://gcc.gnu.org/ ). IF it's a good idea is a whole other story, and depends on what you have, and what you're trying to accomplish. It should be doable to link SO's created with GCJ in QT applications, but I seriously wonder if you are not better off using either C++ or Java, but not mixing them
If your Java code takes input from stdin or some file and writes output to stdout or some file, then the easiest way is to fork java to run that jar, and parse the output in your Qt code.
Things other than that, you'll need to be a bit specific. Something like "my Java code does painting the screen".
My advice is to use SWT or Swing.
You can use gcj gcj to compile the java code to library and simply call the functions of the java code from your C code.
Yes, you can use your jar file in your Qt application. I've done exactly this myself.
One way is to use the JNI Invocation API. This is part of the Java Native Interface (JNI), which makes it feasible but not pleasant to access Java APIs from C++.
A much more pleasant approach is to use CodeMesh JunC++ion, which wraps the Java APIs in C++ classes. This is a great product, if you can afford it.
If you have very little Java code, it may be easier to port it to C++.

How to call a function written in assembly language code from java?

hi i would like to incorporate assembly language code with java.. guys give me some idea and example programs like hello world because assembly language is new to me..
The "right" solution is JNI or JNA.
But then it depends on your code. If for example you wish to call command line utility compiled to native code (and it does not matter which language was used for coding of this utility) call it by invocation of command line (use either Runtime.exec() or ProcessBuilder. If it is a library use JNI/JNA. If this is not just a library but for instance MS COM component (ActiveX) use one of available java interoperability projects like Jawin, Jintegra, Jinterop etc.

Categories