Flipkart Search

Tuesday, 1 December 2015

Some useful Linux commands for Developers

1. find the files modified before a certain time
find /path/to/folder/ -mmin +60
2. find the modified after a certain time
find  /path/to/folder/ -mmin -60

Wednesday, 14 October 2015

Some sql errors and resolutions

1. SQL Error: ORA-00932: inconsistent datatypes: expected DATE got NUMBER
Put the input date as DATE '2016-09-30'

2.  <JDBC> <BEA-001129> <Received exception while creating connection for pool "SOADataSource": ORA-28000: the account is locked
ALTER USER DEV_SOAINFRA  identified by password ACCOUNT UNLOCK

and change the password in the datasource added in console

Friday, 15 May 2015

Set Initial focus on any ADF UI component

Often developers requires focus on a particular UI component on page load. ADF provides out-of-the-box feature for this problem. All you need is the exact component id of that element.
In this example I will show you how to move cursor to the input box used as a username input. This component was inside a bounded-taskflow exposed in a jspx region.
First the jspx code .

 <af:document id="d1" title="#{sessionScope.pageTitle}" 
partialTriggers="r1" initialFocusId="r1:0:sf1:it1">

This is our login module and now will try to find out its id generated on the webpage by developer tool.
We can now see the actual id of the UI component exposed in browser. It is the same ID we need to put in 
initialFocusId.


Thursday, 14 May 2015

Pitfalls in System.out.print or SOPs

While developing any kind of application we want that application to be as fast as we can. But it is not an easy task to achieve. Making a fast application is easy if the application is not complex. With complexity applications tends to slow down and one of the major reason is - System.out.print() of java.

Some of you may know this fact or some of you not. To understand how costly is this SOP . Let's try to build a simple method to test the speed.

    public static void main(String[] s) throws FileNotFoundException,
                                               IOException {
        String count = "";
        long total=0;
        for (int j = 0; j < 20; j++) {
            long temp=calculateCostofSOP();
            count = count + String.valueOf(temp) + " ";
            total=total+temp;
        }
        System.out.println(count);
        System.out.println(total);
    } 

This loop iterator 20 times to have a clear picture of COST of SOP. Let's now have our implementation of calculateCostofSOP

    public static long calculateCostofSOP() throws FileNotFoundException, IOException {
        FileReader fr =
            new FileReader("C:\\gre");
        
        PrintWriter pw=new PrintWriter("C:\\grew");
        BufferedReader bfr = new BufferedReader(fr);

        String line = "";
        StringBuilder sb = new StringBuilder();
        long sv = System.currentTimeMillis();
        while ((line = bfr.readLine()) != null) {
            line = line.replace("\t", "=");
            sb.append(line + "\n");
            System.out.println(line);   //comment this line while we use file out
           // pw.write(line + "\n");   //comment this line while we use console out
        }
        pw.close();
        bfr.close();
        FileWriter f =
            new FileWriter("C:\\gre");
        BufferedWriter buffW = new BufferedWriter(f);
        buffW.write(sb.toString());
        buffW.close();
        return (System.currentTimeMillis() - sv);
    }
Now look at the output we received. It took whopping 109028 milliseconds. The file "gre" was not too long. It contains data from here https://quizlet.com/47571/export.
But when I commented the SOP line and save data to the file the following output was arrived.

 //System.out.println(line);   
pw.write(line + "\n"); 
Now, it took only 1062 milliseconds.
Try it by yourself and see the results. By the above experiment we reach to following conclusion.

  • Try to avoid SOPs as much as you can
  • Never try to put SOPs inside any loop.
  • In prod applications use ADFLogger or log4j for the better performance.
  • If possible concat the String inside the loop and SOP it outside the loop.In my case it took-45216 ms



Tuesday, 27 January 2015

Using google / custom fonts in the ADF application

In ADF use can use any google font as you used to use default fonts provided by ADF or Webcenter.
Here are the steps.

  1. Register the css file in the page through the af:resource tag
<af:resource type="css" source="http://fonts.googleapis.com/css?family=Lobster"/>

     2. Make an entry in the application's css file.

.inText {
    font-family: 'Lobster', cursive;
    font-size: medium;
}

   3. Put the above styleclass in the component
<af:outputText styleClass="inText " value="Text with google font"
                                         id="ol1"/>


Precaution while using javascript in a page fragment or in ADF region

Don't include javascript in the page Fragment just after the jsp:root tag . It will cause undesired effects if this page is navigated from somewhere else.
This will be a wrong approach for a jsff page
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
          xmlns:f="http://java.sun.com/jsf/core">
  <af:resource type="javascript" source="/js/custom.js"/>

The right approach is to include this resource component inside a  container component . Like this
<af:panelFormLayout>
  <af:resource type="javascript" source="/js/custom.js"/>
</af:panelFormLayout>