Tuesday, December 6, 2011
Sunday, July 17, 2011
How to setup development environment for Android
Follow the steps given below to setup Android development environment.
Step1. Download Eclipse from http://www.eclipse.org/downloads/packages/release/galileo/r
Step2. Download Android SDK from http://developer.android.com/sdk/index.html
Step3. Download Android Development Tool (ADT) from here
Step1. Download Eclipse from http://www.eclipse.org/downloads/packages/release/galileo/r
Step2. Download Android SDK from http://developer.android.com/sdk/index.html
Step3. Download Android Development Tool (ADT) from here
Friday, June 17, 2011
How to setup a Android development environment with eclipse
Follow the instructions given below.
1.Download Eclipse IDE
First step is to download Eclipse IDE from http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/ganymedesr2. We need this software to use as a development environment for Android.
2.Download Google Android SDK
We need to download Google Android Software Development Kit for development. Go to http://code.google.com/android/download.html, read and agree to the license and click the "continue" button. Choose the platform that you are currently running on. Once downloaded, locate the archive file and extract or expand it to a location that you will remember. Note the location, as you will need to enter this directory into Eclipse in a moment.
2.Configuring add-on in Eclipse
Start the Eclipse from installation directory.
1.Download Eclipse IDE
First step is to download Eclipse IDE from http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/ganymedesr2. We need this software to use as a development environment for Android.
2.Download Google Android SDK
We need to download Google Android Software Development Kit for development. Go to http://code.google.com/android/download.html, read and agree to the license and click the "continue" button. Choose the platform that you are currently running on. Once downloaded, locate the archive file and extract or expand it to a location that you will remember. Note the location, as you will need to enter this directory into Eclipse in a moment.
2.Configuring add-on in Eclipse
Start the Eclipse from installation directory.
Wednesday, May 11, 2011
Using AES ( CBC ) Encryption in java with Client Server
//File : DesServer.java //DesReceiver //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import java.net.*; import java.util.*; import java.math.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class DesServer { public static void main(String []str)throws Exception { ServerSocket ss = new ServerSocket(5656); Socket s = null; InputStream is = null; ObjectInputStream ois = null; Frame f =null; while(true) { s=ss.accept(); is = s.getInputStream(); ois = new ObjectInputStream(is); f = (Frame)ois.readObject(); System.out.println(decryptString(f.data,f.k,new IvParameterSpec(f.iv))); break; } ois.close(); is.close(); s.close(); ss.close(); } static String decryptString(String data,Key key,IvParameterSpec ivspec)throws Exception { KeyGenerator kg = KeyGenerator.getInstance("DES"); kg.init(56); Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding"); Key k = key; c.init(Cipher.DECRYPT_MODE,new SecretKeySpec("12345678".getBytes(),"DES"),ivspec); byte[] plaintext = c.doFinal(data.getBytes()); return new String(plaintext); } } /******************************************************************/ //File : DesClient.java //DesClient //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import java.net.*; import java.util.*; import java.math.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class DesClient { static KeyGenerator kg = null; static Cipher c = null; static Key k = null; static byte[] ivector=null; public static void main(String []str) { String datatosend=null; try { datatosend = encryptString(getDataFromFile("Data.txt")); Frame f = new Frame(datatosend,k,ivector); sendFrame("localhost",5656,f); } catch(Exception e) { System.out.println(e); } } static String getDataFromFile(String filename) throws Exception { String str=""; Scanner sc = new Scanner(new File(filename)); while(sc.hasNextLine()) { str=str + sc.nextLine(); } sc.close(); return str; } static String encryptString(String data) throws Exception { kg = KeyGenerator.getInstance("DES"); kg.init(56); c = Cipher.getInstance("DES/CBC/PKCS5Padding"); k = kg.generateKey(); c.init(Cipher.ENCRYPT_MODE,new SecretKeySpec("12345678".getBytes(),"DES")); byte[] plaintext = data.getBytes(); byte[] ciphertext = c.doFinal(plaintext); ivector = c.getIV(); return new String(ciphertext); } static void sendFrame(String remoteaddress,int port,Frame f) throws Exception { Socket s = new Socket(remoteaddress,port); OutputStream os = s.getOutputStream(); ObjectOutputStream ous = new ObjectOutputStream(os); ous.writeObject(f); ous.close(); os.close(); s.close(); } } /***********************************************************/ //File : Frame.java //Frame Class //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import java.net.*; import java.util.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class Frame implements Serializable { String data; Key k; byte[] iv; Frame(String mydata,Key key,byte[] ivector) { data=mydata; k = key; if(ivector==null) { iv = null; } else { iv = new byte[ivector.length]; for(int i=0;i<ivector.length;i++) { iv[i]=ivector[i]; } } } }
Browsing gmail using secure connection
Follow the simple steps given below :
Step 1 : Click on Settings option situated at top right corner of screen.
Step 2 : In General tab look for 5th option "Browser connection".
Step 3 : Click on Always use https option.
Step 4 : Save changes
After completing procedure you will see https://www.gmail.com instead of http://www.gmail.com. This indicates that you are browsing gmail on secure connection. It makes your connection encrypted by using SSL/TLS protocols so protects you from the eavesdropping and intercepting your data by someone for malicious purpose.
You can also enable secure browsing in facebook. Read how to make facebook connection secure here
Step 1 : Click on Settings option situated at top right corner of screen.
Step 2 : In General tab look for 5th option "Browser connection".
Step 3 : Click on Always use https option.
Step 4 : Save changes
After completing procedure you will see https://www.gmail.com instead of http://www.gmail.com. This indicates that you are browsing gmail on secure connection. It makes your connection encrypted by using SSL/TLS protocols so protects you from the eavesdropping and intercepting your data by someone for malicious purpose.
You can also enable secure browsing in facebook. Read how to make facebook connection secure here
Tuesday, May 10, 2011
Using AES ( CFB ) Encryption in java with Client Server
//File : AesClient.java //AesClient //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import java.net.*; import java.util.*; import java.math.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class AesClient { static KeyGenerator kg = null; static Cipher c = null; static Key k = null; static byte[] ivector=null; public static void main(String []str) { String datatosend=null; try { datatosend = encryptString(getDataFromFile("Data.txt")); Frame f = new Frame(datatosend,k,ivector); sendFrame("localhost",5656,f); } catch(Exception e) { System.out.println(e); } } static String getDataFromFile(String filename) throws Exception { String str=""; Scanner sc = new Scanner(new File(filename)); while(sc.hasNextLine()) { str=str + sc.nextLine(); } sc.close(); return str; } static String encryptString(String data) throws Exception { kg = KeyGenerator.getInstance("AES"); //kg.init(128); c = Cipher.getInstance("AES/CFB/PKCS5Padding"); k = kg.generateKey(); c.init(Cipher.ENCRYPT_MODE,new SecretKeySpec("1234512345123451".getBytes(),"AES")); byte[] plaintext = data.getBytes(); byte[] ciphertext = c.doFinal(plaintext); ivector = c.getIV(); return new String(ciphertext); } static void sendFrame(String remoteaddress,int port,Frame f) throws Exception { Socket s = new Socket(remoteaddress,port); OutputStream os = s.getOutputStream(); ObjectOutputStream ous = new ObjectOutputStream(os); ous.writeObject(f); ous.close(); os.close(); s.close(); } } /***************************************************************************/ //File : AesServer.java //AESReceiver //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import java.net.*; import java.util.*; import java.math.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class AesServer { public static void main(String []str)throws Exception { ServerSocket ss = new ServerSocket(5656); Socket s = null; InputStream is = null; ObjectInputStream ois = null; Frame f =null; while(true) { s=ss.accept(); is = s.getInputStream(); ois = new ObjectInputStream(is); f = (Frame)ois.readObject(); System.out.println(decryptString(f.data,f.k,new IvParameterSpec(f.iv))); break; } ois.close(); is.close(); s.close(); ss.close(); } static String decryptString(String data,Key key,IvParameterSpec ivspec)throws Exception { KeyGenerator kg = KeyGenerator.getInstance("AES"); //kg.init(128); Cipher c = Cipher.getInstance("AES/CFB/PKCS5Padding"); Key k = key; c.init(Cipher.DECRYPT_MODE,new SecretKeySpec("1234512345123451".getBytes(),"AES"),ivspec); byte[] plaintext = c.doFinal(data.getBytes()); return new String(plaintext); } } /*************************************************************************/ //File : Frame.java //Frame Class //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import java.net.*; import java.util.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class Frame implements Serializable { String data; Key k; byte[] iv; Frame(String mydata,Key key,byte[] ivector) { data=mydata; k = key; if(ivector==null) { iv = null; } else { iv = new byte[ivector.length]; for(int i=0;i<ivector.length;i++) { iv[i]=ivector[i]; } } } }
Browsing facebook using secure connection and Login Notification system
Follow the steps given below to browse facebook using secure connection.
Step 1 : Click on Account menu at the top right corner.
Step 2 : In that click Account Settings option.
Step 3 : On the settings tab click on Account Security option
Step 4 : Check "Browse Facebook on a secure connection (https) whenever possible" box.
Click on Save and you are done.
After completing procedure you will see https://www.facebook.com instead of http://www.facebook.com. This indicates that you are browsing facebook on secure connection. It makes your connection encrypted by using SSL/TLS protocols so protects you from the eavesdropping and intercepting your data by someone for malicious purpose.
The other option is of Login Notifications .
It will notify you when you try to log in to your facebook account using different computer/IP address.
There are two notification options.
1.Send me an Email
When you try to log in using different computer/IP address, facebook will notify you about your log in attempt by sending you an email
2.Send me a text message
When you try to log in using different computer/IP address, facebook will notify you about your log in attempt by sending you a text message on mobile no you have specified in your facebook account.
You can also enable secure browsing in Gmail. Read how to make facebook connection secure here
Step 1 : Click on Account menu at the top right corner.
Step 2 : In that click Account Settings option.
Step 3 : On the settings tab click on Account Security option
Step 4 : Check "Browse Facebook on a secure connection (https) whenever possible" box.
Click on Save and you are done.
After completing procedure you will see https://www.facebook.com instead of http://www.facebook.com. This indicates that you are browsing facebook on secure connection. It makes your connection encrypted by using SSL/TLS protocols so protects you from the eavesdropping and intercepting your data by someone for malicious purpose.
The other option is of Login Notifications .
It will notify you when you try to log in to your facebook account using different computer/IP address.
There are two notification options.
1.Send me an Email
When you try to log in using different computer/IP address, facebook will notify you about your log in attempt by sending you an email
2.Send me a text message
When you try to log in using different computer/IP address, facebook will notify you about your log in attempt by sending you a text message on mobile no you have specified in your facebook account.
You can also enable secure browsing in Gmail. Read how to make facebook connection secure here
Using AES ( ECB ) Encryption in java with Client Server
//File : AESClient.java //AESClient //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import java.net.*; import java.util.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class AESClient { static KeyGenerator kg = null; static Cipher c = null; static Key k = null; public static void main(String []str) { String datatosend=null; try { datatosend = encryptString(getDataFromFile("Data.txt")); Frame f = new Frame(datatosend,k); sendFrame("localhost",5656,f); } catch(Exception e) { System.out.println(e); } } static String getDataFromFile(String filename) throws Exception { String str=""; Scanner sc = new Scanner(new File(filename)); while(sc.hasNextLine()) { str=str + sc.nextLine(); } sc.close(); return str; } static String encryptString(String data) throws Exception { kg = KeyGenerator.getInstance("AES"); c = Cipher.getInstance("AES"); k = kg.generateKey(); c.init(Cipher.ENCRYPT_MODE,k); byte[] plaintext = data.getBytes(); byte[] ciphertext = c.doFinal(plaintext); return new String(ciphertext); } static void sendFrame(String remoteaddress,int port,Frame f) throws Exception { Socket s = new Socket(remoteaddress,port); OutputStream os = s.getOutputStream(); ObjectOutputStream ous = new ObjectOutputStream(os); ous.writeObject(f); ous.close(); os.close(); s.close(); } } /********************************************************************/ //File : AESServer.java //AESServer //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import java.net.*; import java.util.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class AESServer { public static void main(String []str)throws Exception { ServerSocket ss = new ServerSocket(5656); Socket s = null; InputStream is = null; ObjectInputStream ois = null; Frame f =null; while(true) { s=ss.accept(); is = s.getInputStream(); ois = new ObjectInputStream(is); f = (Frame)ois.readObject(); System.out.println(decryptString(f.data,f.k)); break; } ois.close(); is.close(); s.close(); ss.close(); } static String decryptString(String data,Key key)throws Exception { KeyGenerator kg = KeyGenerator.getInstance("AES"); Cipher c = Cipher.getInstance("AES"); Key k = key; c.init(Cipher.DECRYPT_MODE,k); byte[] plaintext = c.doFinal(data.getBytes()); return new String(plaintext); } } /*****************************************************/ //File : Frame.java //Frame Class //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import java.net.*; import java.util.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class Frame implements Serializable { String data; Key k; Frame(String mydata,Key key) { data=mydata; k = key; } }
Using AES ( CBC ) Encryption in java with Client Server
//File : AesClient.java //AesClient //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import java.net.*; import java.util.*; import java.math.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class AesClient { static KeyGenerator kg = null; static Cipher c = null; static Key k = null; static byte[] ivector=null; public static void main(String []str) { String datatosend=null; try { datatosend = encryptString(getDataFromFile("Data.txt")); Frame f = new Frame(datatosend,k,ivector); sendFrame("localhost",5656,f); } catch(Exception e) { System.out.println(e); } } static String getDataFromFile(String filename) throws Exception { String str=""; Scanner sc = new Scanner(new File(filename)); while(sc.hasNextLine()) { str=str + sc.nextLine(); } sc.close(); return str; } static String encryptString(String data) throws Exception { kg = KeyGenerator.getInstance("AES"); kg.init(128); c = Cipher.getInstance("AES/CBC/PKCS5Padding"); k = kg.generateKey(); c.init(Cipher.ENCRYPT_MODE,new SecretKeySpec("1234512345123451".getBytes(),"AES")); byte[] plaintext = data.getBytes(); byte[] ciphertext = c.doFinal(plaintext); ivector = c.getIV(); return new String(ciphertext); } static void sendFrame(String remoteaddress,int port,Frame f) throws Exception { Socket s = new Socket(remoteaddress,port); OutputStream os = s.getOutputStream(); ObjectOutputStream ous = new ObjectOutputStream(os); ous.writeObject(f); ous.close(); os.close(); s.close(); } } /*******************************************************************/ //File : AesServer.java //AESReceiver //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import java.net.*; import java.util.*; import java.math.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class AesServer { public static void main(String []str)throws Exception { ServerSocket ss = new ServerSocket(5656); Socket s = null; InputStream is = null; ObjectInputStream ois = null; Frame f =null; while(true) { s=ss.accept(); is = s.getInputStream(); ois = new ObjectInputStream(is); f = (Frame)ois.readObject(); System.out.println(decryptString(f.data,f.k,new IvParameterSpec(f.iv))); break; } ois.close(); is.close(); s.close(); ss.close(); } static String decryptString(String data,Key key,IvParameterSpec ivspec)throws Exception { KeyGenerator kg = KeyGenerator.getInstance("AES"); kg.init(128); Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding"); Key k = key; c.init(Cipher.DECRYPT_MODE,new SecretKeySpec("1234512345123451".getBytes(),"AES"),ivspec); byte[] plaintext = c.doFinal(data.getBytes()); return new String(plaintext); } } /********************************************************************/ //File : Frame.java //Frame Class //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import java.net.*; import java.util.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class Frame implements Serializable { String data; Key k; byte[] iv; Frame(String mydata,Key key,byte[] ivector) { data=mydata; k = key; if(ivector==null) { iv = null; } else { iv = new byte[ivector.length]; for(int i=0;i<ivector.length;i++) { iv[i]=ivector[i]; } } } }
Using AES ( CFB8 ) Encryption in java with Client Server
//File : AesServer.java //AESReceiver //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import java.net.*; import java.util.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class AesServer { public static void main(String []str)throws Exception { ServerSocket ss = new ServerSocket(5656); Socket s = null; InputStream is = null; ObjectInputStream ois = null; Frame f =null; while(true) { s=ss.accept(); is = s.getInputStream(); ois = new ObjectInputStream(is); f = (Frame)ois.readObject(); System.out.println(decryptString(f.data,f.k,new IvParameterSpec(f.iv))); break; } ois.close(); is.close(); s.close(); ss.close(); } static String decryptString(String data,Key key,IvParameterSpec ivspec)throws Exception { KeyGenerator kg = KeyGenerator.getInstance("AES"); Cipher c = Cipher.getInstance("AES/CFB8/PKCS5Padding"); Key k = key; c.init(Cipher.DECRYPT_MODE,k,ivspec); byte[] plaintext = c.doFinal(data.getBytes()); return new String(plaintext); } } /***************************************************************************/ //File : AesClient.java //AESClient //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import java.net.*; import java.util.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class AesClient { static KeyGenerator kg = null; static Cipher c = null; static Key k = null; static byte[] ivector=null; public static void main(String []str) { String datatosend=null; try { datatosend = encryptString(getDataFromFile("Data.txt")); Frame f = new Frame(datatosend,k,ivector); sendFrame("localhost",5656,f); } catch(Exception e) { System.out.println(e); } } static String getDataFromFile(String filename) throws Exception { String str=""; Scanner sc = new Scanner(new File(filename)); while(sc.hasNextLine()) { str=str + sc.nextLine(); } sc.close(); return str; } static String encryptString(String data) throws Exception { kg = KeyGenerator.getInstance("AES"); kg.init(128); c = Cipher.getInstance("AES/CFB8/PKCS5Padding"); k = kg.generateKey(); c.init(Cipher.ENCRYPT_MODE,k); byte[] plaintext = data.getBytes(); byte[] ciphertext = c.doFinal(plaintext); ivector = c.getIV(); return new String(ciphertext); } static void sendFrame(String remoteaddress,int port,Frame f) throws Exception { Socket s = new Socket(remoteaddress,port); OutputStream os = s.getOutputStream(); ObjectOutputStream ous = new ObjectOutputStream(os); ous.writeObject(f); ous.close(); os.close(); s.close(); } } /*****************************************************************************/ //File : Frame.java //Frame Class //Developed by Malhar Vora //Developed on : 9-5-2011 import java.io.*; import javax.crypto.*; import java.security.*; import javax.crypto.spec.*; public class Frame implements Serializable { String data; Key k; byte[] iv; Frame(String mydata,Key key,byte[] ivector) { data=mydata; k = key; if(ivector==null) { iv = null; } else { iv = new byte[ivector.length]; for(int i=0;i<ivector.length;i++) { iv[i]=ivector[i]; } } } }
Tuesday, May 3, 2011
Osama Dead - Censored Video Leaked Scam on facebook
Today morning i saw link on my facebook wall shared by one of my friend.The text was "Osama Dead - Censored Video Leaked" . This link was one of the very recent facebook scam. The scammers have used the reference toWikileaks to show link genuine to viewer.
By Clicking on the link had taken me to the fan page and asked me to complete 5 steps. Completing 5 steps did nothing but posted same link on my friends wall to spread itself.
The page was something like given below.
By Clicking on the link had taken me to the fan page and asked me to complete 5 steps. Completing 5 steps did nothing but posted same link on my friends wall to spread itself.
The page was something like given below.
Precautions should be taken before clicking on any link that seems suspicious to you because that link can redirect you to a page which is used to steal your using a social engineering attack.
Sunday, April 17, 2011
Saturday, April 16, 2011
Sunday, March 20, 2011
Friday, February 25, 2011
Using IMDb api to get details of movie from Java application
The Internet Movie Database (IMDb) is an online database of information related to movies, television shows, actors, production crew personnel, video games and fictional characters featured in visual entertainment media by Amazon.com. IMDbdoes not provide any api but some websites on the internet provides api which can be used to access IMDb database. One of the such website is http://www.deanclatworthy.com/imdb/.
Here a simple Java application shows how to access these apis. You can visit http://www.deanclatworthy.com/imdb/ for more information about api.
Here a simple Java application shows how to access these apis. You can visit http://www.deanclatworthy.com/imdb/ for more information about api.
/********************************************************************************* Program to demonstrate how to use IMDB api to get details about any movie Developed by : Malhar Vora Developed on : 25-02-2011 Development Status : Completed and tested Email : vbmade2000@gmail.com WebSite : http://malhar2010.blogspot.com **********************************************************************************/ import java.io.*; import java.net.*; import java.util.*; public class IMDBDemo{ public static void main(String []str){ URL url = null; Scanner sc = null; String apiurl="http://www.deanclatworthy.com/imdb/"; String moviename=null; String dataurl=null; String retdata=null; InputStream is = null; DataInputStream dis = null; try{ //Getting movie name from user sc = new Scanner(System.in); moviename=sc.nextLine(); //Check if user has inputted nothing or blank if(moviename==null || moviename.equals("")){ System.out.println("No movie found"); System.exit(1); } //Remove unwanted space from moviename yb trimming it moviename=moviename.trim(); //Replacing white spaces with + sign as white spaces are not allowed in IMDB api moviename=moviename.replace(" ","+"); //Forming a complete url ready to send (type parameter can be JSON also) dataurl=apiurl+"?q="+moviename + "&type=text"; System.out.println("Getting data from service"); System.out.println("########################################"); url = new URL(dataurl); is = url.openStream(); dis = new DataInputStream(is); String details[]; //Reading data from url while((retdata = dis.readLine())!=null){ //Indicates that movie does not exist in IMDB databse if(retdata.equals("error|Film not found")){ System.out.println("No such movie found"); break; } //Replacing | character with # character for spliting retdata=retdata.replace("|","#"); //Splitting up string by # character and storing output in details array details=retdata.split("#"); //details[0] contains name of detail. e.g title,genre etc System.out.print(details[0].toUpperCase() + " -> "); //details[1] contains value of detail. e.g The Cave System.out.print(details[1]); System.out.println(); } } catch(Exception e){ System.out.println(e); } finally{ try{ if(dis!=null){ dis.close(); } if(is!=null){ is.close(); } if(sc!=null){ sc.close(); } } catch(Exception e2){ ; } } } }
Wednesday, February 23, 2011
Simple interest calculator using Servlets ( Practical : 23, MCA, Sem : 4, GTU Programs )
Download simple interest calculator developed using Servlet and html.
Click here to download
Click here to download
Sunday, February 6, 2011
Using Rapidshare.com api to check file status on rapidshare.com
/********************************************************************************* Program to demonstrate how to that file exist on rapidshare.com server using api provided by rapidshare.com Developed by : Malhar Vora Developed on : 6-1-2011 Development Status : Completed Email : vbmade2000@gmail.com WebSite : http://malhar2010.blogspot.com **********************************************************************************/ import java.net.*; import java.io.*; import java.util.*; public class RapidChecker { public static void main(String []str) { URL u=null; String temp[]; Scanner sc = null; String strurl=null; try{ sc = new Scanner(System.in); System.out.println("Enter rapidshare url to check :"); strurl = sc.nextLine(); u = new URL(strurl); //Getting fileid and filename by splaitting string into parts temp = u.getFile().split("/"); //Calling function to check file status checkRapidShareFile(Integer.parseInt(temp[2].trim()),temp[3]); } catch(Exception e) { System.out.println("Error in checking file"); } } static void checkRapidShareFile(int file,String filename) { URL u = null; InputStream is = null; DataInputStream dis = null; String s=null,url=null; String data[]; try { url = "http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=checkfiles&files=" +file + "&filenames=" + filename; u = new URL(url); is = u.openStream(); dis = new DataInputStream(is); s=dis.readLine(); data = s.split(","); System.out.println(data[4]); if(data[4].equals("0")) { System.out.println("File not found"); } else if(data[4].equals("1")) { System.out.println("File found"); } else if(data[4].equals("3")) { System.out.println("Server down"); } else if(data[4].equals("4")) { System.out.println("File is illegal"); } else if(data[4].equals("5")) { System.out.println("File is locked because 10 download is already done"); } else { System.out.println("Undefined response"); } } catch(Exception e) { System.out.print(e); } finally { try { dis.close(); is.close(); } catch(Exception e2) { System.out.print("Error in closing streams"); } } } }
Saturday, February 5, 2011
Connect MS Access database using Type - I JDBC driver
import java.sql.*; /********************************************************************************* Program to demonstrate connection to MS Access database using JDBC driver Type - I Developed by : Malhar Vora Developed on : 6-1-2011 Development Status : Completed Email : vbmade2000@gmail.com WebSite : http://malhar2010.blogspot.com **********************************************************************************/ public class dbcon { public static void main(String[] args) { Connection conn=null; Statement st=null; ResultSet rs=null; try { Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); } catch (Exception E) { System.err.println ("Unable to load driver."); E.printStackTrace (); } try { String db = "jdbc:odbc:db1"; conn = DriverManager.getConnection (db, "",""); st = conn.createStatement(); rs = st.executeQuery("Select * from emp"); while(rs.next()) { System.out.println(rs.getString(1)); } System.out.println ("*** Connected to the database ***"); } catch (SQLException E) { System.out.println ("SQLException: " + E.getMessage()); System.out.println ("SQLState: " + E.getSQLState()); System.out.println ("VendorError: " + E.getErrorCode()); } try { st.close(); if(conn!=null) { conn.close (); } } catch (SQLException E) { System.err.println ("Unable to load driver."); E.printStackTrace (); } } }
Sunday, January 16, 2011
Using Hashtable in Java
import java.util.Hashtable; import java.util.Enumeration; public class HTDemo{ public static void main(String []str){ //Creating new Hatshtable Hashtable ht = new Hashtable(); //Adding objects of Entry class to Hashtable ht.put("Emma Watson",new Entry("Emma Watson","9741631235")); ht.put("Hugh Jackman",new Entry("Hugh Jackman","7353421215")); ht.put("Eric Bana",new Entry("Eric Bana","9471164719")); ht.put("Steve Jobs",new Entry("Steve Jobs","9132135451")); //Enumerating elements of Hashtable displayElements(ht); ht.remove("Eric Bana"); System.out.println("===============After removal=============="); displayElements(ht); } static void displayElements(Hashtable htable){ Enumeration e = htable.keys(); String key; Entry ent; while(e.hasMoreElements()){ key = (String)e.nextElement(); ent = (Entry)htable.get(key); System.out.println("Name -> " + ent.getName()); System.out.println("Phone -> " + ent.getPhone()); System.out.println("-------------------------------"); } } } class Entry{ private String name; private String phone; Entry(){ name=""; phone=""; } Entry(String nm,String pn){ this.name = nm; this.phone = pn; } String getName(){ return this.name; } String getPhone(){ return this.phone; } void setName(String nm){ this.name = nm; } void setPhone(String pn){ this.phone = pn; } }
Subscribe to:
Posts (Atom)