Skip to main content

Posts

JNI Simple Tutorial

After a long break I am posting a simple tutorial on JNI which is one of my favourites. JNI is Java Native Interface, which we can use to call the native methods written in languages other than Java. We are going to call a method written in C++. JNI is very useful where you cannot use Java such as getting system hardware information and much more, it depends up on what you need. For this tutorial you need to read my old post on creating a simple dll in VC++, though if you know how to create DLL's using VC++ then you can skip that post. Lets get started with our tutorial.. First step is to write a class which will use JNI. Well its too simple, following is the code for our Java class which will be using JNI import java.io.*; class JNITest { // native method public native static void WinMessage(String str); static { System.loadLibrary("SimpleDll"); } public static void main(String args[]) { WinMessage("Hello From JNI"); } } After writing this J...

Lightning

This summer temperature is setting new records... I think its because of "Global Warming", because last few summers temperature is increasing more n more. But yesterday there was raining in Pune. Following are some snapshots of lighting that I captured from my terrace

Using JTable

JTable is the component which helps us to display the multi columned data. This post is about fetching database data and displaying it using JTable. First we will design our Frame public class MyFrame extends JFrame {  private JTable table;  private JScrollPane jsp;  public MyFrame()  {   super("MyFrame");   setSize(400,400);   setDefaultCloseOperation(EXIT_ON_CLOSE);   setLocationRelativeTo(null);   initMyFrame();   setVisible(true);  }  private void initMyFrame()  {   setLayout(new BorderLayout());   table=new JTable();   jsp=new JScrollPane(table);   add(jsp,BorderLayout.CENTER);   // database connection and remaining code will go here  }  public static void main(String args[])  {   new MyFrame();  } }

Creating Simple Dll

This post is a tutorial for creating a simple dll in C++. So lets get started,  Create new project " SimpleDll " in Visual C++. If you are using Visual C++ 6.0 then select Dynamic Link Library Project and if you are using 2005 then select Win32 Project and select Dll and Empty Project in Additional options. After this add new header file " simpledll.h " to our project and add following code in header file . // SimpleDll.h #ifndef _SIMPLEDLL_H_ #define _SIMPLEDLL_H_ #include // this is the function which we will export VOID ShowMessage(WCHAR msg); #endif

Creating Executable Jar File

Creating a Executable Jar file is a very easy task until you don't know how to do it!! If you are using Eclipse for Java Application development then its more easier than using command line, Following are the steps for creating Jar file - using Eclipse 1. Right click on your project and select Export from popup menu

Building small utilities

Another day in office, got extra task to do other than office work!! Task is to build a small utility which will replace all occurrences of a pattern in all project files with another pattern. Use of regular expression made id it easy to complete the task and the utility is built. :)