Tuesday, June 26, 2007

Java Native Method Calling - Tute 1


Using java native method

I will do this with simple program Hello.java

1. javac Hello.java
2. javah –jni Hello
It will create a “Hello.h” header file for the native method we are using.
Do not edit that
3. write the your native file “Hello.c”
including “Hello.h” and jni.h and other header files as needed
4. next step compile the Hello.c
take visual studio command prompt
cl -I ”C:\Program Files\Java\jdk1.5.0_11\include”
-I ”C:\Program Files\Java\jdk1.5.0_11\include\win32”
-LD Hello.c -Felibnative.dll

This will create libnative.lib, libnative.exp, Hello.obj, libantive.dll
* you should give the path to libnative.dll in the “Hello.java”

5. to run the java file
java Hello ------- will give "Hello world!" as output

Codes

1.Hello.java

class Hello{
public native void sayHello();
static{
System.load("C:\\java\\test\\Hello\\New Folder\\libnative.dll");
}
public static void main(String[] args){
Hello h = new Hello();
h.sayHello();
}
}

2. Hello.h – this is created header file in the second step

/* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class Hello */

#ifndef _Included_Hello
#define _Included_Hello
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Hello
* Method: sayHello
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_Hello_sayHello
(JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

3. Hello.c

#include
#include "Hello.h"
#include

JNIEXPORT void JNICALL Java_Hello_sayHello
(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}
Java Native Method Calling - Tute 1





Using java native method

I will do this with simple program Hello.java

javac Hello.java
javah –jni Hello
It will create a “Hello.h” header file for the native method we are using.
Do not edit that
write the your native file “Hello.c”
including “Hello.h” and jni.h and other header files as needed
next step compile the Hello.c
take visual studio command prompt
cl -I ”C:\Program Files\Java\jdk1.5.0_11\include”
-I ”C:\Program Files\Java\jdk1.5.0_11\include\win32”
-LD Hello.c -Felibnative.dll

This will create libnative.lib, libnative.exp, Hello.obj, libantive.dll
* you should give the path to libnative.dll in the “Hello.java”


Codes

1.Hello.java

class Hello{
public native void sayHello();
static{
System.load("C:\\java\\test\\Hello\\New Folder\\libnative.dll");
}
public static void main(String[] args){
Hello h = new Hello();
h.sayHello();
}
}

2. Hello.h – this is created header file in the second step
/* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class Hello */

#ifndef _Included_Hello
#define _Included_Hello
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Hello
* Method: sayHello
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_Hello_sayHello
(JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif
3. Hello.c

#include
#include "Hello.h"
#include

JNIEXPORT void JNICALL Java_Hello_sayHello
(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}

Monday, June 25, 2007

Sorting a Portion of a Collection

int[] arNumbers = {13, 4, 7, 10, 2, 8, 17, 5, 1, 11};
System.Array.Sort(arNumbers, 2, 5); // sort numbers between 2 to 5

Automatic Sorting Using a SortedList

Dim usStates As New SortedList
usStates.Add("CA", "California")
usStates.Add("AZ", "Arizona")
usStates.Add("NV", "Nevada")
Console.WriteLine(usStates.GetKey(1) + usStates.GetByIndex(1))Console.ReadLine()
' slsStates order:'
' Keys Values
' ---------------
' AZ Arizona
' CA California
' NV Nevada

Sunday, June 24, 2007

Sorting Arrays

Sorting a Pair of Key-Value Arrays:

Dim aryStateKeys() As String = {"CA", "AZ", "NV", "AK", "WA", "OR", _
"HI", "UT", "ID"}
Dim aryStateValues() As String = {"California", "Arizona", _
"Nevada", "Alaska", "Washington", "Oregon", "Hawaii", "Utah", _
"Idaho"}

Array.Sort(aryStateKeys, aryStateValues)

' New order of the arrays:
'
' aryStateKeys aryStateValues
' -----------------------------
' AK Alaska
' AZ Arizona
' CA California
' HI Hawaii
' ID Idaho
' NV Nevada
' OR Oregon
' UT Utah
' WA Washington

Tuesday, June 05, 2007

Wireless Sensor Networks

Unlike in wired network, in wireless you don’t have wire connecting each and every node (device) in the network. In here devices are connected to the network using mostly radio waves.
Development of wireless sensors were booted by the military researches because of the high military value they possessed. But today these sensor network technologies have penetrated each and every corner of the world. Modern housing equipments, environmental monitoring, healthcare sector are the core areas benefiting through this.

So let’s see the parts of a sensor node
Normally each node has a radio transceiver or other wireless communication device, microcontroller, an energy source. Size of a sensor node can vary from depending on the service provided by the sensor and the technology which has been used to develop it. Today we have sensor nodes of a size of small dust and which are intelligent enough to identify an object or a specific chemical.

Key areas today using wireless technology

Environmental monitoring
Habitat monitoring
Acoustic detection
Seismic Detection
Military surveillance
Inventory tracking
Medical monitoring
Smart spaces
Process Monitoring
Structural health monitoring
In WSN what is the scarcest resource?The answer will be power or the energy. As these sensor nodes are laid in different places where supply of the power is very limited and still today we don’t have a technology to transfer energy through air power is a key issue. The most energy consuming operation is transmission. As each node has to transmit its data to its base station living long and communicating is really a challenge.
Best solutions to these issues are still on research level and in my point of view what we can save energy by reducing the weight of the transmission data and reducing the data transmission distance because of the polynomial growth of the power with the distance.

Friday, June 01, 2007

New 'Google Gears' Allows Offline Web Apps

SAN FRANCISCO (Reuters) - Google Inc. said on Wednesday it had created Web software that runs both online, and offline, marking a sea change for the Internet industry by letting users work on planes, trains, spotty connections and even in the most remote locations.

The technology, called Google Gears, would allow users of computers, phones and other devices to manipulate Web services like e-mail, online calendars or news readers whether online, intermittently connected to the Web or completely offline.

Read this story