postheadericon HTML Exercises





1.      Write HTML code to develop a web page having the background in red and title “My First Page” in any other color.
2.     Create a HTML document giving details of your name, age, telephone, address, Pin code & enrollment no. aligned in proper order (About Me page for you)
3.       Write HTML code to design a page containing a text in a paragraph give suitable heading style. Create three paragraphs each should differently align like left, right and center.
4.       Create a page to show different attribute of Font tag.
5.       Create a page to show different attribute italic, bold, underline, strike, subscript superscript etc.

postheadericon Android Read Phone Contacts Example

Read contact from Phone book  using Content Provider

Ex12Activity.java

package com.bipin.rupadiya.Ex12;



import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract.PhoneLookup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

postheadericon Android Service Example



postheadericon Android WebView Example

postheadericon Android SQLite Database tutorial


postheadericon Android Shape XML Example


postheadericon Android Shapes Example using Java code




postheadericon Android AlertDialog with setMultiChoiceItems Example



postheadericon Android ProgressDialog Example



postheadericon Android AlertDialog setSingleChoiceItems Example



postheadericon Android AlertDialog List Example



postheadericon Android AlertDialog Example



postheadericon Android TimePickerDialog Example



postheadericon Android DatePickerDialog Example


postheadericon Android Button onClick Example that implements onClickListener

This example explain the how we can listen onClick event  of multiple Android Button by implementing  onClickListener.



postheadericon Android Button Example with onClickListener

This example explain the use of anonymous object of onClickListener to listen the click event from Android Button object 


postheadericon Android TimePicker Example with setOnTimeChangedListener


postheadericon Android DatePicker example with onDateChanged listener


postheadericon An Android RadioGroup Example Programmatically



postheadericon Android RadioGroup Example using setOnCheckedChangeListener





MainActivity.java

package bipin.rupadiya.radiogroupexample;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;

postheadericon Android Checkbox Example



MainActivity.java

package bipin.rupadiya.checkboxexample;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;

postheadericon android Checkbox setOnClickListener Example



MainActivity.java

package bipin.rupadiya.checkboxexample;

postheadericon Android Checkbox setOnCheckedChangeListener Example



MainActivity.java

package bipin.rupadiya.checkboxexample;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;

postheadericon command line arguments in linux shell script


args.sh

echo "Total Number of Argument : "$#
echo "Programe Name : "$0
n=0
for i in $*
do
n=`expr $n + 1`
echo "\nArgumnet [ "$n" ] : "$i
done

postheadericon Example of command line argument in C on Linux

args.c

#include "stdio.h"
void main(int c, char *argv[])
{
    int i;
    for(i=0;i<c;i++)
    {
        printf("\nargument[%d] : %s",i,argv[i]);    
    }
}

postheadericon Example of command line argument in Java

args.java

public class args
{
public static void main(String args[])
{
for(int i=0;i<args.length;i++)
{
System.out.println("argument[ "+i+" ] : "+args[i]);
}
}
}

postheadericon AES with CBC mode example in Java

AESCBC.java

