Results for Reader's Desk

How to Create your own widget from Code??

November 19, 2012
Hi Ranjan,
Thank you very much for asking me this question. I have written a post on your request.
Please follow that.

Thanks
Animesh


Widgets are the useful supporting blocks for a blog or website. Yesterday I tried to google a lot on how to create a widget on my own in blogger.
I understand the the blogger's layout give much more flexibilities in terms of widget creation.

you can do a lot of things in Layout section. you can


  • Drag and drop widget
  • Delete widget
  • Create a new widget
  • Reposition a widget.


But now , all blogger's need sophisticated widget and want to alter a theme. So am I.I tried to look into the code. I found a nice way to add widget from back end...from code.

Let me describe how you can create a widget..


  1. Go to template--->edit HTML--->check Expand Widget Templates 
  2. Copy the entire code to a notepad.
  3. Now to to the exact location where you want to place the widget.
  4. Firefox inspect element(firebug). or chrome's web console  can help you to find exact location.

Now let us create a structure of a widget
<b:section class="main" id="main" showaddelement="yes">
<b:widget id="Blog1" locked="true" title="Blog Posts" type="Blog">
<b:includable id="nextprev">
Your widget code here

</b:includable>
</b:widget>
</b:section>

Well this code will surely create a blank widget for you..from here you can go back to template tab of blogger and add your widget or else replace Your widget code here with your actual widget post.

Things to remember:
  • All widget should be between a section whose id should be unique
  • All widget id should be unique.
You are good to go!!! 
Image Credit:androidzoom.com
How to Create your own widget from Code?? How to Create your own widget from Code?? Reviewed by Animesh Chatterjee on November 19, 2012 Rating: 5

How to Transfer of Electricity Connection to Your Name in Hyderabad

November 19, 2012

How to Transfer of Electricity Connection to Your Name?? This question is very common between all of us.
I googled a bit found the below written

Transfer Electricity Meter in Your Name without paying any bribe.  This is good suggestion with respect to Bangalore.

But with respect to Hyderabad..let me tell you what do you require actually...


