Converting a .JAR Into .EXE for WIndows user

We, the Java developers, develop softwares using Java because of it’s platform independency . Though now-a-days JDK is available to users,we usually provide JAR file of the software to the user.So, users can start it with only a double click. But  still some windows users prefere .exe version of that software. So, now I am going to tell you about a software by which we can convert a .jar file to .exe for windows user.

Before starting this we must read these two posts carefully.

Click here

We will use Jar to exe convert wizard 1.8 to convert  our jar files to exe.

 

Step 1 : Install the software and run the wizard.

Step 2:  Browse project.jar and press next.

Step 3: Select Console application or Windows gui application

Step 4: Select the Main class from where the software will start and keep “select a picture for splash window” blank.

Step 5: enable Support System tray and disable all others disable. [or, you can change as your requirements.]

Step 6: Add others Jars you have used like mysql-connector.jar . Usually these are on project/dist/lib/ if you are using Netbeans IDE. 

Step 6:  press Next and Finish.

Step 7 : We got the converted exe file of our jar file.

 

Thanks for reading this post.

Ujjal

 

 

Creating AutoBack Up of MySQL Database using JAVA OR PHP ( পিএচপি অথবা জাভা তে কিভাবে মাইএসকিউএল ডাটাবেজ এর অটোমেটিক ব্যাকআপ করতে হয় )

It is usual that we need to backup the database in software development (specially in Enterprise Software,web applications ) Database is very important which contains all the information about the organization. Last night I have coded a auto backup script in both JAVA and PHP. Here I am gonna post them below with comment.

Code Written in JAVA

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Ujjal Suttra Dhar
 */

class create_backup{

    String database = "your_database_name",  user = "root", password = "pass";
    Connection m_Connection = null;
    Statement m_Statement = null;
    ResultSet m_ResultSet;
    String m_Driver = "com.mysql.jdbc.Driver";
    String m_Url = "jdbc:mysql://localhost:3306/" + database;

    public create_backup(){

        /*Eshtablishment of Connection of java code with MySQL using JDBC
         You must read my previous post to know further about this. 
         */
        try {
            Class.forName(m_Driver);
            m_Connection = DriverManager.getConnection(m_Url, user, password);
            //Create Statement object
            m_Statement = m_Connection.createStatement();

        } catch (Exception ex) {
            ex.printStackTrace();
        }

        try {
            //Database will be stored in filename.sql which can be import on MySQl as backup
            BufferedWriter  out = new BufferedWriter(new FileWriter("kernel_school.sql"));


            //Now here is the informations about the database of which backup will be created
            String dump = "C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump " //Path to mysql
                    + "--host=localhost" //Mysql hostname
                    + "--port=3306" //Mysql portnumber
                    + "--user=root" //Mysql username
                    + "--password=pass" //Mysql password
                    + "--add-drop-table" //Add a DROP TABLE statement before each CREATE TABLE statement
                    + "--add-drop-database" //Add a DROP DATABASE statement before each CREATE DATABASE statement
                    + "--complete-insert" //Use complete INSERT statements that include column names.
                    + "--extended-insert" //Use multiple-row INSERT syntax that include several VALUES lists
                    + "kernel_school";                  //Mysql databasename


            //executing the command through process.
            Process run = Runtime.getRuntime().exec(dump);


            /*resultant SQL informations are here on the br which can be read line by line .
            And at the same time it will be written on another sql file.*/
            InputStream in = run.getInputStream();
            InputStreamReader isr = new InputStreamReader(in);
            BufferedReader br = new BufferedReader(isr);
            String line = null;

            while ((line = br.readLine())!=null) {
                 out.write(line);
                 out.newLine();
            }

       out.flush(); // must flush or close the file after completing the task.
        // int exitVal = run.waitFor();//when exitVal is ,then the process is completed

        } catch (Throwable t) {
            t.printStackTrace();
      }

    }//constructor
 } // class



public class autobackup {
    public static void main(String a[]){
            new create_backup();
    }
}

Code Written in PHP

Changing ownership/Permission of Files/Folders in Linux

A common problem in using Linux is restriction. Some operations are restricted for users by root.But if it is needed to do that operation like editing what to do? Today I have faced same kind of problem. I use /var/www/ as localhost for server based development. I can’t get working jobs (already done) copied from another folder/device because of rescriction by addministrator. If I open that file as administrator ,it works. But It is impossible to open a large number of files by opening as administrator when in server based job like web development. So, I must make /var/www/ accessible for reading and writing for me.