package bsr;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
class AESCBC
{
public KeyGenerator keygenerator;
public SecretKey myDesKey;
Cipher c;
public IvParameterSpec iv;
public AESCBC() throws Exception
{

postheadericon AES with CFM mode example in Java

AESCFM.java

package bsr;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
class AESCFM
{
public KeyGenerator keygenerator;
public SecretKey myDesKey;
Cipher c;
public IvParameterSpec iv;
public AESCFM() throws Exception
{

postheadericon AES with ECB mode example in Java

AESECB.java

package bsr;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
class AESECB
{
public KeyGenerator keygenerator;
public SecretKey myDesKey;
Cipher c;
public AESECB() throws Exception
{

postheadericon 3DES with CFM mode example in Java

D3ESCFM.java

package bsr;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
class D3ESCFM
{
public KeyGenerator keygenerator;
public SecretKey myDesKey;
Cipher c;
public IvParameterSpec iv;
public D3ESCFM() throws Exception
{

postheadericon 3DES with CBC mode example in Java

D3ESCBC.java

package bsr;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
class D3ESCBC
{
public KeyGenerator keygenerator;
public SecretKey myDesKey;
Cipher c;
public IvParameterSpec iv;
public D3ESCBC() throws Exception
{

postheadericon 3DES with ECB mode example in Java

D3ESECB.java


package bsr;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
class D3ESECB
{
public KeyGenerator keygenerator;
public SecretKey myDesKey;
Cipher c;
public D3ESECB() throws Exception
{
// Genrate the Key
keygenerator = KeyGenerator.getInstance("DESede");
myDesKey = keygenerator.generateKey();

postheadericon RSA Encryption Example in Java

RSA.java

import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
class RSA
{
public KeyPairGenerator keygenerator;
public KeyPair myKey;
Cipher c;
public RSA() throws Exception
{
// Genrate the Key
keygenerator = KeyPairGenerator.getInstance("RSA");
keygenerator.initialize(1024) ;
myKey = keygenerator.generateKeyPair();

postheadericon JSP JDBC Example

Develop a JSP Page to perform database driven operations like insert, Delete, Update and selection with table named Student having fields like StudId, Name, Address, result.



Create Table in Oracle / MySQL [ student ]

CREATE TABLE   student (
StudId NUMBER( 4 ) NOT NULL ,
Name VARCHAR( 15 ) NOT NULL ,
Address VARCHAR( 20 ) NOT NULL ,
result NUMBER( 8 ) NOT NULL
)


postheadericon example of preparedstatement in java


Create Table in MySql [ Employee ]


CREATE TABLE  `wtad`.`Employee` (
`EmpId` INT( 4 ) NOT NULL ,
`Empname` VARCHAR( 15 ) NOT NULL ,
`Emp_desig` VARCHAR( 20 ) NOT NULL ,
`Emp_J_Date` VARCHAR( 20 ) NOT NULL ,
`Emp_Salary` INT( 8 ) NOT NULL
) ENGINE = MYISAM ;

Create Table in Oracle [ Employee ]

postheadericon example of page directive in jsp

index.jsp

<html>
<head>
<title>EX-35</title>
</head>
<body>
<%@ page language="java" %>
<%@ page info="A code from www.BipinRupadiya.com"  %>
<ul>
<li><a href="import.jsp">Example of page directive import </a></li>
<li><a href="isThreadsafe.jsp">Example of page directive isThreadsafe </a></li>
<li><a href="jsp-forward.jsp">Example of page directive jsp-forward </a></li>
<li><a href="contentType.jsp">Example of page directive contentType </a></li>
<li><a href="errorPage.jsp">Example of page directive isErrorPage and errorPage </a></li>
</ul>
<body>
</html>


postheadericon example of jsp scripting elements

index.jsp

<html>
<head>
<title>EX-36</title>
</head>
<body>
<!-- Declaration -->
<%!
int i=0;
int n=10;
int ans=0;
%>

postheadericon Example of requestdispatcher

index.jsp

<html>
<head>
<title>MySqlLogin</title>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:300px;
left:5in;
border-style:solid;
}
</style>
</head>

postheadericon JSTL standard tag library Example

index.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<HTML>
<HEAD>
<TITLE>WTAD: Ex31 : www.BipinRupadiya.com</TITLE>
</HEAD>
<BODY>
<h3>Example of JSTL standard tag library.</h3>
<ul>
<li><a href="set.jsp">set, remove and out</a></li>
<!-- Example of c:for -->
<li><a href="for.jsp">for</a></li>
<!-- Example of c:if -->
<li><a href="if.jsp">if</a></li>
<!-- Example of c:choose -->
<li><a href="choose.jsp">choose</a></li>
<!-- Example of c:redirect and c:param -->
<li><a href="redirect.jsp">redirect</a></li>

</ul>
</BODY>
</HTML>

postheadericon DES with CBC mode example in Java

DESCBC.java

class DESCBC
{
public KeyGenerator keygenerator;
public SecretKey myDesKey;
Cipher c;
public IvParameterSpec iv;
public DESCBC() throws Exception
{
// Genrate the Key
keygenerator = KeyGenerator.getInstance("DES");
keygenerator.init(new SecureRandom());
myDesKey = keygenerator.generateKey();

postheadericon DES with CFM mode example in Java

DESCFM.java

class DESCFM
{
public KeyGenerator keygenerator;
public SecretKey myDesKey;
Cipher c;
public IvParameterSpec iv;
public DESCFM() throws Exception
{
// Genrate the Key
keygenerator = KeyGenerator.getInstance("DES");
keygenerator.init(new SecureRandom());
myDesKey = keygenerator.generateKey();

postheadericon DES with ECB mode example in Java

DESECB.java

import bsr.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
/*A code from www.bipinrupadiya.com*/
class DESECB
{
public KeyGenerator keygenerator;
public SecretKey myDesKey;
Cipher c;

postheadericon One Time Pad Encryption Example using Java code

Write a programs to simulate encryption and decryption technique using One Time Pad, algorithm development and Communication between client and server should be done using Java server socket programming.


OneTimePad.java


package bsr;
import java.util.*;
import java.net.*;
import java.io.*;
/*A code from www.bipinrupadiya.com*/
public class OneTimePad
{
public String doEncryption(String s)
{
int i,j;

postheadericon S-Box Example using Java

Write a programs to simulate encryption and decryption technique using S-Box, algorithm development and Communication between client and server will be done using Java server socket programming.

SBOX.java

package bsr;
import java.util.*;
import java.net.*;
import java.io.*;
/*A code from www.bipinrupadiya.com*/
public class SBOX
{
public String doEncryption(String s)// throws Exception
{
int i,temp;

postheadericon P-Box Example using Java

Write a programs to simulate encryption and decryption technique using P-Box, algorithm development and Communication between client and server will be done using Java server socket programming.

P-Box.java

package bsr;
import java.util.*;
import java.net.*;
import java.io.*;
/*A code from www.bipinrupadiya.com*/
public class PBOX
{
public String doEncryption(String s)
{
int i,temp;

postheadericon Transposition cipher example using Java

Write a programs to simulate encryption and decryption technique using Transposition (Columnar) Cipher, algorithm development and Communication between client and server will be done using Java server socket programming.

TranspositionCipher.java

package bsr;
import java.util.*;
import java.net.*;
import java.io.*;
/*A code from www.bipinrupadiya.com*/
public class TranspositionCipher
{
public String selectedKey;
public char sortedKey[];
public int  sortedKeyPos[];

postheadericon Mono-alphabetic Substitution Cipher example using Java

Write a programs to simulate encryption and decryption technique using Mono-alphabetic Substitution Cipher, algorithm development and Communication between client and server will be done using Java server socket programming.

MonoAlphabeticSubstitutionCipher.java

package bsr;
import java.util.*;
import java.net.*;
import java.io.*;
/*A code from www.bipinrupadiya.com*/
public class MonoAlphabeticSubstitutionCipher
{
public char p[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
public char ch[] = {'Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M'};
public String doEncryption(String s)
{

postheadericon Generalized Caesar Cipher example using java

Write a programs to simulate encryption and decryption using Caesar Cipher. algorithm development and Communication between client and server is done using Java socket programming.


CaesarCipher.java

package bsr;
import java.util.*;
import java.net.*;
import java.io.*;
/*A code from www.bipinrupadiya.com*/
public class CaesarCipher
{
char a[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int key=3;

postheadericon java socket programming example



In the era of network programming means write such a script that can be executed on multiple computers / platform. In J2SE, a package java.net provide the number of API that can be used to write code for the communication between multiple computers / platforms. The java.net package of J2SE provide the sport for two important protocol of the network that is TCP and UDP.

The Socket in java provide the way of communication between two or more computers using Transmission Control Protocol (TCP). Here we have  socket  on both side at Client as well as server. A client socket try to communicate to server socket. If everything is fine server accept the connection and communication process begin.

Here I am going to demonstrate a simple example of server socket programming. I have created a java package  bsr and my class that have the definition of socket MySocket.java is placed inside this package. 

I have also created two more class to simulate the behavior of client and server namely sender and  receiver. I used plain text editor to create my script.


postheadericon Protocol 3 A Simplex Protocol for a Noisy Channel

header.h


#include<stdio.h>
#include<fcntl.h>
#include<string.h>
//define Frame structure
struct frame
{
int frame_type;//{1-frame, 0-ack}
int seqno;
int ackno;
char data[50];
};
//services used @ sender side
void from_network_layer(char buffer[])
{
printf("\nEnter Data : ");
scanf("%s",buffer);
}
void to_physical_layer(struct frame *f)
{
int pid1;
system(">pipe1");
pid1=open("pipe1",O_WRONLY);
write(pid1,f,sizeof(struct frame));
close(pid1);
if(f->frame_type==1)
{
printf("\n\n\tFrame [%d]-[%s] sucessfully send.\n",f->seqno,f->data);
}
else
{
printf("\n\n\tAcknowledment [%d]-[%s] sucessfully send.\n",f->ackno,f->data);
}
}
int get_ack()
{
int pid2,ackno=0;
pid2=open("pipe2",O_RDONLY);
if(pid2>0)
{
read(pid2,&ackno,sizeof(ackno));
unlink("pipe2");
}
close(pid2);
return ackno;
}
int start_timer(int seqno)
{
printf("\nTimer Starts");
int i=1,flag=1;
for(i=1;i<=10;i++)
{
sleep(1);
if(seqno==get_ack())
{
flag=0;
break;
}
printf("\ntime : %d ",i);
}
return flag;
}
//services used @ reciving side
void from_physical_layer(struct frame *f)
{
int pid1;
pid1=open("pipe1",O_RDONLY);
f->seqno=0;
if(pid1>0)
{
read(pid1,f,sizeof(struct frame));
unlink("pipe1");
}
close(pid1);
}

void to_network_layer(struct frame *f)
{

printf("\n\nframe No [ %d ]-[%s]received successfully\n",f->seqno,f->data);

}
void send_ack(int seqno)
{
int pid2;
system(">pipe2");
pid2=open("pipe2",O_WRONLY);
if(pid2>0)
{
write(pid2,&seqno,sizeof(seqno));
}
close(pid2);
}

postheadericon Protocol-2 stop-and-wait protocol

header file


/*
Protocol-2 (stop-and-wait) ,
one-directional flow of data from sender to receiver,
error free channel, The receiver has only a finite buffer capacity and a finite
processing speed, protocol must prevent the sender from flooding
*/

#include<stdio.h>
#include<fcntl.h>
#include<string.h>

//define Frame structure
typedef struct
{
int seqno;
int ackno;
char data[100];
}frame;


//services used @ sender side
void from_network_layer(char buffer[],int sno)
{
printf("Enter Frame [%d] : ",sno);
scanf("%s",buffer);
}

void to_physical_layer(frame *f)
{
int pid1;
system(">pipe1");
pid1=open("pipe1",O_WRONLY);
write(pid1,f,sizeof(frame));
close(pid1);
}

void wait_for_event(int seq_no)
{
int pid2,no;
while(1)
{
pid2=open("pipe2",O_RDONLY);
read(pid2,&no,sizeof(no));
 
if(no==seq_no)
break;

}
close(pid2);
unlink("pipe2");
}

//services used @ reciving side
void from_physical_layer(frame *f)
{
int pid1;
pid1=open("pipe1",O_RDONLY);
read(pid1,f,sizeof(frame));
close(pid1);
unlink("pipe1");
}

void to_network_layer(char buffer[])
{
printf("\nFrame  : %s",buffer);
}

void send_ack(int seqno)
{
int pid2;
system(">pipe2");
pid2=open("pipe2",O_WRONLY);
write(pid2,&seqno,sizeof(seqno));
close(pid2);
}


Sender




#include "header.h"

void main()
{
int i,no,pids;
char buffer[100];
frame f;

printf("How many frame you want to send? : ");
scanf("%d",&no);


for(i=0;i<no;i++)
{
from_network_layer(buffer,i);/*  get some data from network layer to send next layer */
strcpy(f.data,buffer);/*  copy received data into frame's pay load for transmission */
f.seqno=i;
to_physical_layer(&f); /*  send our frame on physical layer */
wait_for_event(i); /* block sender until sender received acknowledment from receciver*/
}
}

postheadericon Protocol 1 utopia

header file


/*
   Protocol 1 (utopia)
   provides for data transmission in one direction only, from sender to receiver.
   The communication channel is assumed to be error free,
   and the receiver is assumed to be able to process all the input infinitely fast.
   Consequently, the sender just sits in a loop pumping data out onto the line as
   fast as it can.

*/


#include<stdio.h>
#include<fcntl.h>
#include<string.h>

//define the frame structure
typedef struct
{
int seqno;
int ackno;
char data[100];
}frame;

//services used @ sender side
void from_network_layer(char buffer[],int sno)
{
printf("Enter Frame [%d] : ",sno);
scanf("%s",buffer);
}

void to_physical_layer(int pid,frame *f)
{
write(pid,f,sizeof(frame));
}


//services used @ reciving side

void from_physical_layer(int pid,frame *f)
{
read(pid,f,sizeof(frame));
}

void to_network_layer(char buffer[],int sno)
{
printf("\nFrame [%d] : %s",sno,buffer);
}

postheadericon Cyclic Redundancy Check - CRC


Sender / CRC Genretor



//CRC-Cyclic Redundancy Check Code

#include<stdio.h>
#include<string.h>
#include<fcntl.h>
void main()
{
int i,j,divisor_len,dividend_len,pid;
char dividend[100],dataword[100], divisor[30],temp[30],quotient[100],remainder[30],divisor1[30];

system("clear");

system(">pipe");
pid=open("pipe",O_WRONLY);

printf("Enter dividend: ");
scanf("%s",dataword);
strcpy(dividend,dataword);

printf("Enter divisor : ");
scanf("%s",divisor);
write(pid,&divisor,sizeof(divisor));
//calculate length of data  
divisor_len=strlen(divisor);

dividend_len=strlen(dividend);

//create backup of original divisor
strcpy(divisor1,divisor);

//left shift rawbits in dividend with divisor_len-1
for(i=0;i<divisor_len-1;i++)
{
dividend[dividend_len+i]='0';
}

//copy original dividend(without padding bits) into temp
for(i=0;i<divisor_len;i++)
{
temp[i]=dividend[i];
}

for(i=0;i<dividend_len;i++)
{
quotient[i]=temp[0];
//select quitient bit ZERO if first bit of current dividend is ZERO otherwise ONE
if(quotient[i]=='0')
{
//if ZERO selected Divisor became all ZERO bits
for(j=0;j<divisor_len;j++)
{
divisor[j]='0';
}
    }
else
{
//if ONE is selected divide with Original divisor
for(j=0;j<divisor_len;j++)
{
divisor[j]=divisor1[j];
}
}
for(j=divisor_len-1;j>0;j--)
{
//do the process of XOR and get Reminder
    if(temp[j]==divisor[j])
{
//temp[j]==divisor[j] : Reminder
// 0 == 0 : 0
// 1 == 1 : 1
    remainder[j-1]='0';
}
    else
{
//temp[j]==divisor[j] : Reminder
// 0 == 1 : 1
// 1 == 0 : 1

    remainder[j-1]='1';
}
}
remainder[divisor_len-1]=dividend[i+divisor_len];
strcpy(temp,remainder);
}
for(i=0;i<divisor_len-1;i++)
{
remainder[i]=temp[i];
}
remainder[i]='\0';

system("clear");
printf("\n[%d] - Dataword : %s",strlen(dataword),dataword);
printf("\n[%d] - Divisor  : %s",strlen(divisor1),divisor1);
printf("\n[%d] - CRC      : %s",strlen(remainder),remainder);
strcat(dataword,remainder);
printf("\n[%d] - Codeword : %s\n",strlen(dataword),dataword);
write(pid,&dataword,sizeof(dataword));
close(pid);

}


postheadericon Block Parity Check - Error Detection and Correction Techniques



Sender / Block Parity Generator 


//block parity sender
#include<stdio.h>
#include<string.h>
#include<fcntl.h>

// one bit for NULL char and
// second for Parity bit

#define Frame_Size 32 // size of frame in bit

#define ROW 4+1 //segments
#define COL 8+2 // m bits in a segment [ +2 for '*' and '\0' ]


int getBit(int frameData,int pos)
{
//get binary equavalient of our Frame Data by setting on bit by bit

int code=1; // take base of binary 1 [ 00000001 ]

code=code<<(pos-1); // do the left shift to find  postion

if(frameData & code)  // if both bits are 1 then set bit otherwise return ZERO
return 1;
else
return 0;

}


void blockParity(char myframe[ROW][COL])
{
int i=0,j=0,ROW_count=0,COL_count=0;

//[ Horizontal parity ]
for(i=0;i<ROW;i++)//ROW's Parity Check
{
ROW_count=0;
for(j=0;j<COL-2;j++) //we r using -2 because we want to exclude last two bit that is * and NULL
{
if(myframe[i][j] == '1')//count ROW Parity
{
ROW_count++;
}
}
if((ROW_count % 2) == 0) //set ROW parity bit
myframe[i][j] = '0' ;
else
myframe[i][j] = '1';
}

//[ Virtical parity ]
for(i=0;i<COL-2;i++)//COL's Parity
{
COL_count=0;
for(j=0;j<ROW;j++)
{
if(myframe[j][i] == '1')//count COL Parity
{
COL_count++;
}

}
if((COL_count % 2) == 0) //set COL parity bit
myframe[ROW-1][i] = '0' ;
else
myframe[ROW-1][i] = '1';

}

}

postheadericon Checksum - Error Detection and Correction Techniques


checksum.h


//checksum header file
#include<stdio.h>
#include<string.h>
# define segment_len 8
# define no_segments 4
# define frameSize 32
int getBit(int frameData,int pos)
{
int code=1; //base
code=code<<(pos-1);

if(frameData & code)
return 1;
else
return 0;
}

void sum(char segment1[],char segment2[])
{
int i,j;
//int segment_len=strlen(segment1);
int ans=0,carry=0;
char ans_segment[9]=" ";
// segment_len--;//because starting from zero

for(i=segment_len-1;i>=0;i--)
{
ans=0;
ans=( (int)segment1[i]-48 ) + ( (int)segment2[i]-48 ) + carry; //sum of bits on each position of two segments

if(ans>=2)//carry genrated
{
carry=1;
if(ans==2)
ans=0; // 1 + 1 = 10 ans
else
ans=1;//  1 + 1 + 1(carry) = 11 ans
}
else
{
carry=0;
}
ans_segment[i]=ans+48;

}
ans_segment[segment_len+1]='\0';
strcpy(segment1,ans_segment);

if(carry==0)
return;
else
sum(segment1,"00000001"); //recursive call of function if carry genrated
}


void complement(char segment[])
{
int i,len=strlen(segment);
for(i=0;i<len;i++)
{
if(segment[i]=='1')
segment[i]='0';
else
segment[i]='1';
}
segment[i]='\0';
}


postheadericon GTU Mobile Computing - Android Result 2012-13


Hurray...!

By the grace of God we secured 100% result in the subject of Mobile Computing (Android), continuously second time in Gujarat Technological Exam [Sem-4] in year 2012-13.

I would like to extend thanks to all my students for their sincere efforts.


Bipin Ruapdiya

postheadericon Byte Stuffing - Framing Technics


Sender



#include<stdio.h>
#include<fcntl.h>
#include<string.h>


#define FLAG '#'

#define ESC '*'

void main()
{
int j=1,i,pid;

char Frame_Data[50],Targeted_Frame[50];

system("clear");
  system(">pipe");
pid=open("pipe",O_WRONLY);

printf("Enter the Frame Data : ");
  scanf("%s",Frame_Data);

Targeted_Frame[0]=FLAG; //set header FLAG

for(i=0;i<strlen(Frame_Data);i++)
{
    if (Frame_Data[i]==FLAG || Frame_Data[i]==ESC) //check FLAG or ESCAPE charechter is in frame data
{
    Targeted_Frame[j++]=ESC; // if FLAG / ESCAPE Char found add one more ESCAPE char

}
    Targeted_Frame[j++]=Frame_Data[i]; //copy other data

  }
Targeted_Frame[j++]=FLAG; //set tailer FLAG
Targeted_Frame[j]='\0';

printf("\nFrame to be send  : %s",Targeted_Frame);
write(pid,&Targeted_Frame,sizeof(Targeted_Frame));
close(pid);
}


postheadericon Single Bit Parity Check


Sender

/*Single bit Parity check*/

#include<stdio.h>
#include<fcntl.h>
#include<string.h>

int getBit(int frameData,int pos)
{
    //get binary equavalient of our Frame Data by setting on bit by bit

    int code=1; // take base of binary 1 [ 00000001 ]

    code=code<<(pos-1); // do the left shift to find  postion

    if(frameData & code)  // if both bits are 1 then set bit otherwise return ZERO
        return 1;  
    else
        return 0;

}


int getParity(char targeted_frameData[])
{
    //find the even parity
    int i=0,counter=0;
    for(i=0;i<32;i++)
    {
        if(targeted_frameData[i]=='1')    //count total no. of 1
            counter++;      
    }
    if(counter % 2 == 0 )//Even parity
        return 0;
    else  
        return 1;
}
void main()
{
    int frameData,i,k=0,flag,pid,frame_size=32;;
    char targeted_frameData[34];
    pid=open("pipe",O_WRONLY);

    //Enter Frame Data in decimal Number
    printf("\nEnter Frame Data : ");
    scanf("%d",&frameData);

     for(i=frame_size;i>0;i--)
    {
        targeted_frameData[k++]=getBit(frameData,i) + 48;
    }

    //Set Parity bit
    targeted_frameData[k++]=getParity(targeted_frameData) + 48;
    targeted_frameData[k++]='\0';

    printf("\n\nTageted Frame : %s\n",targeted_frameData);

    write(pid,&targeted_frameData,sizeof(targeted_frameData));
    close(pid);
}

postheadericon Character Count - Framing Technics


Sender


#include<stdio.h>
#include<fcntl.h>
#include<string.h>
void main()
{
int Frame_Count,j=0,len,i,k,pid;
char Frame_Data[50],targeted_frame[100];
system("clear");

system(">pipe");
pid=open("pipe",O_WRONLY);

printf("How many Frame you data want to send : ");
scanf("%d",&Frame_Count);
for(i=0;i<Frame_Count;i++)
{
printf("\nEnter Frame [%d] : ",i);
scanf("%s",Frame_Data);
len=strlen(Frame_Data);
targeted_frame[j]=len+1+48; //set Header [header + total char followed by header]
for(k=0;k<len;k++)
{
j++;
targeted_frame[j]=Frame_Data[k];
}
j++;
}
targeted_frame[j]='\0';
printf("\nFRAME TO SEND : %s",targeted_frame);

write(pid,&targeted_frame,sizeof(targeted_frame));
}
 /*2i5love6india*/

postheadericon Bit Stuffing - Framing Technics

Sender



#include<stdio.h>
#include<string.h>
#include<fcntl.h>



int getBit(int frameData,int pos)
{
//get binary equavalient of our Frame Data by setting on bit by bit

int code=1; // take base of binary 1 [ 00000001 ]

code=code<<(pos-1); // do the left shift to find  postion

if(frameData & code)  // if both bits are 1 then set bit otherwise return ZERO
return 1;
else
return 0;

}


void bitStuffing(char myFrame[])
{
// stuffing procedure
int i=0,k=0,counter=0;
char temp[50];
strcpy(temp,myFrame);
while(temp[i]!='\0')
{
myFrame[k++]=temp[i]; // update Frame data by doing Stufing
if(temp[i]=='1')
{
// if we encounter continues 1 then do increment in counter
counter++;
}
else
{
// if continuty of 1's break, reset counter to ZERO
counter=0;
}
if(counter==5)
{
// after a FIVE consicutive ONE stuff a bit ZERO
myFrame[k++]='0';
}
i++;
}
myFrame[k]='\0';
}
void main()
{
int pid,i,no,k=0,frameData,frame_size=32;
char myFrame[50];


system(">pipe");


pid=open("pipe",O_WRONLY); // open named pipe for write mode

system("clear");

//Enter Frame Data in decimal Number
printf("\nEnter Frame Data : ");
scanf("%d",&frameData);

for(i=frame_size;i>0;i--)
{
myFrame[k++]=getBit(frameData,i)+48;
}
myFrame[k]='\0';

printf("\nBefore Stuffing Frame : %s",myFrame);

bitStuffing(myFrame); // do the process of bit Stuffing

printf("\nAfter Stuffing  Frame : %s\n\n",myFrame);
write(pid,&myFrame[0],sizeof(myFrame)); //write frame in to named pipe
}

postheadericon Difference between GenericServlet and HttpServlet

GenericServlet:


  • As name says it Generic in nature. Means GenericServlet is protocol-independent.
  • import  javax.servlet.servlet package
  • super class of GenericServlet are java.lang.Object and it implements three interfaces Servlet, ServletConfig and java.io.Serializable
  • To write a generic servlet, override the abstract service().
  • GenericServlet  lifecycle methods use ServletConfig interface.
  • GenericServlet implements the log() from ServletContext interface.
  • Prototype:
    • public abstract class GenericServlet extends java.lang.Object implements Servlet, ServletConfig, java.io.Serializable
  • Example:

postheadericon hello world servlet example

Step 1 :  Create .java File using text editor


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class ServletDemo extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML><HEAD><TITLE>WTAD</TITLE></HEAD> <body>");
String str="<h1>welcome to </h1>";
str=str+"<br>www.bipinrupadiya.blogspot.com";
out.println(str);
        out.println("</body> </html>");
}
}

postheadericon Setup Environment Variable for Tomcat



Step : 1 Right Click on My computer and Choose Propertis


    Step : 2 From System Properties Dialog box got to Advance tab and click on Environment Variable Button


    postheadericon install tomcat 7

    This text define How to install Tomcat Application server on windows operating system


    Step : 1 Download Java Development Kit 


    • Servlet required Java Development Kit to compile and Execute  code 
    • Go to http://www.oracle.com and Download latest version of JDK and JRE
    • Install JDK

    Step : 2 Select IDE for the Development of Servlet

    • There so many editor used for J2EE Devlopment like NetBeans, Eclipse, Dreamviewer or Plain Text Editor etc.
    • We use Notpad  as per GTU Guidelines  

    Blog Archive

    Total Pageviews

    © BipinRupadiya.com. Powered by Blogger.