Things you require...



  1. Sale's deed 
  2. Last 2 month's electricity bill(Latest will be required) 
  3. Passport size photograph-4 (2 is required) 
  4. One Signature from Builder on top section ("Signature of Transferor") on Transfer Form (which can be downloaded from http://www.apcentralpower.com/LeftMenu/Downloads/transfer_application_form.htm ). 
  5. If you and your relative or spouse jointly buying then NOC Certificate from your spouse/relative on a 20/- Non-Judicial Stamp Paper is required 
Process you need to Follow:
  1. In Hyderabad eSeva service is very good. Even online service is there . I prefer eSeva. Please pay the current outstanding( current month bill). Still the bill will be on builder's name . Collect the receipt from eSeva. Alternatively you can get the same from builder.(In second case you are really lucky...:) ) 
  2. Now its time for you to prepare for the proof. So in a A4 paper please xerox bill and payment receipt.(2 copies) 
  3. Find out a Gazetted officer from Hyderabad. If you don't find any, go to power office or Miyapur court , You can get many Notary shops to help you out. 
  4. All the pages (front and backside) of the sale's deed and payment proof should be signed by officer. 
  5. Check the ERO Code on your Bill and find out the office.
  6. Xerox all the documents(1-2 copies) 
  7. From this office you need to take a chalan.. attested copies, Builder' signed-TransferForm & 2 Passport Photographs need to be submitted. 
  8. Now they will provide you a form.Please fill this form . 
  9. After checking all these details , a picture will be taken with their cam. 
You are good to go. Now bill will be in your name!!!!.
Image Credit: guardian.co.uk
How to Transfer of Electricity Connection to Your Name in Hyderabad How to Transfer of Electricity Connection to Your Name in Hyderabad Reviewed by Animesh Chatterjee on November 19, 2012 Rating: 5

Final Modifier Simplified in Java

June 23, 2012




Final Modifier in Java:
final is a modifier in Java. The meaning changes from context to context. The final modifier can be used before a class, method, argument, blank field or variable. And its definition changes for each of them. It is available for the below reasons:

  1. Efficiency
  2. Design
  3. Optimization

A filed can be of both static and final. It means that it has only one piece of storage that can not be changed. Final variables act like a class variable and they do not take any space on individual objects of the class.
Impact of the final keyword on the variable:
If final is used before a variable, then the value of that variable will act as a constant and thus, cannot be changed. A final data is a constant in java. Using final keyword the code convey the message to the compiler that

  1. It may be a compile-time constant that can not be changed.
  2. It may be a value initialized at runtime that we do not want to change.
In case of compile-time constant, the compiler may fold the constant value to any of the calculation where it is used. That means the calculation may be performed during compile time instead of run time which eliminates the overhead during runtime.
The constant must be primitive and are expressed using the final keyword. A value must be given at the time of definition of such constant.
Below is the example of compile-time constant:

final int PIE=3.14;
final double BONUS=.56;
Below is the example of the runtime constant:

final int SLEEPVALUE=(int)(Math.random()*60);
 

abstract class Shape{
    final static int SIZE=20;
    public void display()
    {
        System.out.println("Display method of Shape");
    }
    }

public class Rectangle extends Shape{

     public static void main(String []args){
         Rectangle obj=new Rectangle();
         obj.display();
        // obj.SIZE=30;
        System.out.println(SIZE);
        
     }
     
}
 
The output of the code:
$javac Rectangle.java
$java -Xmx128M -Xms16M Rectangle
Display method of Shape
20
Now if we omit the lines of the redefinition of SIZE

abstract class Shape{
    final static int SIZE=20;
    public void display()
    {
        System.out.println("Display method of Shape");
    }
    }

public class Rectangle extends Shape{

     public static void main(String []args){
         Rectangle obj=new Rectangle();
         obj.display();
        obj.SIZE=30;
        System.out.println(SIZE);
        
     }
     
}
 
The output of the code:
$javac Rectangle.java
Rectangle.java:14: error: cannot assign a value to final variable SIZE
obj.SIZE=30;
       ^
1 error

Impact of the final keyword on the Class:
If the final is used before a class, then that class cannot be sub-classed. we generally do not use final class but for security reason sometimes, we create the class as final. So nobody can subclass it and can change the methods of how they work. Like-String class. So we can not inherit the class.putting an entire class is final means that we don't want to inherit from this class or allow anyone else to do so. This is done if the class does not need any change.Defining the class as final simply prevents inheritance.So in other words final prevents a class being further sub classes for security reason.Any such attempt will cause compile time error.

class abc{}
final class xyz{
int i=10;
int j=20;
abc x=new abc();
void mno()
{
}
}
// not possible as xyz class is final class
class AnyClass extends xyz{}
public class MyClass{
public static void main(String args[])
{
xyz newClass=new xyz();
newClass.mno();
newClass.i=40;
newClass.j=60;
}
}
 
Impact of the final keyword on the Methods:
If the final is used before a method, then that method cannot be overridden. In this case, nobody can redefine the method. like-println().The same rule applies to final data members irrespective of the class is defined as final. Making a method final serves two important purposes.. they are as follows:

  1. It simply put a lock on the method to prevent any inheriting class from changing its meaning. Mostly we use this as design phase.It implies that the behavior of the method is retained.In other words,final methods are not overridden. Any private method of a class is implicitly final as we can not access a private method,hence they can not be overridden. However adding final modifier to a private method does not make sense as both they do the same thing.
  2.  The second reason is efficiency. It allows the compiler to turn any method call to in line calls. (when the compiler sees method call mechanism that is to push arguments on the stack,hop over the to the method code,execute it,hop back ,clean off the stack arguments and deal with the return values,it simply replaces the method call with a copy of the method code that reduces the execution overhead and increases efficiency.However if the method body is too big , this mechanism may not hold good and may not give improvement)

Defining the class as final simply prevents inheritance.This means that all methods in a final class are implicitly final.(There is no way to override them).

Impact of final on method argument:
Java allows us to make arguments final by declaring them as such in the argument list. Final argument means inside the method , we can not change what the argument handle points to.

class MyClass{
public void doSomething(){}
}
public class FinalArgumentTest{
void withFinal(final MyClass mc)
{
//mc=new MyClass();//not possible as mc is final
mc.doSomething();
}
void withoutFinal(MyClass mc)
{
mc=new MyClass();//possible as mc is not final
mc.doSomething();
}
public static void main(String args[])
{
FinalArgumentTest fat=new FinalArgumentTest();
fat.withFinal(null);
fat.withoutFinal(null);
}
}
 
We can pass or assign a null handle to an argument without compilation issue for final and non final arguments.
Impact of final on fields:
Java allows us to create final blank fields. They are not given any initialization values but we need to initialize them before we use them.Blank fields provides flexibility like a final filed inside a class can now be different for each object and yet still retains its immutable quality.

public class BlankFinalTest{
final int i=0; //initialized final
final int j; //blank final
final MyClass mc; //blank final handle
//blank final must be initialized in the constructor
BlankFinalTest()
{
    j=1; //initialized the blank field
    mc=new MyClass();
}
BlankFinalTest(int x)
{
    j=x; //initialized the blank field
     mc=new MyClass();
}
     public static void main(String []args){
        BlankFinalTest bft=new BlankFinalTest();
        
     }
     
}
class MyClass{}
 
The assignment to final either with an expression at the point of definition of the field or in every constructor.
Impact of final on objects:
When using final with object handles rather than primitives,the final makes the value constant but with an object handle,final makes the handle constant.The handle must be initialized to an object at the point of decleration and handle can never changed to any other object.

final object; //handle constant needs to be initialized.
 
Compiler has the same efficiency when we make a class or method final. But as a coder we don't know when and how the final class and method will be used. We have to be very careful before making any class or method as final. Specially for general purpose reusable class and methods.
Final Modifier Simplified in Java Final Modifier Simplified in Java Reviewed by Devopriya on June 23, 2012 Rating: 5

How to Run Java Program Without Main Function??

June 18, 2012
Hi Animesh ,
I was asked the question in my semester -"How to Run Java Program Without Main Function??" In a leading book it is said yes and they gave explanation...I did not understand the concept.
Can you please tell me why?
Regards,
Sunita

Hi Sunita,
Thank you very much for writing to me .Yes Surely we can run a Java Program without main method.
How::
In Java, a static initializer gets executed as soon as the class is
loaded, even before the main method is called!!!.

So if we create a static block  and give some command inside it. It will execute.The JVM finds and loads the class into memory when you run this code,the static initializer is executed during the loading and
initialization of the class.
But my suggestion is do not use this feature while developing your application. And even if you use this feature please make sure to incorporate
System.exit(0); After your code
System.exit(0) is called at the end of the static block to terminates the program. If not, then the JVM would have next used reflection on that class to find the main() method. If it does not find the main method, it throws an exception. if we don't write main() in the program then the compiler doesn't know
where to start the program..

public class WithoutMain {
static {
System.out.println( "Hello World" );
System.exit(0);
}
}

I have taken help from http://www.xyzws.com/Javafaq/can-a-java-application-run-without-a-main-method/63
How to Run Java Program Without Main Function?? How to Run Java Program Without Main Function?? Reviewed by Animesh Chatterjee on June 18, 2012 Rating: 5

How to give test URL to my framework

January 26, 2012


This section is dedicated to my viewers.Here they can ask question and I will be happy to help or redirect to some page what is best suitable for them. 







Hi Animesh
How to change/give environment name dynamically -to my framework? .Right now we are hardcoding in our scripts.

Regards
Veenetha
Hi Veenetha,
Thank you very much for writting me!! I am trying my level best to solve your query.

Well veenetha,there are several ways how you can insert environment name into your framework:----
1)Ofcourse,I agree,the hardcoding into a script is one of the options.
 String  URL="www.abc.com"
