Friday, April 30, 2010

Most Simple JNI Program using Borland

||Jai Shree Mataji ||

Something About JNI


JNI allows one to write native methods to handle situations when an application cannot be written entirely in the Java programming language, e.g. when the standard Java class library does not support the platform-specific features or program library.

It can be used to interface with code written in other languages, such as C and C++. It is also used for time-critical calculations or operations like solving complicated mathematical equations, since native code can be faster than JVM code.

How the JNI works


In the JNI framework, native functions are implemented in separate .c or .cpp files. (C++ provides a slightly cleaner interface with JNI.) When the JVM invokes the function, it passes a JNIEnv pointer, a jobject pointer, and any Java arguments declared by the Java method. A JNI function may look like this:
JNIEXPORT void JNICALL Java_ClassName_MethodName
  (JNIEnv *env, jobject obj)
{
    /*Implement Native Method Here*/
}

The env pointer is a structure that contains the interface to the JVM. It includes all of the functions necessary to interact with the JVM and to work with Java objects. Example JNI functions are converting native arrays to/from Java arrays, converting native strings to/from Java strings, instantiating objects, throwing exceptions, etc. Basically, anything that Java code can do can be done using JNIEnv, albeit with considerably less ease.
For example, the following converts a Java string to a native string:
 //C++ code
JNIEXPORT void JNICALL Java_ClassName_MethodName
  (JNIEnv *env, jobject obj, jstring javaString)
{
    //Get the native string from javaString
    const char *nativeString = env->GetStringUTFChars(javaString, 0);

    //Do something with the nativeString
    //DON'T FORGET THIS LINE!!!
    env->ReleaseStringUTFChars(javaString, nativeString);
}
 /*C code*/
JNIEXPORT void JNICALL Java_ClassName_MethodName
  (JNIEnv *env, jobject obj, jstring javaString)
{
    /*Get the native string from javaString*/
    const char *nativeString = (*env)->GetStringUTFChars(env, javaString, 0);

    /*Do something with the nativeString*/
    /*DON'T FORGET THIS LINE!!!*/
    (*env)->ReleaseStringUTFChars(env, javaString, nativeString);
}
 /*Objective-C code*/
JNIEXPORT void JNICALL Java_ClassName_MethodName(JNIEnv *env, jobject obj, jstring javaString)
{
    /*DON'T FORGET THIS LINE!!!*/
    JNF_COCOA_ENTER(env);

    /*Get the native string from javaString*/
    NSString* nativeString = JNFJavaToNSString(env, javaString);

    /*Do something with the nativeString*/

    /*DON'T FORGET THIS LINE!!!*/
    JNF_COCOA_EXIT(env);

}

Note that C++ JNI code is syntactically slightly cleaner than C JNI code because like Java, C++ uses object method invocation semantics. That means that in C, the env parameter is dereferenced using (*env)-> and env has to be explicitly passed to JNIEnv methods. In C++, the env parameter is dereferenced using env-> and the env parameter is implicitly passed as part of the object method invocation semantics.

Native data types can be mapped to/from Java data types. For compound types such as objects, arrays and strings the native code must explicitly convert the data by calling methods in the JNIEnv.

Mapping types


The following table shows the mapping of types between Java and native code.

