Table Structure

CREATE TABLE Areas(AreaName VARCHAR(255),
                    PinCode VARCHAR(255))
                    
INSERT INTO Areas(AreaName, PinCode)VALUES
                 ('Teynampet', '6000018'), 
                 ('Ramapuram', '6000089'),
                 ('TNagar', '6000017'), 
                 ('Mylapore', '6000014'), 
                 ('Gopalapuram', '6000087')

Stored Procedure

DROP PROCEDURE IF EXISTS mp_test;
CREATE PROCEDURE mp_test(IN pArea VARCHAR(255))
   BEGIN
      SET @Query = '';
      SET @City  = '';
      SET @Query = 'SELECT PinCode FROM Areas';

      IF pArea != '' THEN
         SET @City = CONCAT(' WHERE AreaName = "', pArea, '"');
      END IF;
      
      SET @Query = CONCAT(@Query, @City);

 PREPARE stmt FROM @Query;
 
 EXECUTE stmt;
 DEALLOCATE PREPARE stmt;  
END 

How Static and Constructor will work when class is Extended

  public class Main2 extends A   
  {
   public static void main(String args[])
    {	
	   
    }
  }

  class A extends B 
  {
    A()
    {
      System.out.println("I am A Constrctor");
    }
	
    static
   {
      System.out.println("I am Static Method");
   }
	
   {
      System.out.println("Empty");
   }
 }

 class B
 {
   B()
   {
     System.out.println("I am B Constrctor");
   }
 }

OP:I am Static Method

How Static and Constructor will work when class object is Created

   public class Main2 extends A   
  {
   public static void main(String args[])
    {	
       A objA = new A();  
    }
  }

  class A extends B 
  {
    A()
    {
      System.out.println("I am A Constrctor");
    }
	
    static
   {
      System.out.println("I am Static Method");
   }
	
   {
      System.out.println("Empty");
   }
 }

 class B
 {
   B()
   {
     System.out.println("I am B Constrctor");
   }
 }

OP:I am Static Method
I am B Constrctor
Empty
I am A Constrctor

How to Store CSV Ids in Hidden Field
Script

function AddProjectId(pProjectId) 
{
    var arrProjectIds = new Array();
    var strComma = '';
    csvProjectIds = $('#hdnInterestedProjectIds').val();
    csvProjectIds = $.trim(csvProjectIds);
    
    if (csvProjectIds != '') 
    {
        arrProjectIds = csvProjectIds.split(', ');
        lngArrLength = arrProjectIds.length;
    } else {
        lngArrLength = 0;
    }
    
    if (arrProjectIds.indexOf(pProjectId) != 0) {
        if (lngArrLength > 0)
            strComma = ', ';
        csvProjectIds = csvProjectIds + strComma + pProjectId;
    }
    
    $('#hdnInterestedProjectIds').val(csvProjectIds);
}

function RemoveProjectId(pProjectId) 
{
    csvProjectIds = $('#hdnInterestedProjectIds').val();
    csvNewProjectIds = '';
    arrProjectids = csvProjectIds.split(', ');
    arrNewProjectIds = new Array();
    lngArrLength = arrProjectids.length;
    
    for (i = 0; i < lngArrLength; i++) 
    {
        if (arrProjectids[i] != pProjectId) 
        {
            arrNewProjectIds.push(arrProjectids[i]);
        }
    }
    
    for (i = 0; i < arrNewProjectIds.length; i++) 
    {
        strComma = '';
        
        if ((csvNewProjectIds != '') && (arrNewProjectIds.length != (arrNewProjectIds.length - 1)))
            strComma = ', ';
        
        csvNewProjectIds = csvNewProjectIds + strComma + arrNewProjectIds[i];
    }
    
    $('#hdnInterestedProjectIds').val(csvNewProjectIds);
}
<input type=”hidden” name=”hdnInterestedProjectIds” id=”hdnInterestedProjectIds”/>

How to Split CSV into array

   csvProjectIds = '1,2,3,4';
   arrProjectIds = csvProjectIds.split(',');				

Output

     arrProjectIds[0] = 1
     arrProjectIds[1] = 2
     arrProjectIds[2] = 3
     arrProjectIds[3] = 4