2)The second improvement could be,you can create a dialog box(input to take the environment.This you will place master/global driver and the value you will pass to the child scripts.

Or,you get the URL from user and save it to the notepad and read it dynamically afterwords.
3)Create an environment file for providing URL.I found advantage on creating a separate file for environment details.Updation is very easy and effective.
Say active_URL="google.com"
Tomorrow you can change it to
  active_URL="yahoo.com"
  active_URL="google.com"


My personal suggestion is to go with either 2 or 3.
How to give test URL to my framework How to give test URL to my framework Reviewed by Animesh Chatterjee on January 26, 2012 Rating: 5

Why Client Side Applet is over??

January 16, 2012

This section is dedicated to my viewers.Here they can ask question and I will be happy to help or redirect to some page what is best suitable for them.


Hi,I am very new to Java.our text book starts with an applet, So far I understand this is client side applet. But in practical life nobody writes applet(as per our sir). Can you explain me why??
Regards,

Rini
Hi Rini
Thank you very much for writing me!!!.I am really happy to help you with this regards.




  • What happens,when we try to access a page which is having applet embedded in it,the byte code of the applet starts to download to the client machine.if your applet is small enough then it is beautiful but if it is huge?? yes the downloading time becomes a headache for new techies.
  • Apart from this there is also a compatibility problem.To run an applet your browser has to have the applet compatible. Think about today's scenario,The client side means a laptop,a desktop,a server, a tablet even the new smart phones have the browser facility. All they may not have browser compatibility.
  • Third is the security issue with local applet.The applet , when talking to database ,may give more access to secure data to the user if not coded properly. The client side applet can open a connection to the server which stays behind firewall.Now getting response from server through RMI is a real pain. 
For these reasons the applet -client side is not a good practice while coding.Rather there are several javascript available which will give more great GUI feature.



you know what?? Applet is termed as it runs in client side.But servlet is termed as that java code(applet) runs on server side.Ser-let.!!!