In addition, the signature "L fully-qualified-class ;" would mean the class uniquely specified by that name; e.g., the signature "Ljava/lang/String;" refers to the class java.lang.String. Also, prefixing [ to the signature makes the array of that type; for example, [I means the int array type.

Here, these types are interchangeable. You can use jint where you normally use an int, and vice-versa, without any typecasting required.

However, mapping between Java Strings and arrays to native strings and arrays is different. If you use a jstring in where a char * would be, your code could crash the JVM.
 // !!! Incorrect !!! //

JNIEXPORT void JNICALL Java_ClassName_MethodName
  (JNIEnv *env, jobject obj, jstring javaString)
{
    printf("%s", javaString);
}
 // Correct //
JNIEXPORT void JNICALL Java_ClassName_MethodName
  (JNIEnv *env, jobject obj, jstring javaString)
{
    //Get the native string from javaString
    const char *nativeString = env->GetStringUTFChars(javaString, 0);
    printf("%s", nativeString);
    //DON'T FORGET THIS LINE!!!
    env->ReleaseStringUTFChars(javaString, nativeString);
}

This is similar with Java arrays, as illustrated in the example below that takes the sum of all the elements in an array.
 // !!! Incorrect !!! //
JNIEXPORT jint JNICALL
    Java_IntArray_sumArray(JNIEnv *env, jobject obj, jintArray arr)
{
     int i, sum = 0;
     for (i = 0; i < 10; i++) {
         sum += arr[i];
     }
     return sum;
}
 // Correct //
JNIEXPORT jint JNICALL
    Java_IntArray_sumArray(JNIEnv *env, jobject obj, jintArray arr)
{
     jint buf[10];
     jint i, sum = 0;
     env->GetIntArrayRegion(arr, 0, 10, buf);
     for (i = 0; i < 10; i++) {
         sum += buf[i];
     }
     return sum;
}

Of course, there is much more to it than this. Look for links below for more information.

JNIEnv*


A JNI interface pointer (JNIEnv*) is passed as an argument for each native function mapped to a Java method, allowing for interaction with the JNI environment within the native method. This JNI interface pointer can be stored, but remains valid only in the current thread. Other threads must first call AttachCurrentThread() to attach themselves to the VM and obtain a JNI interface pointer. Once attached, a native thread works like a regular Java thread running within a native method. The native thread remains attached to the VM until it calls DetachCurrentThread() to detach itself.
To attach to the current thread and get a JNI interface pointer:
JNIEnv *env;
(*g_vm)->AttachCurrentThread (g_vm, (void **) &env, NULL);

To detach from the current thread:
(*g_vm)->DetachCurrentThread (g_vm);

--------------------------------------------------------------------------------------------------------------------------------------------------------

About Borland Compilation


This is a tutorial which told you, how to use JNI.

Below are the steps to use JNI Simple Hello world Program.


1. You have to install the Borland C++ Compiler(C++ Compiler 5.5). It can be downloaded from :- Borland C++ Compiler.


2. After Installation put Borland bin path in Environmental Variables:- "F:\Borland\bin".


3. Change your Borland "F:\Borland\Bin\bcc32.cfg" file like Below
-I"F:\Borland\include;C:\Program Files\Java\jdk1.6.0_02\include;C:\Program Files\Java\jdk1.6.0_02\include\win32"
-L"F:\Borland\lib;F:\Borland\Lib\PSDK"

4. Write the Java File
class MyJNI {
public native void displayHelloWorld();
static {
System.loadLibrary("MyJNI"); //This is MyJNI.dll
}
public static void main(String[] args) {
MyJNI obj=new MyJNI();
obj.displayHelloWorld();
}
}

5. Compile the Java File by Command:-
javac MyJNI.java

6. Next task is to create the Header file from Java File. To create that use following command:-
javah -jni MyJNI

This will create MyJNI.h. The Content of MyJNI.h file will be as follow. Do not Edit this file as it is generated by machine.
/* DO NOT EDIT THIS FILE - it is machine generated */
#include 
/* Header for class MyJNI */

#ifndef _Included_MyJNI
#define _Included_MyJNI
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class:     MyJNI
* Method:    displayHelloWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_MyJNI_displayHelloWorld
(JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

7. Now importent work to implement the C code. That is shown below:-
/*MyJNI.c*/
#include 
#include "MyJNI.h"
#include 

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

The JNI function shown in underscore format as above.

8. To Compile this C Code we are using the borland Compiler. The Command will be as below.
F:\Java\JNI\MyEx>bcc32 -tWM -tWD MyJNI.c
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
MyJNI.c:
Warning W8057 MyJNI.c 10: Parameter 'env' is never used in function Java_MyJNI_displayHelloWorld
Warning W8057 MyJNI.c 10: Parameter 'obj' is never used in function Java_MyJNI_displayHelloWorld
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

9. This will create the files :- MyJNI.dll, MyJNI.obj, MyJNI.tds

10. To create Library file for use we have following command:-
implib -c MyJNI.lib MyJNI.dll

This will create the file:- "MyJNI.lib".
11. Now Final step is to run this JNI Program.
F:\Java\JNI\MyEx>java MyJNI
Hello world!

F:\Java\JNI\MyEx>



12. You can also download the source code here.


Now you can use this libary with dll any where you want.

This is most easy way to use JNI rather than going to use VC++ as C Compiler.

Enjoy Have a nice Day.

For more information visit Dwij IT Solutions.

Friday, April 23, 2010

Video Snapshot in NOKIA3110 using J2ME & Media API

This is a Midlet build in J2ME.

It is compatible with NOKIA Phone, specially with the NOKIA3110.

Following are the files under the Sun's Wireless Toolkit JDK.

 src
 |_CaptureVideo.java
 |_ImageCanvas.java
 |_VideoCanvas.java
 |_VideoSnap.java

CaptureVideo.java:-
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
import javax.microedition.io.file.FileConnection;
import javax.microedition.lcdui.*;
import javax.microedition.media.MediaException;
import javax.microedition.media.control.VideoControl;

public class CaptureVideo extends Thread {
 public VideoSnap midlet;
 public VideoControl videoControl;
 public VideoCanvas canvas;
 public CaptureVideo(VideoCanvas canvas, VideoSnap midlet, VideoControl vc) {
  this.canvas = canvas;
  this.midlet = midlet;
  this.videoControl = vc;
 } 
 public void run() {
  try     {
   byte[] raw = videoControl.getSnapshot("encoding=jpeg");
   Image image = Image.createImage(raw, 0, raw.length);
   if(canvas.imageNumber == 5)
    return;
   canvas.images[canvas.imageNumber] = raw; //Adding Image byte Array to Image Array
   Image resizedImage = createThumbnail(image); //Resize image to thumbnail
   canvas.thumbImages[canvas.imageNumber] = resizedImage; // Add thumbnail image to image Array
   canvas.imageNumber++;
   canvas.repaint();
  } catch (Exception e) {
   Alert mediaExceptionAlert = new Alert("Media Exception","Cannot Capture Image: "+e.toString(),null,AlertType.INFO);
   mediaExceptionAlert.setTimeout(3000);
   midlet.display.setCurrent(mediaExceptionAlert);
  }
 }
 private Image createThumbnail(Image image) {
  int sourceWidth = image.getWidth();
  int sourceHeight = image.getHeight();
  int thumbWidth = 35;
  int thumbHeight = -1;
  if (thumbHeight == -1)
   thumbHeight = thumbWidth * sourceHeight / sourceWidth;
  Image thumb = Image.createImage(thumbWidth, thumbHeight);
  Graphics g = thumb.getGraphics();
  for (int y = 0; y < thumbHeight; y++) {
   for (int x = 0; x < thumbWidth; x++) {
    g.setClip(x, y, 1, 1);
    int dx = x * sourceWidth / thumbWidth;
    int dy = y * sourceHeight / thumbHeight;
    g.drawImage(image, x - dx, y - dy, Graphics.LEFT | Graphics.TOP);
   }
  }
  Image immutableThumb = Image.createImage(thumb);
  return immutableThumb;
 }
}


ImageCanvas.java:-
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
import javax.microedition.io.file.FileConnection;
import javax.microedition.lcdui.*;
import javax.microedition.media.MediaException;
import javax.microedition.media.control.VideoControl;

public class ImageCanvas extends Canvas {
 public VideoSnap midlet;
 public VideoCanvas canvas;
 public byte[] img;
 
 public ImageCanvas(VideoSnap midlet, VideoCanvas canvas, byte[] img) {
  this.midlet = midlet;
  this.canvas = canvas;
  this.img = img;
  setFullScreenMode(true);
    }
    public void paint(Graphics g) {
        Image image = Image.createImage(img, 0, img.length);
  g.drawImage(image, 0, 0, 0);
  g.setColor(128,128,128);
  g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
  g.drawString("Save",54,151,0);
  g.drawString("Back",112,151,0);
 }
 protected void keyPressed(int paramInt) {
  if(paramInt == -7) {
   midlet.display.setCurrent(canvas);
  } else if(paramInt == -5) {
   saveImage();
  }
 }
 void saveImage() {
  try {
   FileConnection fc = null;
   for(int i=0; i < 100; i++) {
    fc = (FileConnection) Connector.open("file:///E:/image_"+i+".jpg");
    if(fc.exists())
     continue;
    else
     break;
   }
   fc.create();
   OutputStream out = fc.openOutputStream();
   out.write(img);
   out.flush();
   out.close();
   
   Alert alert = new Alert("Image","Image Saved...",null,AlertType.INFO);
   alert.setTimeout(3000);
   midlet.display.setCurrent(alert);
  } catch(Exception e) {
   Alert alert = new Alert("Exception"," Image not Saved..."+e.toString(),null,AlertType.INFO);
   alert.setTimeout(3000);
   midlet.display.setCurrent(alert);
  }
 }
}

VideoCanvas:-
import javax.microedition.lcdui.*;
import javax.microedition.media.MediaException;
import javax.microedition.media.control.VideoControl;

public class VideoCanvas extends Canvas {
  public VideoSnap midlet;
  public VideoControl videoControl;
  public int imageNumber = 0;
  public byte[][] images = new byte[5][];
  public Image[] thumbImages = new Image[5];
  public int[] imageLocations = {72, 10, 72, 57, 1, 104, 37, 104, 73, 104};
  public VideoCanvas(VideoSnap midlet, VideoControl vc) {
    this.midlet = midlet;
    this.videoControl = vc;
    int width = getWidth();
    int height = getHeight();
    setFullScreenMode(true);
    videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
    try {
      videoControl.setDisplayLocation(1, 10);
      videoControl.setDisplaySize(70, 93);
      videoControl.setDisplayFullScreen(false);
    } catch (MediaException me) {}
    videoControl.setVisible(true);
  }
  void drawImageOnCanvas(Graphics g) {
    for(int i=0; i      if(thumbImages[i] != null)
        g.drawImage(thumbImages[i], imageLocations[2*i], imageLocations[2*i+1], 0);
  }
  public void paint(Graphics g) {
    int width = getWidth();
    int height = getHeight();
    g.setColor(128,128,128);
    g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
    g.drawString("Shri Ganesha",33,1,0);
    g.setColor(0, 0, 0);
    g.drawString("Capture",50,151,0);
    g.drawString("Exit",112,151,0);
    if(thumbImages.length > 0)
      drawImageOnCanvas(g);
  }
  protected void keyPressed(int paramInt) {
    if(paramInt == -7) {
      midlet.destroyApp(true);
      midlet.notifyDestroyed();
    } else if(paramInt == -5) {
      CaptureVideo cv = new CaptureVideo(this, midlet, videoControl);
      cv.start();
    } else if(paramInt == 49 && images[0] != null) {
      ImageCanvas imgCanvas = new ImageCanvas(midlet, this, images[0]);
      midlet.display.setCurrent(imgCanvas);
    } else if(paramInt == 50 && images[1] != null) {
      ImageCanvas imgCanvas = new ImageCanvas(midlet, this, images[1]);
      midlet.display.setCurrent(imgCanvas);
    } else if(paramInt == 51 && images[2] != null) {
      ImageCanvas imgCanvas = new ImageCanvas(midlet, this, images[2]);
      midlet.display.setCurrent(imgCanvas);
    } else if(paramInt == 52 && images[3] != null) {
      ImageCanvas imgCanvas = new ImageCanvas(midlet, this, images[3]);
      midlet.display.setCurrent(imgCanvas);
    } else if(paramInt == 53 && images[4] != null) {
      ImageCanvas imgCanvas = new ImageCanvas(midlet, this, images[4]);
      midlet.display.setCurrent(imgCanvas);
    }
  }
}

VideoSnap.java:-
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.media.control.VideoControl;
public class VideoSnap extends MIDlet {
  public Display display;
  private Player player;
  private VideoControl videoControl;
  public void startApp() {
    display = Display.getDisplay(this);
    try {
      //player = Manager.createPlayer("capture://video");
      player = Manager.createPlayer("capture://image");
      player.realize();
      player.prefetch();
      videoControl = (VideoControl)player.getControl("VideoControl");
      Canvas canvas = new VideoCanvas(this, videoControl);
      display.setCurrent(canvas);
      player.start();
    } catch (IOException ioe) {} catch (MediaException me) {}
  }
  public void pauseApp() {}
  public void destroyApp(boolean unconditional) {
  player.close();
  }
}


Just compile this program & use it.

For more information visit Dwij IT Solutions.

Simple Game in J2ME for Nokia3110

This is a Game which is made in J2ME.
Following is the files under the Sun's Wireless Toolkit JDK.
src
|_FullScreenGame.java
|_MainCanvas.java
|_MenuCanvas.java
|_TitleCanvas.java

FullScreenGame.java:-
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class FullScreenGame extends MIDlet implements CommandListener {
private Display display;
private TitleCanvas titleCanvas;
private MainCanvas mainCanvas;
private MenuCanvas menuCanvas;
public int score=0;
public void startApp() {
display = Display.getDisplay(this);
titleCanvas = new TitleCanvas();
menuCanvas = new MenuCanvas(this);
display.setCurrent(titleCanvas);
try{Thread.sleep(2000L);}
catch (InterruptedException localInterruptedException){}
display.setCurrent(menuCanvas);
System.gc();
}
public void GameOver() {
display.setCurrent(menuCanvas);
System.gc();
}
public void GameStart() {
mainCanvas = new MainCanvas(this);
display.setCurrent(mainCanvas);
}
public void pauseApp(){}
public void destroyApp(boolean paramBoolean){}
public void commandAction(Command paramCommand, Displayable paramDisplayable) {}
}


MainCanvas.java:-
import java.io.*;
import javax.microedition.lcdui.*;
import java.util.*;
class MainCanvas extends Canvas implements Runnable {
Image image;
int width,height,mode,XPosition=60,inc=1,x=3,y=3,paramInt=5,miss=0;
static int speed=10;
boolean running = true;
FullScreenGame mainProgram;
public MainCanvas(FullScreenGame fsg) {
mainProgram = fsg;
mainProgram.score=0;
try{image = Image.createImage("/back.jpg");}catch (IOException localIOException) {}
setFullScreenMode(true);
Thread localThread = new Thread(this);
mode = 2;
localThread.start();
}
public void run() {
while(running) {
repaint();
try{Thread.sleep(speed);}catch(InterruptedException e){return;}
}
}
public void paint(Graphics g) {
if(y==133 && (mode==1 || mode==2)) {
if(XPosition+2 > x || x > XPosition+22)
miss++;
else {
if(mode==1)mode=0;
if(mode==2)mode=3;
mainProgram.score+=10;
}
}
if(x==2) {
if(mode==0)mode=3;
if(mode==1)mode=2;
}
if(y==137) {
if(mode==1)mode=0;
if(mode==2)mode=3;
}
if(x==119) {
if(mode==2)mode=1;
if(mode==3)mode=0;
}
if(y==2) {
if(mode==0)mode=1;
if(mode==3)mode=2;
}
switch(mode) {
case 0:
x-=inc;
y-=inc;
break;
case 1:
x-=inc;
y+=inc;
break;
case 2:
x+=inc;
y+=inc;
break;
case 3:
x+=inc;
y-=inc;
break;
}
g.drawImage(image,0,0,0);
g.setColor(0,0,0);
g.drawLine(2,144,125,144);//Bottom Bar Line
g.drawRect(1,1,125,157);//Boundry
g.setColor(255,0,128);
g.drawString("Score:"+mainProgram.score+" Speed:"+(11-(speed/2))+" Miss:"+miss,3,146,0);//String Bottom Bar
g.setColor(128,0,255);
g.fillRect(XPosition+2,140,20,4);//Bar
g.setColor(255,0,0);
g.fillArc(x,y,7,7,0,360);//Ball
if(miss == 5) {
g.drawString("Game Over",45,60,0);
g.drawString("Score: "+mainProgram.score,45,60,0);
running = false;
mainProgram.GameOver();
}
}
protected void keyPressed(int paramInt) {
if(paramInt == 35)//Close on Button #
mainProgram.GameOver();
if(paramInt == -3)//LEFT
if(XPosition != 0)
XPosition = XPosition-10;
if(paramInt == -4)//RIGHT
if(XPosition < 101)
XPosition = XPosition+10;
if(paramInt == -2)//DOWN
if(speed < 21)
speed +=2;
if(paramInt == -1)//UP
if(speed > 2)
speed -=2;
}
}


MenuCanvas:-
import java.io.IOException;
import javax.microedition.lcdui.*;
import java.util.*;
class MenuCanvas extends Canvas {
Image image;
int width,height;
int randomNo[]={12,6,9,8,3,11,4,9,7,6,2,10,7,2,5,10,8,12,4,9,8,
2,6,2,10,7,1,5,2,5,12,4,9,8,0,2,7,0,2,9,0,2,4,9,5,12,6,9,8,3,
11,4,3,7,6,2,10,7,2,5,2,5,12,4,9,8,2,6,2,10,7,2,5,7,5,12,4,9,
8,0,2,3,0,2,6,0,2,4,9,512,6,9,8,3,11,4,3,7,6,2,10,7,2,5,2,5,12,
4,9,8,2,6,2,10,7,2,5,2,5,12,4,9,8,0,2,2,0,2,2,0,2,4,9,5};
Font font,simpleFont;
FullScreenGame mainProgram2;
public MenuCanvas(FullScreenGame fsgame) {
mainProgram2 = fsgame;
try {
image = Image.createImage("/back.jpg");
} catch (IOException localIOException) {}
setFullScreenMode(true);
width = getWidth();
height = getHeight();
}
public void paint(Graphics g) {
simpleFont=g.getFont();
font = Font.getFont(32,1,16);
g.setFont(font);
g.drawImage(image,0,0,0);
g.setColor(225, 0, 0);
g.drawString("Nirmal Ganesha",8,20,0);
g.setColor(225, 0, 128);
g.drawRect(35,44,60,12);
g.drawRect(33,42,64,16);
for(int i=0;i<128;i+=3){
g.drawRect(i,0,3,randomNo[i+1]);
g.drawRect(i,160-randomNo[i],3,randomNo[i]);
}
g.drawString("DX Ball",41,43,0);
g.setColor(225, 0, 255);
g.setFont(simpleFont);
g.drawString("Creater: Ganesh Bhosale",4,62,0);
g.setColor(0, 0, 225);
g.drawString("Press Fire to Start Game",4,80,0);
g.drawString("Press # to Close",25,100,0);
g.setColor(128,0,255);
g.drawString("Last Game Score: "+mainProgram2.score,18,120,0);
}
protected void keyPressed(int paramInt) {
System.out.println(paramInt);
if(paramInt == 35) {//Close on Button # 
mainProgram2.notifyDestroyed();
}
if(paramInt == -5) {
mainProgram2.GameStart();
}
}
}
TitleCanvas.java:-
import java.io.IOException;
import javax.microedition.lcdui.*;
class TitleCanvas extends Canvas {
private Image image;
private int width;
private int height;
public TitleCanvas() {
try {
image = Image.createImage("/title.jpg");
}
catch (IOException localIOException) {}
setFullScreenMode(true);
width = getWidth();
height = getHeight();
}
public void paint(Graphics g) {
g.fillRect(0, 0, width, height);
g.setColor(225, 0, 128);
g.drawImage(image, width / 2 - (image.getWidth() / 2), height / 2 - (image.getHeight() / 2), 0);
g.drawString("Nirmal Ganesh", 1, 1, 0);
}
}

The variable "Mode" used in Program is showing direction of ball. That is well explained in Image below:



The following are the Required image files for this Game which must be put into "res" folder:- back.jpg:-  title.jpg:-  
Just compile this program & use it.

The screenshot below may help you little bit.

For more information visit Dwij IT Solutions.


Thursday, April 22, 2010

Triniti


|| Jai Shree Mataji ||
She is a Mother of All Mothers.
From her lotus feets dust this universe is created.
She is one who is Kundalini residing on our Sahasrara.
She is one who loves us, cares us, help us, save us.
She is one who is a doer of all divine work.
She is one who flows through all divine things.
She is one who wants to save the humanity in the World.
She is one who is Adishakti, our Primordial Mother.

She is one who is Triniti,
She is Mahalakshmi, who develope us,
She is Mahasaraswati, who works through us,
She is Mahakali, who wishes through us,

Mother, May every day be yours.
Every moment be yours.
Every live be yours.

Oh Mother you are the supreme source of Love.

Salute to you mother again and again, again and again.

|| Jai Shree Mataji ||

Sabako dua dena maa sabako dua dena,
Jai nirmal mataji dilame sada rehana maa sabako dua dena

|| Jai Shree Mataji ||


For more information visit Dwij IT Solutions.


Wednesday, April 14, 2010

Send EMail by Java

This is a program used to send Email using Java with use of Gmail SMTP Server.
For using this code just change Account Settings.
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class SendMail {
  public static void main(String[] args) {
    String userName = "gdb.sci123@gmail.com";
    String passWord = "password";
    String host = "smtp.gmail.com";
    String auth = "true";
    boolean debug = false;
    String to = "gdb_sci123@rediffmail.com";
    String subject = "MySubject";
    String text = "Jai Shree Mataji, This email is send by Java Program";

    Properties props = new Properties();
    props.put("mail.smtp.user", userName);
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.auth", auth);
    props.put("mail.smtp.port", "465");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.socketFactory.fallback", false);
    try {
      Session session = Session.getDefaultInstance(props, null);
      session.setDebug(debug);
      
      MimeMessage msg = new MimeMessage(session);
      msg.setText(text);
      msg.setSubject(subject);
      msg.setFrom(new InternetAddress(userName));
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
      msg.saveChanges();
      
      Transport transport = session.getTransport("smtp");
      transport.connect(host, userName, passWord);
      transport.sendMessage(msg, msg.getAllRecipients());
      transport.close();
    } catch (Exception mex) {
      mex.printStackTrace();
    }
  }
}


For more information visit Dwij IT Solutions.