Friday, 9 August 2013

Simple JQuery to Hide and Display a Specific Block


        Two simple, effective methods [Self explanatory] in displaying or hiding specific blocks in jQuery are

.hide() - Used to Hide the specific block by ID
.show() - Used to Display the specific block by ID

.hide() & .show()

        This method does not accept any arguments.

.hide( [duration ] [, complete ] ) & .show( [duration ] [, complete ] )
 
        duration (default: 400) -  Type: Number or String
        A string or number determining how long the animation will run.

        complete -  Type: Function()
        A function to call once the animation is complete.

.hide( options ) & .show(options)

        options -   Type: PlainObject
        A map of additional options to pass to the method.

            It will support duration, easing, queue, specialEasing, step, progress, complete, done, fail and always.

Sample Program 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
<script src="/Sample/js/jquery-1.9.1.js"></script>
<script>
$(document).ready(function(){
        $("#Admin").hide();
        $("#Student").hide(); 
        $("#Submit").hide();
});

function changeUserType(value)
{
      if(value != 'Select'){
            if(value == 'Admin'){
                  $("#Admin").show();
                  $("#Student").hide();
            }
            else if(value == 'Student'){ 
                  $("#Student").show();
                  $("#Admin").hide();
            }
            $("#Submit").show();
      } 
} 
</script>
</head>
<body>
      <h3 align="Center">User Login Page</h3>
      <div align="Left">
<select id="Select" onchange="changeUserType(this.value)" name="Select">
  <option value="Select">Select...</option>
  <option value="Admin">Admin</option>
  <option value="Student">Student</option>
</select>

<form name="myform" action="login">

  <div id="Admin">
    <h4>Admin Block</h4>
      Enter Administrators Name: <input type="text" name="aname"><br>
      Password: <input type="text" name="apassword"><br>
  </div>

      <div id="Student">
            <h4>Student Block</h4>
            Enter Student Roll No: <input type="text" name="rnumber"><br>
            Password: <input type="text" name="spassword"><br> 
      </div>

      <div id="Submit">
            <input type="submit" value="Submit">
      </div>
</form>
</div>
</body>
</html>

        Some simple JQuery methods became effective tool for web developers to do magic on the screen.  Happy Learning...

Saturday, 25 May 2013

Method Overriding Functionality



Overriding - override the functionality of any existing method

Method overriding - Having two methods with the same signature (name, number and the type of its parameters), return type  but different implementation. 


Necessary Condition



One of them would exist in the Parent class (Base Class)
Another will be in the derived class(Child Class).
@Override annotation is required

It is runtime activity- overriding uses dynamic binding

If a subclass defines a class method with the same signature as a class method in the super class, the method in the subclass hides the one in the super class.



Sample Program


 public class Alpha {
    protected void addCapability() {
        System.out.println("In Cocoon - Get Stronger and Stronger to Servive in this World");
    }
}

public class Beta {
    public void addCapability()    {
        System.out.println("Become Fly - Add the capability of being Happy and Fly with real Freedom");
    }
    public static void main(String[] args) {
        Beta b = new Beta();
        b.addCapability();
    }
}
Here we have the flexibility of hiding the base functionality  by adding completely new functionality in accordance with our dynamically changing requirements


Constrains

1. Method signature must be same including return type, number of method parameters and type of parameters and order of parameters

2. Overriding method cannot throw higher Exception than original or overridden method. if original method throws IOException than overriding method cannot throw super class of IOException, the sub class can use FileNotFoundException but not wider exception e.g. Exception or Throwable.

3. An overriding method can allow more visibility , but not less, access than the overridden method protected instance method in the super class can be made public but not private, in the subclass.

4. Static - The version of the overridden method that gets invoked is the one in the subclass.The version of the hidden method that gets invoked depends on whether it is invoked from the superclass or the subclass.