To do this here is the command which must be executed on terminal.

sudo chown -R www-data:ujjal /var/www

// chown    -> change ownership
// www-data (owner name from)-> right click on the file and check permission tab for the owner name.
// ujjal   (owner name to be made)-> your username (check users and groups if you dont know your username)

or

sudo chmod 777 -R /var/www

Precautions: Linux is case sensitive.mind it.

Thanking you….

Frequently used header files ( string.h , algorithm ) in C/C++

I am starting this briefing assuming that the reader is already known about the basic structure of programming with C. Here you will find a brief collection which are used frequently in programming.

Let’s start from #include
strlen(): int strlen(consts char *array)
A frequently used function and quite familiar to everyone is strlen() which returns the length of a character array passed to the function.

Example:

char arr[]=”This is a strlen function test. ”;
Printf(“%d”,strlen(arr));
Output:  30


strcmp(): int strcmp(const char *a,const char *b)

This one is used for comparing two strings. It can be used on Big number comparison also.
Exapmle:


	char  a[]=”ABC”;
	char  b[]=”ABC”;
	char  c[]=”AAA”;
	// now 
	int  x= strcmp(a,b)  ; // x= 0  as a==b
	x= strcmp(a,c);	// x>0  as a>c;  1st  parameter>  2nd parameter
	x= strcmp(c,a)        // x<0  as c<a;   1st  parameter<  2nd parameter

Now what is the basis of comparison of this function and what does this comparison actually mean? This comparison actually means lexicographically comparison.
Each of the character has a ASCII value . and ASCII value thus ‘A’ is less than ‘a’
So if we compare them ‘a’ >’A’

Now let’s have a practice about this type of comparison .
1. strcmp( “abc”,”Abc” ) Output : >0
2. strcmp(“cow”,”woc”) Output: 0
4. strcmp(“cow”,”cowa”) Output: <0
Now have a look closely
A[]= “cow”
B[]= ”cowa”
If we see the memory we would see like this :

A[] :‘c’ ‘o’ ‘w’ 0 0
B[] :‘c’ ‘o’ ‘w’ ‘a’ 0

Now see place 0 : A[0]==B[0] // ‘c’
A[1]==B[1] // ‘o’
A[2]==B[2] // ‘c’
A[3]<B[3] // 0<’a’ by ascii value ( here 0 ,not ‘0’)
So,now strcmp return a value less than 0.
Thus strcmp(A,B)’y’ so it returns >0 value.
It will return 0 if and only if two strings are equal.

strcpy(): char *strcpy(char *destination,const char *source)
This function is used to copy 2nd string to 1st string.
Example:

char destination[]=”DEPT”;
char source[]=”CSE”;
strcpy(destination,source);

destination: “CSE”
source : ”CSE”
One thing is very important and should be remembered that Array size of destination must be greater than array of source, Else program may crash.
Now the question is why?
Look closely at the memory.
Say,
char dest=”cse”; // size is 4 considering the NULL
char source=”department”; // size is 11 considering the NULL
strcpy(dest,source);
Is it possible ?

dest: memory size 4 (considering the NULL)
‘c’ ‘s’ ‘e’ 0

Source : memory size 11 (considering the NULL)
‘d’ ‘e’ ‘p’ ‘a’ ‘r’ ‘t’ ‘m’ ‘e’ ‘n’ ‘t’ 0

Now think is it possible to keep this 11 elements including NULL (0) in 4 sized array of “dest” ? so you have to ensure that the destination will be long enough so that no overflow occurs .

strcat(): char * strcat(char *a,const char *n)
This function is generally used for concatenation. If two strings are str1,str2 then,

char str1[100],str2[100];
gets(str1);  // say input is “cse” 
gets(str2);   // say input is “ rocks.”
strcat(str1,str2);
puts(str1);    // output : cse rocks.
puts(str2);    // output : rocks

1st string is changed and no change to 2nd one .
But here we also have to be careful about size of 1st parameter . As 2nd parameter is added to 1st one , size should be available otherwise overflow will occur.

memset() : void * memset ( void * ptr, int value, size_t num )
This function is very much helpful.If you want to initialize an array with a desired value then what you will do, just iterate.but memset support this with a single statement.

Lets see

  int a[100];  // or  char a[100]
    for(int i=0;i<50;i++) 
 	a[i]= ‘f’;