How to Find Element is in Array

   csvProjectIds = '1,2,3,4';
   arrProjectIds = csvProjectIds.split(',');				
   alert(arrProjectIds.indexOf('1'));

Output

 0

The indexOf Returns 0 incase the element is in the array or
-1 if not in the array

What would be the Output

public class Main 
{	
  static
  {
    System.out.println("My Name is Mugil");
  }
}

OP: My Name is Mugil
followed by exception in Main

public class Main 
{	
  static
  {
    System.out.println("My Name is Mugil");
  }
	
  public static void main(String args[])
  {
    {
      System.out.println("What is your Name");	 
    }
  }
}

OP: My Name is Mugil
What is your Name

public class Main 
{	
  public static void main(String args[])
  {
    {
      System.out.println("What is your Name");
    }
   }
}

OP: What is your Name

4.What is the order they are processed

public class Main 
{	
 public static void main(String args[])
 {
   {
     ClassA objA = new ClassA();
     System.out.println("What is your Name"); 
   }
 }
}

class ClassA 
{
  static
  {
    System.out.println("I am in ClassA Static");
  }
	
  ClassA()
  {
    System.out.println("I am in ClassA Constrctor");  
  }

  {
    System.out.println("I am in ClassA");
  }
}

OP:I am in ClassA Static
I am in ClassA
I am in ClassA Constrctor
What is your Name

Static blocks are initiated at first followed by Constructor followed by classA and content in empty class.

5.How to Use Object to invoke function in Class

public class Main2
{
 public static void main(String args[])
 {	
   new A().showName();
 }
}

class A 
{
  public void showName()
  {
    System.out.println("Hi there");
  }
}

OP : Hi there

6.How to Find Class of object

  public class Main3 
  {
   public static void main(String[] args) 
   {
     ClasB objB = new ClasB();
     
     if(objB instanceof ClasB)
     {
       System.out.println(objB.getClass().getName());	
     }		
    }
  }

  class ClasB
  {	
  }

Toggle Class does not work by the way you think

.ClassA
{        
  color : green;
}

.ClassB
{
  color : red;
}
 $('document').ready(function(){
   $('.ClassA').on('click', function(){
      alert($(this).attr('class'));
      $(this).toggleClass('ClassB')
   }); 
 });
<div>Class A</div>
<div>Class B</div>

After the first Time ClassA is Applied When you click ClassA both ClassA and ClassB will be applied to the same tag.

The alert message will display output some thing link ClassA ClassB

Final Modifier Assures that a Reference variable cannot be referenced to a different Object

 public class Main 
 {	
   public int Age;
   public static void main(String args[])
   { 	
     final Main objMain = new Main();
     Main objMain2 = new Main();
     objMain = objMain2;
   }	
 }

OP:Generates a Exception
The final local variable objMain cannot be assigned.

How to find Length of Array

public class Main 
{
  public static void main(String args[])
  {
    int[] a = {1,2,3,4,5};
    System.out.println("Length of array " + a.length);
  }
}

Two Dimensional Array – Java

  class Main
  {
    public static void main(String args[])
    {
      int[][] a = {{1,2}, {3,4}};
      System.out.println("Content of array " + a[0][1]);     
      System.out.println("Length of array " + a[0].length);
    }
  }

OP: Content of array 2
Length of array 2

public class Main11
{
public static void main(String args[])
{
String[] arrName = new String[5];
int[] arrAge = {21, 25, 24, 26, 27};
char[] arrSection = {'A', 'B', 'C', 'D', 'E'};

arrName[0] = "Mugil";
arrName[1] = "Vinu";
arrName[2] = "Madhavan";
arrName[3] = "Adhavan";
arrName[4] = "Suryan";

//Method 1
for(int i=0;i<arrName.length;i++)
{
if(arrName[i] != null)
System.out.println(arrName[i]);
}

//Method 2
//For - Each Method
for(String item : arrName)
{
System.out.println(item);
}

//Method 3
int j =0;
while(j<arrAge.length)
{
System.out.println(arrAge[j]);
j++;
}

//Method 4
int k=0;
do
{
System.out.println(arrSection[k]);
k++;
}while(k<arrSection.length);
}
}