Why Client Side Applet is over?? Why Client Side Applet is over?? Reviewed by Animesh Chatterjee on January 16, 2012 Rating: 5

KeyWord driven Framework and Testing

January 14, 2012




This section is dedicated to my viewers.Here they can ask question and I will be happy to help or redirect to some page what is best suitable for them.


ur blog looking great,Especially For QTP u r sharing very useful stuff.Can u Share some ideas on Key word driven framework.----by Rajesh


Hi Rajesh
Thank you very much for writing me!!!...I have covered few topics already.Please go through..

  1. http://www.mydigitalvoice.in/2010/09/what-is-keyword-driven-framework.html
I hope you will get more information. If you need anything specific to keyword driven ,Please let me know.I will be happy to help you.Happy Reading!!
KeyWord driven Framework and Testing KeyWord driven Framework and Testing Reviewed by Animesh Chatterjee on January 14, 2012 Rating: 5

How To Set Classpath in Java

January 14, 2012
Once you install java this settings are not immediate required.It is only required when you try to run java programs from other than bin folder. Without the class path settings one can run Java programs from bin folder. But after number of coding code , the bin folder looks very unorganized. Even if you have created and archived the source and .class files to another folder. To run them you need to bring them into bin folder.

It would have been great if we could create our own folder structure place required source code and .class files into them and could run.

Yes!! if you are thinking this then this post is for you. To solve this problem we need to set classpath for java.
Lets see how:

Step 1: First install java software,say in E drive or in C drive inside folder j2sdk1.4.2_01 or java

Step 2: Now,set the class path.
Step 3: Go to 'My Computer'.
Step 4: Right click on mouse and go to 'Properties'.

Step 5: Go to 'Advanced' on the 'System Properties'. then click on 'Environment Variables'

Step 6: In User Variables click 'New'.





Step 7: Write 'JAVA_HOME' in Variable name and the path where the software is installed in Variable value.And then click 'OK'.
Step 8: In System variables, click new and give the values as in figure.And then click 'OK'.
Step 9: In System variables, there will be a variable named 'Path'. Double click there. A new window will come. In 'Variable value' give a semi-colon after whatever is written. After that write '%Path%;C:\j2sdk1.4.2_01\lib;.;'  (if the software is installed in j2sdk1.4.2_01 folder of C drive.for this device it is in E:\java\lib And click 'OK' wherever required.

Hope you enjoyed this post. Please consider sharing this article .Also let me know if you face any issue regarding the same.
How To Set Classpath in Java How To Set Classpath in Java Reviewed by Animesh Chatterjee on January 14, 2012 Rating: 5

How to determine a vulgar fraction in java

January 10, 2012
This section is dedicated to my viewers.Here they can ask question and I will be happy to help or redirect to some page what is best suitable for them.

Hi Animesh,I am bit confused with valgar fraction definition.What is vulgar fraction?? can you write a small program to determine a vulgar fraction??
Thanks
Arindam

Hi Arindam,Thank you very much for writting this.Let me tell you I got confused too by seeing the vulgar fraction definition!!!How ever i have taken help from http://www.wordreference.com/definition/vulgar%20fraction

A vulger fraction:


A vulger fraction is a fraction in which denominator is an integer other than 10,100,1000.....
like -3/4,4/5,5/7 etc.

Logic to write a vulger fraction determination

Well the logic is...
1.take the fraction in x/y form from user
2.It will come as a string
3.Split the String with "/"
4. Find out the second number
5.Check if that is any multipler of 10.While we modulo operation with 10 ,it should not give any remainer
6.Determine the vulger fraction.


Lets code

1.take the fraction in x/y form from user-----take the input the code is here
2.It will come as a string
3.Split the String with "/"
4. Find out the second number
5.Check if that is any multipler of 10.While we modulo operation with 10 ,it should not give any remainer
6.Determine the vulger fraction.



public class Vulger {
    public Vulger() {
        int deno;
       // this is where you take user input
        String fraction="3/1000";
        String [] temp = null;
      //Split it with "/"
        temp= fraction.split("/");
       //Change it integer from String
       deno=Integer.parseInt( temp[1] );
       //Here the main logic comes checking if it is divisible by 10 and making sure denominator is only  a subset of  multiplier of 10 like 10,100,1000.... not 20,30,40...etc
        if (((deno%10)==0) &&  (checkval(deno)))
        {
         System.out.println(fraction+" is not a vulger fraction");
        }
        else
        System.out.println(fraction+" is a vulger fraction");  
    }
    public static void main(String[] Args) {
        new Vulger();
    }

    private boolean checkval(int deno) {
      //making sure denominator is only  a subset of  multiplier of 10 like 10,100,1000.... not 20,30,40...etc
           int res=1;
            do
            {
             res=deno%10;
            deno=deno/10;
            }
                while (deno>=1);
        if (res==1)      
        {
            return true;
        }
                else
        return false;
    }
}

How to determine a vulgar fraction in java How to determine a vulgar fraction in java Reviewed by Animesh Chatterjee on January 10, 2012 Rating: 5

How to Call a servlet from HTML using Ajax

January 09, 2012
This section is dedicated to my viewers.Here they can ask question and I will be happy to help or redirect to some page what is best suitable for them.
















 Reader's Question:
Hi Animesh,
can you please let me know how to connect a servlet /jsp from HTML? Basically my requirement is something that I need to send some data to the server and get response from server without  refreshing the page.
Regds,
Ashwin

Hi Ashwin,
Please visit this link to understand more on this call http://www.hiteshagrawal.com/ajax/ajax-programming-with-jsp-and-servlets

For more simplification I am modifying the code given there
say I have a simple HTML page where user gives login id and password. upon correct login info it will say "successfull login" or else it will say " Please insert correct data"

your HTML will look like-




<html>
<head>
<title>Checking login in AJAX</title>
<script type="text/javascript">
 function getXMLObject()  //XML OBJECT
{
 //Not changing his original values
var xmlHttp = false;
   try {
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
        }
        catch (e) {
    try {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
        }
        catch (e2) {
       xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
       }
       }
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
     xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
      }
   return xmlHttp;  // Mandatory Statement returning the ajax object created
}

