Professional Documents
Culture Documents
It0423 Ipt Manual 2012-13
It0423 Ipt Manual 2012-13
DEPARTMENT OF INFORMATION TECHNOLOGY
FACULTY OF ENGINEERING & TECHNOLOGY
LAB MANUAL
FOR
SUBJECT: INTEGRATIVE PROGRAMMING &TECHNOLOGY LAB
SUBJECT CODE: IT0423
PREPARED BY
N.J.SUBASHINI & J.JEYSREE
Assistant Professor
Department of Information Technology
SRM University, SRM Nagar, Kattankulathur‐603203
Kancheepuram District, Tamil Nadu
IT 0423 –Integrative Programming and Technology LAB
SYLLABUS
IT INTEGRATIVE PROGRAMMING AND 0 0 4 2
0423 TECHNOLOGIES LAB
Co requisite
IT 0407 INTEGRATIVE PROGRAMMING AND
TECHNOLOGIES
PURPOSE
This course enables the students to practice and implement various concepts like RMI, JAVA
BEANS, and Web services using EJB.
INSTRUCTIONAL OBJECTIVES
After successful completion of the course, the students should be able to
• Implement distributed application using RMI.
• Implement distributed components such as Java bean, EJB
• Implement Language interoperability program using JNI
LIST OF EXERCISES
JAVA
• Multiple Inheritance
• Frames , Applet and Different Components
JAVA BEAN
• Create a simple bean components using java class and swing class
RMI
• Create a RMI component to reverse a given string from server to client as
requested
• .Create a RMI component to transfer one file from server to client as requested
using web application
JNI
• Object Passing
• Sorting Array
• Exception handling and different data types
•
ENTERPRISE JAVA BEAN
• Create a session, message driven and entity component
• Create a web services
• Create a design pattern
TOTAL 60
REFERENCE:
1. Integrative Programming and Technologies Lab Manual, Department of Information
Technology, SRM University
IT 0423 –Integrative Programming and Technology LAB
LIST OF EXERCISES
1. BASIC JAVA
a. Multiple Inheritance – Employee Detail
b. Event Handling – Leave Application Form
2. RMI
a. File Transfer
b. With Servlet to Perform different arithmetic operation
3. JAVA BEANS
a. Account Details –Using Non-Visual Bean
b. Color Bean – Using Visual Bean
4. JNI
a. Object Passing
b. Sorting Array
c. Different Data Types and Exception handling
5. MSMQ Using VB
a. Passing message using MSMQ
IT 0423 –Integrative Programming and Technology LAB
TABLE OF CONTENT
IT 0423 –Integrative Programming and Technology LAB
Question : Develop a payroll System in JAVA to illustrate the concept of Multiple Inheritance.
Procedure:
1. Design a interface called as “NetPayCalculation” with the following method declarations.
a. void grosspaycalculation();
b. void taxcalculation();
c. float netpaycalculation();
2. Design a simple class called as “Employee” with the following variables & methods
Variables are :-
int ID_No; String Name, DOJ, Designation, PAN_No, Department; float Basic_pay;
Methods are:-
void get_Data() Æ get all the variables defined/mentioned above
3. Design a main class which called “payroll” extends and implements the above
mentioned class & interface respect with following variables & methods.
Variables are:-
float gross-pay, Taxable_amount, Net_pay;
Method :-
void display_details()Æ to display all the details about an employee.
Specifications :-
grosspay calculation method:
Define 2 float variables DA, HRA
Where DA= 50% of basic_pay
HRA= 20% of basic_pay
Gross_pay = sum of DA, HRA & Basic_pay
Tax calculation method:
If the total income for 12 months is between >=1,00,000 & <2,00,000 then
Taxable _amount = 20% of gross_pay
else if > 3,00,000
Taxable_amount = 30% of gross_pay
Netpaycalculation method:
From this method call the grosspay & tax calculation methods and calculate the
Net_pay as gross_pay – taxable_amount;
Return the net_pay
In main() method
create an object & call the get_data() & display_details() methods.
IT 0423 –Integrative Programming and Technology LAB
Solution:
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
Sample Output
IT 0423 –Integrative Programming and Technology LAB
Question: Develop a Leave Application Form using Swing Components. It should contain a Submit
button and Print button. On clicking submit button no. days the student has applied leave for should be
calculated. On clicking on Print button the details entered by the student should get displayed in another
Frame
Procedure:
1. Design JApplet called “LeaveApplication” with the following components
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
Solution:
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
Sample Output
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
Question: Develop a RMI program using servlet to perform different arithmetic operation, by getting the
values from the user through HTML file.
Procedure:
1. Design a interface called as ‘Arithmetic_Interface’ with the following method definition
public double add(double a,double b)
public double sub(double a, double b)
public double div(double a, double b)
public double mul(double a, double b)
public double mod(double a, double b)
2. Create a java main class called as “ArithmeticServer_Impl” which implements the above
interface. Define the necessary connection inside main and define different arithmetic function.
3. Design a HTML page with the <form> tag as given below and name the html file as
‘Arithmetic_Rmi_html’
Note: use <table> tag for proper alignment
4. Create a servlet program ‘ArithmeticClient_Servlet’ as client for requesting the server and
display the result.
IT 0423 –Integrative Programming and Technology LAB
Solution:
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
Sample Output
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
Question: Develop a JAVA Bean to calculate the current balance in your account and display the balance
detail as a message using JFrame.
Procedure:
1. Create a java bean class named as ‘AccountDetail_Bean’. Define the following
Properties
a. private String Date
b. private long Acct_no
c. private String Name
d. private double Withdraw_amount
e. private final double Balance_amt = 100000
Methods
a. public void generate_SystemDate( )
It gets the system date and from this call setDate( ) method.
b. public double current_balance( )
This method calculates balance as balance = Balance_amt – withdraw_amount. If
balance_amt is less than Withdraw_amount then return balance_amt itself,
otherwise return the balance calculated.
2. Create another project with java swing Form. In this create a JFrame called as Account_Form.
Design the form with following details.
IT 0423 –Integrative Programming and Technology LAB
c. Calculate the current balance by invoking the method current_balance( ) defined in Bean
class and set the calculated current balance to the label “lbl_Balance”.
4. On double clicking the ‘Message button
5. Display the message as “Balance in your Account no: <acc_no> as on <date> is <balance_amt>”
6. The message should be displayed using JoptionPane.showMessageDialog(null, output, “sms”, 1).
Solution:
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
Sample Output:
IT 0423 –Integrative Programming and Technology LAB
Question: Create a visual java bean using mouse event for moving a small oval along with the
cursor point.
Procedure:
1. Design a Java Bean class named as “MouseMove_Bean” extends JPanel class.
with properties :- private int Circle_size=20
private int xm, ym ;
method:- private color randomColor() {……}
> used to generate random colors.
[Hint- use predefined color() class Æ takes 3 int org for color() constructor.Math.random() used
to provide random no.]
Overridden methods ( From JPanel)
a. public void paintComponent (Graphics g)
Set the color by calling random color () method & draw the oval with the “Circlesize”
property defined above
b. public Dimension get( )
Return new Dimension (200, 200) for setting the size of the JPanel
Inside the Constructor
a. Set the background for the JPanel (Bean created) and addMouseMotionListener to
perform Mousemoved event.
b. Inside the MouseMoved () event method get the x, y position of the cursor and set it from
xm & ym variables.
Note :- While drawing the oval use xm, ym, circle-size, so that circle moves when xm, ym
changes when mouse is moved.
2.Design a JApplet Form called as “MouseMove_Form”
Here drag & drop the above bean created.
3.Execute the JApplet.
IT 0423 –Integrative Programming and Technology LAB
Solution:
Add properties to the class as stated in the previous exercise, with the class extending JPanel
IT 0423 –Integrative Programming and Technology LAB
Sample Output
IT 0423 –Integrative Programming and Technology LAB
Question: To create a JNI program to pass object as argument from java to c program.
Procedure:
1) Create a Java Application named as “Exercise4_JNI” with a java main class named as
“PassingObject” and a java class named as “SimpleClass”
2) In the “SimpleClass” file do the following
a. Declare a variable int count;
b. Define a method named “Increment()” to increment the count value by 10 as
count=count*10; and print the count value inside the method.
3) In the “PassingObject” class/file do the following
a. Define a native method declaration as follows
public static native void changecountvalue ( SimpleClass sc); and inside the main()
method perform the following
1. Create the obj for SimpleClass as sc,
2. assign the value of count to 10,
3. invoke the Increment() method,
4. invoke changecountvalue by passing ‘sc’ as argument ,
5. print the value of count before and after changecountvalue() method call.
4) Create a C/C++ application project named as “Excercise4_JNI_C” with “PassingObject.c”
file in it.
Create header file & perform the necessary step to change the value of count from c program.
Solution:
IT 0423 –Integrative Programming and Technology LAB
Within this package create a java class file and main class file with native methods
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
Sample Output
IT 0423 –Integrative Programming and Technology LAB
Question: To create a JNI program to sort the values in an array by using C++ application.
Procedure:
1. Create a java main class named as “Sorting_array” which contain only one native method as
follows
public native int[] ArraySorting (int[] array);
and a static array declaration as
Static int array[];
within the main() method perform the following.
a. get the length of the array
b. now using length create a new array
c. from user get the values for the array
d. call the method ArraySorting (int []) by passing the array values got from the user.
e. assign the return value of ArraySorting() method to a new array variable called as
sorted_array[] and print the sorted_array[] values.
Solution:
Follow the same steps as mentioned in the above program
1. Create a java main class
2. Generate the header file for the java class
3. Create C/C++ applications with necessary codes
4. Set the properties, clean and build to generate the .dll file
5. Load the .dll file in the .java file
IT 0423 –Integrative Programming and Technology LAB
Sample output
IT 0423 –Integrative Programming and Technology LAB
Question: To create a JNI program to use different types such as int, float, String & Exception
Handling with c program.
1. create a java main class called as “Exception_Difftypes”
Define the following method(s) declaration
a. public native int intMethod (int n);
b. public native Boolean booleanMethod (boolean text)
c. public native string stringMethod (String text);
d. public native void doit() throws IllegalArgumentException;
and the following method definition
e. public void callback () throws NullPointerException
{
throw new NullPointerException(“CatchThrow.callback”)
}
Inside the main () function perform the following
Create the object of the class and invoke the method a, b, c and print the values returned
by them.
In try… catch block call the d & e method.
2. Create a C/C++ application with “Exception_Differenttype.c” file
Create header file & perform the following operation in different method.
a. intMethod () Æ return the product of 2 No’s
b. booleanMethod () Æ return the !boolean value
c. StringMethod () Æ return the uppercase string
d. doit () Æ to throw the exception
Solution:
Follow the same steps as mentioned in the above program
1. Create a java main class
2. Generate the header file for the java class
3. Create C/C++ applications with necessary codes
4. Set the properties, clean and build to generate the .dll file
5. Load the .dll file in the .java file
IT 0423 –Integrative Programming and Technology LAB
Sample Output
IT 0423 –Integrative Programming and Technology LAB
Question: To create a application using VB for sending message using MSMQ concept
Procedure:
Create a STDEXE VB application named as “QWriter” with the following form design and write
the necessary code to update the message in the MSMQ object
Text box 1 named as txtlabel and text box 2 named as txtbody and command button named as
cmdsend
Create a STDEXE VB application named as “QReader” with the following form design and
write the necessary code to retrieve the message from the MSMQ object
Text Box named as txtLog, Button named as cmdDeleteQ, and a timer named as tmrTerminate
Specification:
ÆDefine a function LOG() to update the textbox with the message from writer.
ÆProvide condition as if message is not received for 30 sec close the Reader form(use timer
object)
IT 0423 –Integrative Programming and Technology LAB
ÆMake the label and button to be visible when last 10 min is left
IT 0423 –Integrative Programming and Technology LAB
Sample Output:
IT 0423 –Integrative Programming and Technology LAB
References:
1. Ash Rofail, Yasser Shohoud, Mastering COM and COM+, BPB Publications, New Delhi
2000.
2. Gerald Bose,Andreas Vogel, Keith Duddy, Java Programming with CORBA, Wiley
Publications, 2003.
3. http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html
4. http://download.oracle.com/javase/1.5.0/docs/guide/jni/spec/jniTOC.html
5. http://www.cygwin.com/setup.exe
6. http://www.codeproject.com/KB/COM/
7. http://www.cogin.com/articles/IntroductionToMSMQ.php
IT 0423 –Integrative Programming and Technology LAB
Solution Code
IT 0423 –Integrative Programming and Technology LAB
BASIC JAVA
a. Multiple Inheritance – Employee Detail
b. Event Handling – Leave Application Form
NetPayCalculation.java
public interface NetPayCalculation {
void grossPayCalculation();
void taxCalculation();
float netPayCalculation();
}
Employee.java
import java.util.*;
public class Employee {
Scanner s=new Scanner(System.in);
int ID_No;
String Name, DOJ, Designation, Pan_No,Department;
float Basic_Pay;
void get_Data()
{
System.out.println("Enter Employee ID Number: == ");
ID_No=s.nextInt();
System.out.println("Enter Employee Name: ==");s.nextLine();
Name=s.nextLine();
System.out.println("Enter Employee Date of Joining: ==");
DOJ=s.nextLine();
System.out.println("Enter Employee Designation: ==");
Designation=s.nextLine();
System.out.println("Enter Employee Pan Number: ==");
Pan_No=s.nextLine();
System.out.println("Enter Employee Department Name: ==");
Department=s.nextLine();
System.out.println("Enter Employee Basic Pay: ==");
Basic_Pay=s.nextFloat();
}
}
Department of Information Technology, SRM University P a g e | 56
IT 0423 –Integrative Programming and Technology LAB
Payroll.java
public class Payroll extends Employee implements NetPayCalculation{
float Gross_Pay, Taxable_amount,Net_Pay;
IT 0423 –Integrative Programming and Technology LAB
String todate=Text_Dateto.getText();
String to[]=todate.split("/");
IT 0423 –Integrative Programming and Technology LAB
int date1=Integer.parseInt(to[0]);
int month1=Integer.parseInt(to[1]);
int year1=Integer.parseInt(to[2]);
Calendar calendar2 = Calendar.getInstance();
calendar2.set(year1, month1,date1);
// Get the represented date in milliseconds
long milis1 = calendar1.getTimeInMillis();
long milis2 = calendar2.getTimeInMillis();
// Calculate difference in milliseconds
long diff = milis2 - milis1;
// Calculate difference in days
long diffDays = diff / (24 * 60 * 60 * 1000);
Long diffday=new Long(diffDays);
Text_applieddays.setText(diffday.toString());
String avalied_leave=Text_availedleave.getText();
int avail_leave=Integer.parseInt(avalied_leave);
long total_availed=diffDays+avail_leave;
if(total_availed>15)
{
Label_Leavestatus.setText("Leave is Not Approved");
}
else
{
Label_Leavestatus.setText("Leave is Approved");
}
}
private void PrintActionPerformed(java.awt.event.ActionEvent evt) {
PrintForm form=new PrintForm();
form.setVisible(true);
String name=Text_Name.getText();
String dept=Combo_Department.getSelectedItem().toString();
String leavetype=LIst_Leave.getSelectedValue().toString();
String appliedleave=Text_applieddays.getText();
String reason=Textarea_Reason.getText();
String status=Label_Leavestatus.getText();
form.printdata(name,dept,leavetype,appliedleave,reason,status);
}
}
IT 0423 –Integrative Programming and Technology LAB
PrintForm.java
public class PrintForm extends javax.swing.JFrame {
/** Creates new form PrintForm */
public PrintForm() {
initComponents();
// String name=LeaveApplication
}
void printdata(String name,String dept,String leavetype,String appliedleave,String
reason,String status)
{
Lbl_name.setText(name);
Lbl_Dept.setText(dept);
Lbl_type.setText(leavetype);
Lbl_days.setText(appliedleave);
Lbl_reason.setText(reason);
Lbl_status.setText(status);
}
}
2. RMI
a. File Transfer
b. With Servlet to Perform different arithmetic operation
File Transfer
FileRetrieve_Int.java
import java.rmi.*;
public interface FileRetrieve_Int extends Remote{
public byte[] downloadFile(String fileName) throws RemoteException;
}
FileRetrieve_Impl.java
import java.rmi.*;
import java.rmi.server.*;
import java.io.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class FileRetrieve_Impl extends UnicastRemoteObject implements FileRetrieve_Int {
public FileRetrieve_Impl() throws RemoteException{
}
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
Arithmetic_interface.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Arithmetic_interface extends Remote
{
public double add(double a, double b) throws RemoteException;
public double sub(double a, double b) throws RemoteException;
public double mul(double a, double b) throws RemoteException;
public double div(double a, double b) throws RemoteException;
public double mod(double a, double b) throws RemoteException;
}
ArithmeticServer_Impl.java
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class ArithmeticServer_Impl extends UnicastRemoteObject implements
Arithmetic_interface{
public ArithmeticServer_Impl() throws RemoteException{
}
public static void main(String[] args) {
ArithmeticServer_Impl server = null;
try {
server = new ArithmeticServer_Impl();
Registry registry = LocateRegistry.createRegistry(1099);// default:1099
registry.rebind("RemoteObject", server);
System.out.println("Server started..........");
}catch(Exception e){ e.printStackTrace(); }
}
@Override
public double add(double a, double b) throws RemoteException {
return (a+b);
}
@Override
public double sub(double a, double b) throws RemoteException {
return(a-b);
}
@Override
IT 0423 –Integrative Programming and Technology LAB
import java.io.IOException;
import java.io.PrintWriter;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name="ArithmeticClient_Servlet", urlPatterns={"/ArithmeticClient_Servlet"})
public class ArithmeticClient_Servlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
Arithmetic_interface obj = null;
try {
obj = (Arithmetic_interface)(Naming.lookup("rmi://localhost:1099/RemoteObject"));
} catch (NotBoundException e) {
e.printStackTrace();
}
String s1=request.getParameter("Num1");
String s2=request.getParameter("Num2");
response.setContentType("text/html;charset=UTF-8");
IT 0423 –Integrative Programming and Technology LAB
double num1=Double.parseDouble(s1);
double num2=Double.parseDouble(s2);
out.println("<b>Sum of Two Numbers === </b>"+ obj.add(num1, num2));
out.println("<br><b>Difference between two Numbers === </b>"+ obj.sub(num1, num2));
out.println("<br><b>Product of Two Numbers === </b>"+ obj.mul(num1, num2));
out.println("<br><b>Division of Two Numbers === </b>"+ obj.div(num1, num2));
out.println("<br><b>Modulus of Two Numbers === </b>"+ obj.mod(num1, num2));
} finally {
out.close();
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}
}
3. JAVA BEANS
a. Account Details –Using Non-Visual Bean
b. Color Bean – Using Visual Bean
Account Details –Using Non-Visual Bean
AccountDetail_Bean.java
import java.util.Calendar;
import java.util.GregorianCalendar;
public class AccountDetail_Bean {
private String Date;
private long Acct_no;
private String Name;
private final double Balance_amt = 100000;
private double Withdraw_amount;
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
{
double balance = Balance_amt-Withdraw_amount;
if(Withdraw_amount>Balance_amt)
{
return Balance_amt;
}
else
{
return balance;
}
}
}
Account_form.java
import javax.swing.JOptionPane;
public class Account_form extends javax.swing.JFrame {
public Account_form() {
setSize(500, 650);
initComponents();
accountDetail_Bean1.generate_SystemDate();
Lbl_date.setText(accountDetail_Bean1.getDate());
}
private void Button_OKActionPerformed(java.awt.event.ActionEvent evt) {
accountDetail_Bean1.setName(Text_name.getText());
accountDetail_Bean1.setAcct_no(Long.parseLong(Text_AccountNo.getText()));
double bala=accountDetail_Bean1.getBalance_amt();
Double balance = new Double(bala);
Text_balance.setText(balance.toString());
accountDetail_Bean1.setWithdraw_amount(Double.parseDouble(Text_Withdraw.getText()));
double current_balance=accountDetail_Bean1.current_Balance();
Double current_bala = new Double(current_balance);
Lbl_Balance.setText("Current Balance is=="+current_bala.toString());
}
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
super.paintComponent(g);
g.setColor(randomcolor());
g.fillOval(xm - Circle_Size/2, ym - Circle_Size/2, Circle_Size, Circle_Size);
}
public MouseMove_Bean()
{
setBackground(Color.CYAN);
addMouseMotionListener (new MouseAdapter()
{
@Override
public void mouseMoved(MouseEvent me)
{
xm = me.getX();
ym = me.getY();
repaint();
}
});
}
@Override
public Dimension getPreferredSize()
{
return new Dimension(200, 200);
}
Create a file named as Mousemove_form.java and drag and drop the bean added to the pallete
4. JNI
a. Object Passing
b. Sorting Array
c. Different Data Types and Exception handling
Object Passing
SimpleClass.java
package exercise6_jni;
public class SimpleClass {
int count;
IT 0423 –Integrative Programming and Technology LAB
IT 0423 –Integrative Programming and Technology LAB
import java.util.Scanner;
public class Sorting_array {
static int array[];
static
{
System.load("E:\\INTEGRATIVE PROGRAMMING AND TECHNOLOGIES\\IT0407 -
IPT\\LAB\\Exercise6_JNI_CPP_Program\\DLLFile\\sort.dll");
}
public native int[] ArraySorting(int[] array);
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of elements to be sorted...");
int array_length=sc.nextInt();
array=new int[array_length];
System.out.println("Enter the array elements...");
for(int i=0;i<array_length;i++)
{
array[i]=sc.nextInt();
}
IT 0423 –Integrative Programming and Technology LAB
}
Sorting_array.cpp
#include <cstdlib>
#include "jni.h"
#include "Headerfile.h"
#include <iostream.h>
using namespace std;
int main(int argc, char** argv) {
return 0;
}
JNIEXPORT jintArray JNICALL Java_exercise6_1jni_Sorting_1array_ArraySorting
(JNIEnv *env, jobject obj, jintArray array)
{
int i,temp;
jsize len=(env)->GetArrayLength(array);
jint *body=(env)->GetIntArrayElements(array,0);
//jintArray res=(*env)->GetIntArrayElements()
for (i=0; i<len; i++)
{
for(int j=0;j<len;j++)
{
if(body[i]>body[j])
{
temp=body[i];
body[i]=body[j];
body[j]=temp;
}
}
}
cout<<"C++ sorting\n";
for(i=0;i<len;i++)
{
cout<<body[i]<<"\n";
}
jintArray result = env->NewIntArray(len);
env->SetIntArrayRegion(result, 0, len, body);
return result;
IT 0423 –Integrative Programming and Technology LAB
}
Different Data Types and Exception handling
Exception_Difftypes.java
package exercise6_jni;
public class Exception_Difftypes {
static
{
System.load("E:\\INTEGRATIVE PROGRAMMING AND TECHNOLOGIES\\IT0407 -
IPT\\LAB\\Exercise6_JNI_Exp_dt\\dist\\expdt.dll");
}
edt.callback();
} catch (Exception e) {
System.out.println("In Java1:\n\t" + e);
}
try {
edt.doit();
} catch (Exception e) {
System.out.println("In Java2:\n\t" + e);
}
IT 0423 –Integrative Programming and Technology LAB
}
}
Exception_differenttypes.c
#include <stdio.h>
#include <stdlib.h>
#include "jni.h"
#include "Header.h"
#include <string.h>
int main(int argc, char** argv) {
return (EXIT_SUCCESS);
}
JNIEXPORT jint JNICALL Java_exercise6_1jni_Exception_1Difftypes_intMethod
(JNIEnv *env, jobject obj, jint num)
{
return num * num;
}
JNIEXPORT jboolean JNICALL Java_exercise6_1jni_Exception_1Difftypes_booleanMethod
(JNIEnv *env, jobject obj, jboolean jbool)
{
return !jbool;
}
JNIEXPORT jstring JNICALL Java_exercise6_1jni_Exception_1Difftypes_stringMethod
(JNIEnv *env, jobject jobj, jstring string)
{
const char *str = (*env)->GetStringUTFChars(env, string, 0);
char cap[128];
strcpy(cap, str);
(*env)->ReleaseStringUTFChars(env, string, str);
return (*env)->NewStringUTF(env, strupr(cap));
}
JNIEXPORT void JNICALL Java_exercise6_1jni_Exception_1Difftypes_doit
(JNIEnv *env, jobject obj)
{
jthrowable exc;
jclass cls = (*env)->GetObjectClass(env, obj);
jmethodID mid =(*env)->GetMethodID(env, cls, "callback", "()V");
(*env)->CallVoidMethod(env, obj, mid);
exc = (*env)->ExceptionOccurred(env);
if (exc) {
IT 0423 –Integrative Programming and Technology LAB
jclass newExcCls;
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
newExcCls = (*env)->FindClass(env,"java/lang/IllegalArgumentException");
if (newExcCls == NULL) {
return;
}
(*env)->ThrowNew(env, newExcCls, "thrown from C code");
}
}
5. MSMQ Using VB
a. Passing message using MSMQ
Passing message using MSMQ
QReader.vbp
Main.frm(source code)
Option Explicit
IT 0423 –Integrative Programming and Technology LAB
qinfoIn.PathName = ".\PRIVATE$\TestQ"
On Error Resume Next
qinfoIn.Create
If Err.Number = MQ_ERROR_QUEUE_EXISTS Then
Log "*Test queue already exists*"
ElseIf Err.Number <> 0 Then
Log "*Queue creation error: " & Hex$(Err.Number) & " " & Err.Description & "*"
Else
Log "*Test queue created*"
End If
On Error GoTo 0
IT 0423 –Integrative Programming and Technology LAB
QWriter.vbp
Main.frm (source code)
Option Explicit
With msgOut
.Label = txtLabel.Text
.Body = txtBody.Text
.Send destOut, MQ_NO_TRANSACTION
End With
txtLabel.Text = ""
txtBody.Text = ""
txtLabel.SetFocus
End Sub
IT 0423 –Integrative Programming and Technology LAB
.Open
End With
End Sub