Posts

CSC Interview Question: how to find common elements between two collections

Solution: retainAll method do this.   public boolean retainAll (Collection<?> c) Example: public class Test {        public static void main(String [] args){          LinkedHashSet hs = new LinkedHashSet();           // add elements to the hash set           hs.add("B");           hs.add("A");           hs.add("D");           hs.add("E");           hs.add("C");           hs.add("F");           System.out.println(hs);                     LinkedHashSet hs2 = new LinkedHashSet();       ...

nth Highest salary

Find the Nth highest salary Solution: Common logic for all database is as... select t.name,t.salary from employee t   where N= (               select count(u.salary) from                   (select distinct salary from employee ) as u                   where t.salary<= u.salary        )

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role

Errror: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role....... Solution: Add lazy=false in your hbm file where you have declare collection... Example: <set name="hhResume" inverse="true" lazy="false" >             <key>                 <column name="UID" not-null="true" />             </key>             <one-to-many class="com.example.HhCandidate" />         </set>

Read gzip response from a URL using Java

Here is a code template..... public static String readGZFile(String url) throws IOException {            StringBuffer dataBuffer =new StringBuffer();            InputStream gzipStream = new GZIPInputStream((new URL(url)).openStream());            Reader decoder = new InputStreamReader(gzipStream, "UTF-8");            BufferedReader buffered = new BufferedReader(decoder);            int i=0;            String line=buffered.readLine();            while(line !=null){                dataBuffer.append(line);                line=buffered.readLine();           ...

DFP with Google App Engine

See the code ************************************************************************************* package com.lin.web.servlet; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import java.util.logging.Logger; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.google.api.ads.common.lib.exception.ValidationException; import com.google.api.ads.dfp.appengine.oauth.CredentialException; import com.google.api.ads.dfp.jaxws.factory.DfpServices; import com.google.api.ads.dfp.jaxws.v201302.ApiException_Exception; import com.google.api.ads.dfp.jaxws.v201302.Network; import com.google.api.ads.dfp.jaxws.v201302.NetworkServiceInterface; import com.google.api.ads.dfp.lib.client.DfpSession; import com.lin.web.util.ClientLoginAuth; import com.lin.web.util.LinMobiileProperties; import com.lin.web.util.Lin...

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();