this may be done by also this:

memset(a,’f’,50*sizeof(a[0]) );

if any one want to insert whole array a single value than

memset(a,’f’,sizeof(a));

A complete c code is also provided here for clarification. 

#include 
#include 

int main ()
{
  char str[] = "almost every programmer should know memset!";
  memset (str,'-',6);
  puts (str);
  return 0;
}

strtok: char * strtok ( char * str, const char * delimiters )
strtok is a superb function indeed. According to me this function is more valuable than any other cstring’s functions. Now let’s see ,what is it ?

char str[]=”I am a cse student. Oh! Shit, I forgot to say my high CGPA.”
strtok= string tokenizer (:P)

If you want to tokenize a string by space ,’!’ ,’.’, ‘,’ or any characters then you can do it by strtok. Now what does tokenize means ? sometimes we take input of an array of a paragraph and we need to separate the words form it. In this case words are our token .
You can use strtok in this case.
char * p =strtok(str,” .,!.”);
now we are ready to get tokens :
1. I
2. am
3. a
4. cse
5. student
6. Oh
7. shit
8. I
9. forgot
10. to
11. say
12. my
13. High
14. CGPA
We have 14 tokens as we has given delimiters ” .,!.”
Here a c code is also provided for more clarification.

#include 
#include 

int main ()
{
  char str[] ="- This, a sample string.";
  char * pch;
  printf ("Splitting string %s into tokens\n",str);
  pch = strtok (str," ,.-");
  while (pch != NULL)
  {
    printf ("%s\n",pch);
    pch = strtok (NULL, " ,.-");
  }
  return 0;
}

Output:
Splitting string "- This, a sample string." into tokens:
This
a
sample
string

This were frequently used string manupulating functions.

In c++ there is anothet header file algorithm.h which provides us many bullt-in function Which are frequently used by us. Here I am giving an example for describing some of them.

#include 
#include 
using namespace std;

