Java Native Interface (JNI) is one of the intersting interface by java
By using Java Native Interface (JNI) you can operate with other applications and libraries.
JNI is the native programming interface for java that is part of JDK.
Using JNI you can operate with other applications and libraries written in other language
such as C,C++.
But the basic question arises when should I use the JNI ?
You want some platform specific information and the standard Java class
library may not support the platform-dependent features needed by your
application.
You have some library application written in other language and
you want to use it in your java application.
You want Java should interact with some low level programming language.
Below is given Simple Example
See that methods have 'native' KeyWord
public native void displayHelloWorld();
public native void displayOther();
private native String getLine(String prompt);
The DLL we are going to use is firstJNI.DLL
This DLL can be generated by VC++ or borland.
Which we will discuss later.
Compile the above code using
prompt>javac firstJNI.java
Then create header File using
prompt>javah javah -jni HelloWorld
This will create firstJNI.h file
In the header File you will see
To generate DLL
create bcc32.cfg file in %BORLAND_INSTALL%/BCC5/bin Folder
In the bcc32.cfg file add following code
-I"%BORLAND_INSTALL%\BCC55\include;%JAVA_HOME%\include;%JAVA_HOME%\include\win32"
-L"%BORLAND_INSTALL%\BCC55\lib;%BORLAND_INSTALL%\BCC55\Lib\PSDK;"
i.e the path for borland compiler and java.
now goto prompt and say
prompt>bcc32 -tWM -tWD firstJNI.c
This will create firstJNI.lib File
Now say
prompt>implib -c firstJNI.lib firstJNI.dll
That's it!!
It will generate DLL file.
Now you can run the firstJNI.class file by using java.
--------------------
Now let see how to generate DLL using VC++
Click File->New->Win32Dynamic-Link Library
Give name and Select A simple DLL project
You will have
firstJNI.CPP file
Below is given the firstJNI.cpp file
The syntax declaration is same as discussed above. In VC++ it
may throw error for unable to include for jni.h or
firstJNI.h where you have to give path for these header files while including.
The above code will also check for RAM size and print it.
Borland compiler do not provide bios.h so it is not included in the code.
Build all Application and you will get the DLL file.
Go to prompt and run firstJNI.class using java.
So here we can print RAM size!!!
Now since this is the basic we can go further with this.
If you don't set the library path correctly it will throw exception java.lang.UnsatisfiedLinkError: no hello in shared library path
at java.lang.Runtime.loadLibrary(Runtime.java)
at java.lang.System.loadLibrary(System.java)
at
at java.lang.Thread.init(Thread.java)
Java MP3 Player by David Barron
A fully functioning MP3 Player with complete source code available for download
A simple way to JTable by Kanad Deshpande
Many face trouble while dealing with JTable. Here is simplest way to handle JTable.
ID Verification using JSP by Nouman Rashid
One of the most important parts of
web development is to make sure that
only authorized users get access to certain areas of the site. This tutorial
takes a look at various steps involved
in making JSP pages which validate a
user ID and password from a MS Access database which contains the username and
password.
Java Native Interface (JNI) by Kanad Deshpande
Java Native Interface (JNI) is one of the intersting interface by java
By using Java Native Interface (JNI) you can operate with other applications and libraries.
Understanding Hibernate ORM for Java/J2EE by Saritha.S.V
Hibernate is the most popular and most complete open source object/relational mapping solution for Java environments.Hibernate's goal is to relieve the developer from 95 percent of common data persistence related programming tasks.
Login codes with JSP,JavaBean from mySQL database by Prakash
my problem is can i have the code to login with the username and password using JSP and JavaBean/Servlets from mySQL database.When the user enters the username and password in the login page then it will go to the requested site.How to do it?
Java Speech Synthesizer by David Barron
Small and simple. Type a sentence and press enter and your computer will speek to you.
simple Java Development Environment by David Barron
Program in JAVA with ease, using this development environment, or adapt it to your own needs.
Turn EJB components into Web services by Krunal J Patel
Web services have become the de facto standard for communication among applications. J2EE 1.4 allows stateless Enterprise JavaBeans (EJB) components to be exposed as Web services via a JAX-RPC (Java API for XML Remote Procedure Call) endpoint, allowing EJB applications to be exposed as Web services. This article presents a brief introduction to JAX-RPC, outlines the steps for exposing a stateless session bean as a Web service, and provides the best practices for exposing EJB components as Web services
CORBA Technology by Krunal Patel
CORBA defines an architecture for distributed objects. The basic CORBA paradigm is that of a request for services of a distributed object. Everything else defined by the OMG is in terms of this basic paradigm.