var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object

function ajaxFunction() {
  //get the values from textboxes
  var userIn=document.myForm.id.value;
  var pwd=document.myForm.pwd.value;
  alert(userIn);
  if(xmlhttp) {
    xmlhttp.open("POST","servlet1",true); //gettime will be the servlet name
    xmlhttp.onreadystatechange  = handleServerResponse;
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    //send them to server one by one .You can send more data one by one..I customized this part
  xmlhttp.send("id=" + userIn);
    xmlhttp.send("pwd=" + pwd);
  }
}

function handleServerResponse() {
   if (xmlhttp.readyState == 4) {
   
     if(xmlhttp.status == 200) {
 
       //document.myForm.time.value=xmlhttp.responseText; //Update the HTML Form element
       document.getElementById("text").innerHTML=xmlhttp.responseText;
     }
     else {
        alert("Error during AJAX call. Please try again");
     }
   }
}
</script>
        <body>
        <form name="myForm" method="POST" action="Servlet1">
        Enter your ID<input type="text" name="id" />
        <br />
        Enter your Password<input type="text" name="pwd" />
        <input type="button" onClick="javascript:ajaxFunction();" value="Click to check teh userName"/>
        <br />
        <div id="text" name="validation" />
        </form>
        </body>
        </head>
        </html>
Server side servlet will be something

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Servlet1 extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }

    public void doGet(HttpServletRequest request,
                      HttpServletResponse response) throws ServletException,
                                                           IOException {
     
        doPost(request,response);
 
    }

    public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
                    PrintWriter out = response.getWriter();
                String name = null;
                String pwd=null;
                if(request.getParameter("id") != null) {
                                        name = request.getParameter("id");
                                     
                                }
                                else {
                                       name = "";
                                }
               //put your logic here
                if (name.equals("Animesh"))
                {
                       //based on the logic send response back
                                out.println("You have successfully logged in:" + name);
                }
                else
                out.println("This is not a valid login" + name);
               }
}

How to Call a servlet from HTML using Ajax How to Call a servlet from HTML using Ajax Reviewed by Animesh Chatterjee on January 09, 2012 Rating: 5

How to make a script drive/area independent in QTP

June 20, 2009
There is good question asked by Lakshmanan Durairajan ...
When my manager takes the scripts, he wants to run them from his D drive. But I have written the scripts in such a way that it gets executed and stores the results in an Excel at C drive. To avoid this, I want to get the current folder path. How to do that?

if i make it more simple Lakshmanan....what is required is to take the test path dynamically i.e how to make a script drive/area independent?

lets do it..



now go to



this is the option by which QTP determines from here the script is running.
These are all environment variable.Now what you need to do is to take the path by using the environment variable.


now if yoy are using this command...i.e. environment of testpath...this will dynamically give you the path of the test running folder.

now configure your testing here I mean the path and the folder structure.your problem is solved.
How to make a script drive/area independent in QTP How to make a script drive/area independent in QTP Reviewed by Animesh Chatterjee on June 20, 2009 Rating: 5
Powered by Blogger.