Method name same as Class Name
void Sample3 is a method not a Constructor

package com.scjp.test;

public class Sample3 
{	
	void Sample3()
	{
		System.out.println("I am Constructor");
	}
	public static void main(String[] args) 
	{
		Sample3 objSample3 = new Sample3();
	}
}

OP:

Overloading Constructors

package com.scjp.test;

class Sample3
{
  public static void main(String args[])
  {
    Vasko objVasko1 = new Vasko(54);
    Vasko objVasko2 = new Vasko();
    System.out.println(objVasko1.Size);
    System.out.println(objVasko2.Size);
  }	
}

class Vasko
{
   int Size;

   Vasko()
   {	  
   }
	
   Vasko(int s)
   {
    Size = s;	  
   }
}

OP:

54
0

Install Apache Server in Terminal CentOS

 yum install httpd

Check Status of Apache Server

/etc/init.d/httpd status

Start Apache Server

/etc/init.d/httpd start

Start MySQL Terminal

/etc/init.d/service mysqld start

Check Status of MySQL

/etc/init.d/service mysqld status

Javascript Code
Please Note – this doesnt work with old version of js File


$('document').ready(function(){
$('#cboCity').live("change", function(){
alert('Hi there');
});

$('#btnChange').on("click", function(){
changeCities();
});
});

function changeCities()
{
strSelect = "<select id='cboCity' name='cboCity'><option>Chennai</option><option>Mumbai</option></select>";
$('#City').html(strSelect);
}

HTML Code

<input id="btnChange" type="button" name="btnChange" value="Change Me" /></pre>
<table>
<tbody>
<tr>
<td>
<div id="City">
<select id="cboCity" name="cboCity"><option>Chennai</option><option>Mumbai</option><option>Delhi</option><option>Kolkatta</option><option>Andrapradesh</option>
</select>

</div>
</td>
</tr>
</tbody>
</table>

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')

Procedure which returns multiple result sets

 DROP PROCEDURE IF EXISTS mp_test1;
 CREATE PROCEDURE mp_test1()
 BEGIN
   SELECT AreaName FROM Areas;
   SELECT PinCode FROM Areas; 
 END 

Procedure Call

 CALL mp_test1()

PHP Code To retrieve Records from Multiple Resultsets

   $mysqli	= new mysqli('localhost', 'root', '', 'test','3306');
	
   $query = "CALL mp_test1()";
	
   $i = 0;	
	
   if ($mysqli->multi_query($query)) 
   {
    do {		
	/* store first result set */
        if ($result = $mysqli->use_result()) 
	{
	  $j = 0;
	  
          while ($row = $result->fetch_row()) 
	  {
	     $arrResult[$i][$j] = $row[0];
	     $j++;
	  }
				
   	  $result->close();
         }
			
	if($mysqli->more_results()) 
	{
  	  $i = $i + 1;
	}			 
     } while ($mysqli->next_result());
   }
	
   print "
";
   print_r($arrResult);

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”/>