Posts

Best way to Format a Double value to nth Decimal places in Java

Best way to Format a Double value to nth Decimal places in Java ------------------------------------------------------------------ public static double getDoubleValue(String value,int digit){         if(value==null){             value="0";          }         double i=0;          try {              DecimalFormat digitformat = new DecimalFormat("#.##");              digitformat.setMaximumFractionDigits(digit);             return Double.valueOf(digitformat.format(Double.parseDouble(value)));                     } catch (NumberFormatException numberFormatExp) {         ...

Append option into a select using jquery

You can use jquery to append data from select from a array of data. See the java script function where you can pass the dataArray like dataArray=["A","B"] and elementId , means the id attribute of your select element; function appendDataToSelectDropDown(dataArray, elementId ){       if(dataArray !=null && dataArray.length>0){           $('#'+ elementId ).find('option').remove().end()             .append('<option value="-1">Select Creative Size</option>');           $.each(dataArray, function( index, value ) {                    $('#'+ elementId ).append(new Option(value, value));           });       }   }

Fusion table layer: data may be still loading

On hitting fusion table layer on Maps, it says data may be still loading Answer : Check your query syntex, new query syntex is as given below with an example (Non numeric fields must be enclosed with '' quotes) function fetchDataFromFusionTable(){    try{                            var fusionOptions = {                             query: {                 select: 'Geometry',                 //from: "1QTnVfSO-agR4ueOAVa-uUzYrmNwE4DQ6l0e22EA",                 from: "1Fhnl0uOC3Ol3rMHI5FQIiTDIP3gw7QbRjldvFgY",                 where: " 'Start_Da...

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