Official Site

click here to view our new site launched

Pages

Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Wednesday, January 11, 2012

FLAMES- IN JAVA APPLET

Hi all its curious to know about relationship and its fun to play with flames..
here i written code for finding the result in a single click...no need to compute in a paper to find..
Click here to Play with FLAMES.

copy the files to a directory say c:/
go to Command prompt
change directory to c:\
Type the following

cd c:\
appletviewer flames.java

Download the files given below...
Click here to download flames.java
Click here to download flames.class

or
if u want to simply view applet in a browser instead of command prompt open the following webpage.
Note:Your browser must have JRE.

Click here to see Demo

Tuesday, April 19, 2011

MYSQL connectivity Java

// java bean for database connection to MySQL

package db;
import java.sql.*;

public class DbConnect {

private Connection conn = null;

public Connection OracleConnect() {
try {

Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
System.out.println("connected");
//return conn;
} catch (Exception e) {
//in case no password error catching error and try again.
try{
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
}
catch (Exception ee) {
System.out.println("Error in Database Connection2"+ee.getMessage());
}

System.out.println("Error in Database Connection1"+e.getMessage());
}
finally{
return (conn);
}
}

protected void CloseConnection() {
try {
conn.close();
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
}



Friday, February 4, 2011

Send Mail in Java


package mail;

import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class SendMail {
String MAIL_SERVER = "smtp.gmail.com";


public void Sendmail(String USERNAME,String PASSWORD,String fromAddress,String toAddress,String subject,String message) {
try {

Properties properties = System.getProperties();
properties.put("mail.smtps.host", MAIL_SERVER);
properties.put("mail.smtps.auth", "true");

Session session = Session.getInstance(properties);
MimeMessage msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(fromAddress));
msg.addRecipients(Message.RecipientType.TO, toAddress);
msg.setSubject(subject);
msg.setText(message);

Transport tr = session.getTransport("smtps");
tr.connect(MAIL_SERVER, USERNAME, PASSWORD);
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();
} catch (AddressException ex) {
System.out.println(ex.getMessage());
}
catch (MessagingException ex) {
System.out.println(ex.getMessage());
}

}



public static void main(String[] args){

String USERNAME="xxxx@gmail.com";
String PASSWORD="your password";
String fromAddress="xxx@gmail.com";
String toAddress="toaddress";
String subject="your subject";
String message="your message";

s.Sendmail(USERNAME, PASSWORD, fromAddress, toAddress, subject, message);

}


}



click here to download mail.jar and SendMail Java bean

Thursday, August 19, 2010

Simple Encryptor

" An encryptor converts meaningful information into gibbrish form so that it is safe from the eyes of unauthorized people "
import javax.swing.*;
import java.io.*;
public class encrypt
{
public static void main(String arg[]) throws FileNotFoundException, IOException
{
String choice = JOptionPane.showInputDialog("Encrypt(E)/Decrypt(D)");
String file= JOptionPane.showInputDialog("File Name:");
File usrfile = new File(file);
File encfile = new File("enc.txt");
encfile.createNewFile();
BufferedWriter userStream = new BufferedWriter( new FileWriter(encfile));
try
{
PushbackReader in = new PushbackReader( new BufferedReader ( new FileReader(usrfile)));
int c=-4,i=0,temp=0;
while(c!=-1)
{
c=in.read();
temp=c;
if(c==-1)break;
if(choice.equals("e")||choice.equals("E"))
{
if(temp%2==0)temp+=9;
else temp-=7;
}
else if(choice.equals("d")||choice.equals("D"))
{
if(temp%2!=0)temp-=9;
else temp+=7;
}
userStream.write(String.valueOf((char)temp));
}
in.close();
userStream.close();
usrfile.delete();
File usrfile2 = new File(file);
encfile.renameTo(usrfile2);
}
catch(IOException e)
{
JOptionPane.showMessageDialog(null,e);
}
System.exit(0);
}
}
Execute the above program.
Encrypt(E)/Decrypt(D)
enc2
File Name:
enc3
Sample File
en1
Encrypted File
enc4
To get back the non-gibberish form or decrypted text, execute the code once again and enter d in the first window and file name in the following window.
Note:
  • This code can be used to encrypt/decrypt only files encoded in Text Format
  • The file to be encrypted has to be in the same folder from which the code is executed.
  • Sound knowledge of Java is required to understand and successfully execute the above code.
$2.49 .COM at GoDaddy.com! Expires 5/14/13