বুধবার, ৩০ মার্চ, ২০১১

Dynamic programming

For improving our programming knowledge,we learn different algorithm and then find the problem numbers of different online programming sites.
Here is 300 DP problems of Uva
300 DP Problems

সোমবার, ২৮ মার্চ, ২০১১

Big Number problem in JAVA in programming contest

Bignumber problem can be solved easily using BigInteger class in java.Here is a sample for doing this....

import java.math.BigInteger;

public class BIG
{
public static void main(String[] args)
{
//initialization
BigInteger N1 = new BigInteger ("1000000000000000000");
BigInteger N2 = new BigInteger ("123456789123");
BigInteger N3 = new BigInteger ("50000000000");
//Math operations
BigInteger mult = N1.multiply(N2); //This is how to send arguments in bigint functions
BigInteger add = N1.add(N2);
BigInteger div= N1.divide(N2);
BigInteger substract1 = N1.subtract(N2); //N1-N2
BigInteger substract2 = N2.subtract(N1); //N2-N1
BigInteger gcd = N1.gcd(N3);
//Printing output
System.out.println("Mult >>> " + mult);
System.out.println("add >>> " + add);
System.out.println("div >>> " + div);
System.out.println("substract1 >>> " + substract1);
System.out.println("substract2 >>> " + substract2);
System.out.println("gcd N1 N3 >>> " + gcd);
}
}

There are some more built in functions:

BigInteger.ONE; (==1)
BigInteger.ZERO;(==0)
A.abs();
A.add(N);
A.divide(N);
A.divideAndRemainder(N); (returns an array)
A.max(N);
A.min(N);
A.mod(N);
A.multiply(N);
A.remainder(N);
A.signum(N);

A.doubleValue();
A.floatValue();
A.intValue();
A.longValue();
A.toString();
A.compareTo(N)

converting an integer to bigint
BigInteger A = BigInteger.valueOf(20000);
You can take input using scanner just as you input int,long etc.


Reference:
BigInteger Class

রবিবার, ২৭ মার্চ, ২০১১

Converting .jar to .exe

Generally people try to,look for making the .exe of their application created by java.Actually I did the same and found that there is no need to convert our JAR files to .EXE .Because we know that JAVA is platform independent.But in .exe,this attribute will be lost.So,lets don't spoil our times to convert .jar to a .exe

To make a little bit clear sense,you can read this post,
convert-java-into-program-i-e-exe-file.html
how-convert-jar-file-into-exe-file.html





If you are not clear by now,then read this......
CREATING JAR FILES

শনিবার, ২৬ মার্চ, ২০১১

Sending mail from php

Today I am going to post a simple method to send mail from php code.To this we must use SMTP [Simple Mail Transfer protocol]which uses default port that is 25.Before sending mail,SMTP server name must be included in php.ini .To make our job easier I will use three php files.
They are
01: SMTPconfig.php
02: SMTPclass.php
03: index.php


01: SMTPconfig.php

//Server Address
$SmtpServer="gmail.com";
$SmtpPort="25"; //default
$SmtpUser="yourgmailid@gmail.com";
$SmtpPass="yourgmailpassword";


Here,SMTP server setup is completed.



02: SMTPclass.php


class SMTPClient
{

function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)
{

$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;

if ($SmtpPort == "")
{
$this->PortSMTP = 25;
}
else
{
$this->PortSMTP = $SmtpPort;
}
}

function SendMail ()
{
if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
{
fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n");
$talk["hello"] = fgets ( $SMTPIN, 1024 );
fputs($SMTPIN, "auth login\r\n");
$talk["res"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpUser."\r\n");
$talk["user"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpPass."\r\n");
$talk["pass"]=fgets($SMTPIN,256);
fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n");
$talk["From"] = fgets ( $SMTPIN, 1024 );
fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n");
$talk["To"] = fgets ($SMTPIN, 1024);
fputs($SMTPIN, "DATA\r\n");
$talk["data"]=fgets( $SMTPIN,1024 );
fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n");
$talk["send"]=fgets($SMTPIN,256);
//CLOSE CONNECTION AND EXIT ...
fputs ($SMTPIN, "QUIT\r\n");
fclose($SMTPIN);
//
}
return $talk;
}
}
/////////////////////////////////



03: index.php


include('SMTPconfig.php');
include('SMTPClass.php');
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$to = "to_mailid";
$from = "from_mailid";
$subject = "subject";
$body = "message";
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
}


Thanks for visiting this...
to be more clear Click here

বৃহস্পতিবার, ২৪ মার্চ, ২০১১

মঙ্গলবার, ২২ মার্চ, ২০১১

শুক্রবার, ১৮ মার্চ, ২০১১

Codeforces

to be a good programmer, we must attend programming contest.A contest is going to be held at 10 P.M.(Bangladesh) in 18th March,2011.
visit this to register

And a contest will be held on tomorrow at

সোমবার, ১৪ মার্চ, ২০১১

sql with java part 2

We must download a mysql-connector-java-5.0.8-bin.jar and keep it to
C:\Program Files\Java\jdk1.6.0_01\jre\lib\ext\



In java programming, before coding we must established a connection between editor and MySQL.

at first we must import some built in packages.they are:

import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Connection;


now finally in our main job

Connection m_Connection = null;
Statement m_Statement = null;
ResultSet m_ResultSet = null;

String m_Driver ="com.mysql.jdbc.Driver";
String m_Url = "jdbc:mysql://localhost:3306/databasename";

//Loading driver
try {
Class.forName(m_Driver);
}
catch (ClassNotFoundException ex) {
ex.printStackTrace();
}


String query = "";
try {

//Create connection object
m_Connection = DriverManager.getConnection(m_Url, user, password);

//Create Statement object
m_Statement = m_Connection.createStatement();
query = "SELECT * FROM ";
query+=tablename;

//Execute the query
m_ResultSet = m_Statement.executeQuery(query);
String s,t="";

//Loop through the results
while (m_ResultSet.next()) {

s=m_ResultSet.getString(1); //here 1 means value of first coloumn


}//end for while loop


}
catch (SQLException ex) {
ex.printStackTrace();
System.out.println(query);

}
catch (Exception e) {
System.err.println("Error: " + e.getMessage());

}


finally {

try {
if (m_ResultSet != null)
m_ResultSet.close();
if (m_Statement != null)
m_Statement.close();
if (m_Connection != null)
m_Connection.close();
}
catch (SQLException ex) {
ex.printStackTrace();
}
}







thanks for being with me

sql with java

Sometimes we need to use database(MySQL).So,we must connect our interpreter to the existing MySQl.For this we need JDBC driver to install it.In netbeans IDE jdbc driver is built in.But to make this working, we must have a mysql connector,which is a jar file in our system. In the next post ,A sample example will be given....

thanks for being with me....

রবিবার, ১৩ মার্চ, ২০১১

JAVA [creating Jar files]

to create a jar file execute this command given below
jar cf jar-file input-file(s)

For more you can see this Creating JAR files


After creation you must specify the main class using menifest.

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]

then I have executed command given below
updating e jar file with main class

jar umf aaa.txt calender.jar
jar xvf calender.jar
type META-INF\MANIFEST.MF