int main()
{
    int a=10,b=15;

//a=10 b=15
    swap(a,b);
//a=15 b=10

    cout<< max(a,b)<

There are many of these types of usuful functions in this header file.For further information see books.

There is another thing called STL which means Standard Template Library,another useful library of functions which makes programmer's job easier. This function provides with decrease of line of codes.

Frequently used container classes of STL :
1. vector
2. queue
3. string
4. stack
5. map
6. list
7. set
8. pair

Fore more about STL click here

Thanking for reading this,
Ujjal Suttra Dhar
sssujjal@gmail.com

Programming,Mathematics and Newbies

I am not sure if I am the right person or not to write this. Now I am going to share something with you that I know. Yes, These all are about the “Importance of programming” for the newbies. Here I will inspire you to be a good programmer, not the “Boss” of one of the C/C++/JAVA/PHP or web developments and many others. Being a programmer means being well-developped logically i.e mathematically who can use any language whatever it is,to solve a real life problem efficiently. As I know, and I think everyone will agree with me that mathematics is the one and only way to solve any real-life problems (which are not defined impossible by the experts). As a Bangladeshi , It is a matter of shame that we are far from other countries in the race of mathematics which is an obstacle in the race of technological development. If you say,“God didn’t give me a good brain,what can I do?”, I will not agree with you. As my opinion, It’s all about practice.We,the lazy people,passes our time doing nothing. A Proverb is said to be “Practice makes a man perfect”.
So, What are you thinking now? Wanna start practicing mathematics and programming now? An Eiffel Tower can not be built in one night.So,you have to spend some of your precious times to gain the power to control your PC,the coming world of technology.now what to do? Let’s go through some steps.

Step 1:
Find some books on basic mathematics/Number theory.
* Elementary Number Theory with Applications
-Thomas Koshy
*Concrete mathematics
-Donald Knuth

Step 2:
Select an programming language to implement those mathematics you have learnt. Now-a-days, C,C++,JAVA are the most popular and widely used languages. If you are newbie ,I will suggest you to learn C because it is the most efficient and easiest language. Most of important softwares and Some of operating systems are developed in C.
If you are not a student of CSE background,don’t be afraid,because you can learn it easily. You can learn this from this book. Ya, all the newbies who are related to CSE,this book is also for you too.
*Art Of Programming contest
* Programming with C
-Bayron Gottfried
Step 3:
Now you have learnt a little bit of mathematics, at least one of the programming languages, it’s time go now. What to do? You have to solve problems.There are many Online judges,In which there are thousands of problem descriptions with the facility to judge your solution ,is it ok or not,I will mention “Is the solution efficient or not”.
As you are newbie I will suggest you to use UVA at first . For this you have to open an account on this site.you can browse problems of their site. The first job of you to read the problem carefully,find the solution ,then code it.
What is coding? If you have learnt any of the programming languages, don’t ask it again.You have to write a code which will take input and provide with outputs as the problem description. After login you have to submit your solution to the onlinejudge.That machine will judge your solution in RE (runtime error),TE (time limit exceede),WA (wrong answer),PA (presentation error) and AC (accepted).
When submitting,you have take some measures which will be described below.
You can track your progress from here .
After solving some of problems,you should not be limited only in a single judges.

Here are some others OJs.
*SPOJ
*Light OJ
*Topcoder
*Codeforces

Here are some of websites/blogs which can be useful for you too.
*Smilitude
* UVA FORUM

Problems solving with C:
A sample code for submitting a problem is given below.
[code]
#include<stdio.h>
int main()
{
int testcase,input,I,j,k;
while(scanf(“%d”,&input)==1)
{
//your solution exists here
If(input ==2)
printf(“two”);
else
printf(“Not two”);
}
return 0;
}
[/code]

Now practice problem solving. You must attend free online contests to judge yourself.

For any kind of help or suggestions
I am here

Minimum Spanning Tree in JAVA

বন্ধুরা অনেক আগে থেকে ফ্রিলান্সিং করলেও আমি করি নাই। আমার ইচ্ছা ছিল আগে প্রোফাইল ভাল করব যাতে বিড করলেই কাজ পাই। গত কাল রাতে হটাত ব্রাওজার এর বুকমার্ক দেখতে দেখতে হটাত চোখ পড়লো Ezdia নামক একটি সাইট এ। ঢুকলাম । প্রথমেই যার ওপর চোখ পড়ল তা হল minimum spanning tree এর implementation JAVA দিয়ে করতে হবে। ভাবলাম কোড তো C++ এ করাই আসে।JAVA তে convert করতে র কত সময় লাগবে। Bid করলাম । কাজ টা পেয়েও গেলাম। JAVA অনেকদিন দেখি নাই।তাই ভুলে গেসিলাম কিছু জিনিস। তাই করতে কিছুটা সময় বেসি লাগল। সব মিলিয়ে ২.৫০ ঘণ্টায় কাজ টা delivery দিলাম।

যাই হোক,কাজটা client এর পছন্দও হল। কিন্তু এখন পর্যন্ত উনি আমাকে pay করেন নাই। প্রথম কাজেই ধরা খাইলাম। ব্যাপার না। আরও হবে। আপাতত সেই কাজ তাই আপনাকে দেখাচ্ছি।

updater after 2 days
দেরীতে হলেও ফিডব্যাক পাওয়া গেল।টাকাও।

Here is the input/output format

Input

Input starts with an integer T, denoting the number of test cases.

Each case begins with an integer n denoting the number of nodes. Then there will be n lines, each having n space separated integers, denoting the lengths of two connected nodes. Each length will be between 0 and 100.

Output:
If generating a tree is impossible ,then output is -1 else the minimal cost.

Example:

Input:
3

2
27 26
1 52

4
0 10 10 0
0 0 1 1
0 0 0 2
0 0 0 0

4
0 1 0 0
1 0 0 0
0 0 0 1
0 0 1 0

Output:
Case 1: 105
Case 2: 12
Case 3: -1

[code]

import java.util.*;

class edge {

public int dist;
int st, end;

edge(int i, int j, int k) {
this.st = i;
this.end = j;
this.dist = k;
}
};

class exe {

public edge road[] = new edge[3000];
edge ce;
int arr[][] = new int[52][52];
int rank[] = new int[52];
int par[] = new int[52];
double ans = 0;
int min1 = 0, max1 = 0;
int cost;
int C, R, cnt, E;

int find(int i) {
if (i != par[i]) {
par[i] = find(par[par[i]]);
}
return par[i];
}

void link(int x, int y) {
if (rank[x] > rank[y]) {
par[y] = x;
} else {
par[x] = y;
if (rank[x] == rank[y]) {
rank[y]++;
}
}

}

void kruskal() {
int i = 0, j = 0, u, v, flag = 0;
System.out.println("Tree diagram is ");
for (i = 0; j < C – 1 && i < E; i++) {
u = find(road[i].st);
v = find(road[i].end);
if (u == v) {
continue;
}
link(u, v);
flag = 1;
j++;
min1 += road[i].dist;

System.out.println(road[i].st + "->" + road[i].end + " cost is " + road[i].dist);

}
if (j < C – 1) {
System.out.println(-1);
} else {
//System.out.println(max1-min1);
System.out.println("Minimal Cost is " + min1);
}

} //krus

public exe() {

int i, j, k, T, cs = 0;

Scanner s = new Scanner(System.in);

T = s.nextInt();

while (true) {
if (T == 0) {
break;
}

C = s.nextInt();

for (i = 1; i <= C; i++) {
par[i] = i;
rank[i] = 0;
}

k = 0;
max1 = 0;
for (i = 1; i <= C; i++) {
for (j = 1; j <= C; j++) {
arr[i][j] = s.nextInt();

if (arr[i][j] != 0 && i != j) {
road[k] = new edge(i, j, arr[i][j]);
k++;
}
max1 += arr[i][j];
}
}

E = k;
for (i = 0; i < E – 1; i++) {
for (j = i + 1; j < E; j++) {
if (road[i].dist > road[j].dist) {
ce = road[i];
road[i] = road[j];
road[j] = ce;
}

}
}

min1 = 0;

System.out.print("Case " + (++cs) + ": ");
kruskal();

T–;
} // while

}
}//class exe

public class Ezdia1 {

public static void main(String ars[]) {
try {
exe object = new exe();
} catch (Exception p) {
}

}
//main
}//class

[/code]

ধন্যবাদ সবাইকে।

Huffman coding

[code]
//Originally FOUND in Internet
//by RIT2009061 vikesh iiita

//Author: Ujjal Suttra DHar [CSE’08,RUET]

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>

using namespace std;

struct node {
int weight;
char value;
const node *child0;
const node *child1;

node( int c, int i ) {
value = c;
weight = i;
child0 = 0;
child1 = 0;
}

node( const node* c0, const node* c1 ) {
value = 0;
weight = c0->weight + c1->weight;
child0 = c0;
child1 = c1;
}

bool operator<( const node &a ) const {
if(weight ==a.weight)
return value>a.value;
else
return weight >a.weight;
}

void traverse(string code="") const{

if ( child0 ) {
child0->traverse( code + ‘0’ );
child1->traverse( code + ‘1’ );
} else {
cout <<" " <<value <<" ";
cout <<weight;
cout <<" " <<code <<endl;
}
}

};

/*
void count_chars( int *counts )
{
for ( int i = 0 ; i <256 ; i++ )
counts[ i ] = 0;

freopen("input.dat","r",stdin);

char c;
while((c=getchar())!=EOF)
counts[c]++;
}

*/

int main()
{

freopen("input.dat","r",stdin);

int counts[ 256 ];
char a[1000];

gets(a);

for ( int i = 0 ; i <256 ; i++ )
counts[ i ] = 0;

for(int i=0;i<strlen(a);i++)
counts[a[i]]++;

priority_queue < node > q;

for (int i = 0 ; i <256 ; i++ )
if ( counts[ i ] )
q.push( node( i, counts[ i ] ) );

//if you wanna show the queue
/*while(!q.empty()){
cout<<q.top().value<<endl;
q.pop();
}
*/

while ( q.size() >1 ) {
node *child0 = new node( q.top() );
q.pop();
node *child1 = new node( q.top() );
q.pop();
q.push( node( child0, child1 ) );
}

cout <<"CHAR FREQUENCY HOFFMAN-CODE" <<endl;
q.top().traverse();
return 0;
}

[/code]

BigInt by Jan vai

/**
*Author : Jan
*Problem Name : Big int for contest
*Algorithm :
*Complexity :
**/

#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include<iostream>
using namespace std;

struct Bigint {
string a;
int sign;

Bigint() {}
Bigint( string b ) { (*this) = b; }
int size() { return a.size(); }
Bigint inverseSign() { sign *= -1; return (*this); }
Bigint normalize( int newSign ) {
sign = newSign;
for( int i = a.size() - 1; i > 0 && a[i] == '0'; i-- ) a.erase(a.begin() + i);
if( a.size() == 1 && a[0] == '0' ) sign = 1;
return (*this);
}
void operator = ( string b ) {
a = b[0] == '-' ? b.substr(1) : b;
reverse( a.begin(), a.end() );
this->normalize( b[0] == '-' ? -1 : 1 );
}
bool operator < ( const Bigint &b ) const {
if( a.size() != b.a.size() ) return a.size() < b.a.size();
for( int i = a.size() - 1; i >= 0; i-- ) if( a[i] != b.a[i] ) return a[i] < b.a[i];
return false;
}
Bigint operator + ( Bigint b ) {
if( sign != b.sign ) return (*this) - b.inverseSign();
Bigint c;
for( int i = 0, carry = 0; i < (int)a.size() || i < (int)b.size() || carry; i++ ) {
carry += (i < (int)a.size() ? a[i] - 48 : 0) + (i < (int)b.a.size() ? b.a[i] - 48 : 0);
c.a += (carry % 10 + 48);
carry /= 10;
}
return c.normalize(sign);
}
Bigint operator - ( Bigint b ) {
if( sign != b.sign ) return (*this) + b.inverseSign();
if( (*this) < b ) return (b - (*this)).inverseSign();
Bigint c;
for( int i = 0, borrow = 0; i < (int)a.size(); i++ ) {
borrow = a[i] - borrow - (i < b.size() ? b.a[i] : 48);
c.a += borrow >= 0 ? borrow + 48 : borrow + 58;
borrow = borrow >= 0 ? 0 : 1;
}
return c.normalize(sign);
}
Bigint operator * ( Bigint b ) {
Bigint c("0");
for( int i = 0, k = a[i]; i < (int)a.size(); i++, k = a[i] ) {
while(k-- - 48) c = c + b;
b.a.insert(b.a.begin(), '0');
}
return c.normalize(sign * b.sign);
}
Bigint operator / ( Bigint b ) {
if( b.size() == 1 && b.a[0] == '0' ) b.a[0] /= ( b.a[0] - 48 ) ;
Bigint c("0"), d;
for( int j = 0; j < (int)a.size(); j++ ) d.a += "0";
int dSign = sign * b.sign; b.sign = 1;
for( int i = a.size() - 1; i >= 0; i-- ) {
c.a.insert( c.a.begin(), '0');
c = c + a.substr( i, 1 );
while( !( c < b ) ) c = c - b, d.a[i]++;
}
return d.normalize(dSign);
}
Bigint operator % ( Bigint b ) {
if( b.size() == 1 && b.a[0] == '0' ) b.a[0] /= ( b.a[0] - 48 ) ;
Bigint c("0");
int cSign = sign * b.sign; b.sign = 1;
for( int i = a.size() - 1; i >= 0; i-- ) {
c.a.insert( c.a.begin(), '0');
c = c + a.substr( i, 1 );
while( !( c < b ) ) c = c - b;
}
return c.normalize(cSign);
}
void print() {
if( sign == -1 ) putchar('-');
for( int i = a.size() - 1; i >= 0; i-- ) putchar(a[i]);
}
};

int main() {

Bigint a, b, c;
string p,q;

cin>>p>>q;
a=p;
b=q;

c = a + b;

c.print();

putchar('\n');

c = a - b;
c.print();
putchar('\n');

c = a * b;
c.print();
putchar('\n');

c = a / b;
c.print();
putchar('\n');

c = a % b;
c.print();
putchar('\n');

return 0;
}

JAVA [creating Jar files]

To create a jar file execute this command given below

[code]
jar cf jar-file input-file(s)
[/code]
//input files are .class files and extra files you have used like music,jars etc.

For more you can see this Creating JAR files
After creation you must specify the main class using manifest.

Ways to update a jar file with manifest……
I have created a text file as manifest like aaa.txt which contains

[Code]Main-class: Mainclassname
[/Code]
//a new line or enter must be pressed after Mainclassname before saving

Updating a jar file with main class, you have to move the jar file to the BIN folder of JDK. Then using the command propmt executed the commands given below:

[code]
jar umf aaa.txt calender.jar
jar xvf calender.jar
type META-INFMANIFEST.MF
[/code]
Now double-click on your JAR file….

Thanking you,
Ujjal

Stack Implementation in Assembly Language (Algebric expression is correct or not.)

Problem description:
This is a problem in elementary algebra is to decide if a given algebric expression containing several kinds of brackets,such as [,],{,},(,), is correctly bracketed or not.

For example:
(a+[b-{c*(d-e)}]+f) is correctly bracketed but (a+[b-{c*(d-e)]}+f) is not correctly bracketed.

Solution:
This is the case if
(a) There are the same number of left and right bracketes of each kinds,and
(b) When a right bracket appears,the most recent preceeding unmatched left bracket should be of the same type.
This can be decided by using stack. The expression is scanned left to right. When a left bracket is encountered,it is pushed onto the stack. When a right bracket is encountered, the stack is poped (if the stack is empty ,there are too many right brackets) and the brackets are compared. If they are of the same type,the scanning continues.If there is a mismatch,the expression is incorrectly bracketed. At the end of the expression ,if the stack is empty ,the expression is correctly bracketed otherwise there are too many left brackets.
[code]
.model small
.stack 100h
.data

cr equ 0DH ; cr represents carriage return
lf equ 0AH ; lf represents line feed

msg DB cr,lf,’ENTER AN ALGEBRIC EXPRESSION : ‘,cr,lf,’$’
msg_correct DB cr,lf,’EXPRESSION IS CORRECT.$’
msg_left_bracket DB cr,lf,’TOO MANY LEFT BRACKETS. BEGIN AGAIN!’,cr,lf,’$’
msg_right_bracket DB cr,lf,’TOO MANY RIGHT BRACKETS. BEGIN AGAIN!’,cr,lf,’$’
msg_mismatch DB cr,lf,’BRACKET MISMATCH. BEGIN AGAIN!’,cr,lf,’$’
msg_continue DB cr,lf,’Type Y if you want to Continue : ‘,cr,lf,’$’

.code

main proc

mov ax,@data ;get data segment
mov ds,ax ;initialising

start:
lea dx,msg ;user prompt
mov ah,9
int 21h

xor cx,cx ;initializing cx
mov ah,1

input: ;this label for taking input

int 21h

cmp al,0Dh ;checking if the enter is pressed or not
JE end_input

;if left bracket,then push on stack
cmp al, "["
JE push_data
cmp al, "{"
JE push_data
cmp al, "("
JE push_data

;if right bracket,then pop stack

cmp al, ")"
JE parentheses
cmp al, "}"
JE curly_braces
cmp al, "]"
JE line_bracket
jmp input

push_data:
push ax
inc cx
jmp input

parentheses:
dec cx
cmp cx,0
JL many_right

pop dx
cmp dl, "("
JNE mismatch
JMP input

curly_braces:
dec cx
cmp cx,0
JL many_right
pop dx
cmp dl, "{"
JNE mismatch
JMP input

line_bracket:
dec cx
cmp cx, 0
JL many_right
pop dx
cmp dl, "["
JNE mismatch
JMP input

end_input:
cmp cx, 0
JNE many_left

mov ah, 9
lea dx, msg_correct
int 21h

lea dx, msg_continue
int 21h

mov ah,1
int 21h

cmp al, "Y"
JNE exit
JMP start

mismatch:
lea dx, msg_mismatch
mov ah,9
int 21h
JMP start

many_left:
lea dx, msg_left_bracket
mov ah,9
int 21h
JMP start

many_right:
lea dx, msg_right_bracket
mov ah,9
int 21h
JMP start

exit:
mov ah,4ch
int 21h

MAIN ENDP
END MAIN
[/code]

Difficulties & Discussion:
Since I have already solved this problem in C, I hadn’t face too much problem for the algorithm to solve this in assembly language. All dificulties I faced was in the syntax of Assembly language. At first,finishing the code,it wasn’t working for some inputs like (a+b)) or (a+b)} for which output will be “TOO MANY RIGHT BRACKETS”. But my code was being redirected to starting position of main procedure because of my silly mistake.Thsi mistake was in line number 83,94 and 104.

Wrong code
[code] pop dx
dec cx
cmp cx,0
JL many_right
cmp dl, "{"
JNE mismatch
JMP input[/code]
Corrected code:
[code]
dec cx
cmp cx,0
JL many_right
pop dx
cmp dl, "{"
JNE mismatch
JMP input

[/code]

For the example (a+b)}
When the last ‘}’ is scanned,then stack is empty.but in the code I have poped from stack,which is an invalid instruction. But actually it is required that,I will first check if the stack is empty or not.If empty,then “too many right brackets”. If not then pop dx and should be checked with the scanned data.It was done in the right side code.

This problem is an application of stack implementation and we have successfully solved this using stack in assembly language.