Posts

Showing posts from May, 2015

Steps to crearte facebook application at Facebook Developers Page.

Image
For login with facebook to work we have to create a facebook application at Facebook Developers Page using following steps, 1. Login to Facebook Developers Page . 2. Goto " My Apps " menu. 3. Click " Add a New App " option. 4. In popup select " WWW " symbol which represent website login. 5. Then give a application name in provided text field. 6. Click " Create New Facebook App ID " button 7. In next screen choose " Category " of your application. 8. Then click " Create App ID " button. 9. Then on next screen give your site URL. For development purpose use http://localhost:<port number>

Create a pdf file using java and encrypt / decrypt it.

For this example to work you will need following jar files. 1.  bcpkix-jdk15on-1.47.jar 2.   itextpdf-5.1.0.jar 3.   bcprov-jdk14-146.jar Download them and include them in your project classpath . /* * This class is part of the book "iText in Action - 2nd Edition" * written by Bruno Lowagie (ISBN: 9781935182610) * For more info, go to: http://itextpdf.com/examples/ * This example only works with the AGPL version of iText. */ import java.io.FileOutputStream; import java.io.IOException; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.PdfStamper; public class EncryptionPdf { /** User password. */ public static byte[] USER = "Hello".getBytes(); /** Owner password. */ public static byte[] OWNER = "World".getBytes

How to refresh JSP page automatically after each time period?

<%@ page import="java.io.*,java.text.*,java.util.*"%> <html> <head> <title>Auto Refresh Header Example</title> </head> <body> <h2>Auto Refresh Header Example</h2> <% // Page will be auto refresh after 1 second response.setIntHeader("Refresh", 1); // Get Current Time DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Calendar cal = Calendar.getInstance(); out.println(dateFormat.format(cal.getTime())); %> </body> </html>

Login with Facebook example.

Below is the code for logging our application using Facebook. Note: Please change appId : ' 45366235237356756 ' with your Facebook application ID. <div id="fb-root"></div> <script> //Load the Facebook JS SDK (function(d) { var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; if (d.getElementById(id)) { return; } js = d.createElement('script'); js.id = id; js.async = true; js.src = "http://connect.facebook.net/en_US/all.js"; ref.parentNode.insertBefore(js, ref); }(document)); // Init the SDK upon load window.fbAsyncInit = function() { FB.init({ appId : ' 45366235237356756 ', // App ID status : true, // check login status cookie : true, // enable cookie

How to convert 24 hr format time in to 12 hr Format?

Here is the code to convert 24-Hour time to 12-Hour with AM and PM. If you don't want AM/PM then just replace hh:mm a with hh:mm. import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String [] args) throws Exception { try { String _24HourTime = "22:15"; SimpleDateFormat _24HourSDF = new SimpleDateFormat("HH:mm"); SimpleDateFormat _12HourSDF = new SimpleDateFormat("hh:mm a"); Date _24HourDt = _24HourSDF.parse(_24HourTime); System.out.println(_24HourDt); System.out.println(_12HourSDF.format(_24HourDt)); } catch (Exception e) { e.printStackTrace(); } } } Output: Thu Jan 01 22:15:00 IST 1970 10:15 PM Another Solution: System.out.println(hr%12 + ":" + min + " " + ((hr>=12) ? "PM" : "AM"));

How to remove PayPal Developer MyApps?

Delete App facility is now added in PayPal. Goto developer.paypal.com Click  My Apps You will get all applications list Then look at right side of each application there you will get the " Delete " button. Clicking it will pops an window Write your application name in text box and click delete. That's it.

How to print any number into specific number of digits?

To print any integer in specific number of digits then we can use format() function from java.lang.String class. For e.g. public class LeadingZerosExample { public static void main(String[] args) { int number = 15; String formatted = String.format("%04d", number); System.out.println("Number with leading zeros: " + formatted); } } Output for this program will be as follows: Number with leading zeros: 0015