Posts

Google Ads Developer Blog: Google App Engine for Java meet DFP API, Part 1: H...

Google Ads Developer Blog: Google App Engine for Java meet DFP API, Part 1: H... : We are excited to start discussing how to use the DFP API from within the Google App Engine (Java) environment. This first blog post in th...

Date using Java: create Data using year, month, day, hour, minute, seconds in Java

Creating  custom date using java 1) Using java.util.Date  int year=2013; int month=5;   // months starts from 0 to 11, as 0 stands January and 11 stands for December int day=15; int hour=12; int minute=58; int seconds=47; *** Date utilDateObj=new Date(year,month,day,hour,minute,seconds); ***  This is depricated. We recommend to use Calander as given below: Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.set(Calendar.HOUR, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, seconds); Date lastUpdatedDate = calendar.getTime();

Impetus Interview questions: Code-2

What will be the output of the following... class A{ public static void main(String [] arg){         String s1="hello";         String s2=new String("hello");         System.out.println(s1==s2);         String s3=new String("world");         String s4=new String("world");                 System.out.println(s3==s4);         System.out.println(s1.equals(s2));         System.out.println(s3.equals(s4));         String s5="hello";         System.out.println(s1==s5);     } } Output:  See here..... false false true true true s1 == s2 : false, both refernece variable pointing to different objects s3 == s4 : false, both refernece variable poin...

Impetus Interview Questions: Code Snipet 1

What will be the output of the code? interface TestOne{     int limit=100;     void display();    } interface TestTwo{     int limit=200;     void display();    } public class TestInterface implements TestOne,TestTwo{     //int limit=0;     @Override     public void display() {         System.out.println("Hello... Test interface...."+limit);             }         public static void main(String [] arg){         TestInterface obj=new TestInterface();         obj.display();      } } ------------------------------------------- Output: Compiler error at System.out.println(....) : The field "limit" is ambiguous.

Read file from google cloud storage using Java

You can read file from google cloud storage using following code.... public void readTextFileOnly(String fileName) {          log.info("Reading from google cloud storage,fileName:"+fileName);         FileService fileService = FileServiceFactory.getFileService();         String filename = "/gs/" + BUCKET_NAME + "/" + fileName;         log.info("Reading from google cloud storag: filename:"+filename);         AppEngineFile readableFile = new AppEngineFile(filename);         FileReadChannel readChannel;         try {                 readChannel = fileService.openReadChannel(readableFile, false);                 BufferedReader reader = new BufferedReader(Chann...

Blowfish decryption: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher

Problem : Blowfish decryption+  javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher Solution: Always check your data whether it is a multiple of 8 bit or not.               if(decodedBytes.length % 8 != 0){ //not a multiple of 8                    System.out.println("decodedBytes is not padded properly in 8 bits");                    //create a new array with a size which is a multiple of 8                    byte[] padded = new byte[decodedBytes.length + 8 - (decodedBytes.length % 8)];                    //copy the old array into it     ...

Encryption and decryption using Blowfish and base64 on Google App Engine

Encryption and Decryption  using Blowfish and base64 on Google App Engine using Java 1.. Encryption double using blowfish and then base64   public static String doubleEncryption_Blowfish_Base64(String to_encrypt,String key,String charEncoding){            //charEncoding="UTF-8";            Cipher cipher;             try {                byte[] encodedBytes =to_encrypt.getBytes(charEncoding);                                      if(encodedBytes.length % 8 != 0){ //not a multiple of 8                    System.out.println("encodedBytes is not padded properly in 8 bits"); ...