Friday, July 30, 2010

Java Static Function

Q. Can we override the Static function in Java ?
A. Yes we can override the Static function in Java see the sample recipe

class Sample implements Over {

public static int simple(int a, int b) {
int c = a + b;
return c;
}
}
class Overloading extends Sample {

public static int simple(int a, int b) {
int c = a * b;
return c;

}
public static void main(String[] args) {
        Sample sam = new Sample(22, 90);
        Overloading obj = new Overloading();
          obj.simple(10,20); // here the sub class function call
         sam..simple(10,20); // here the super class function call
}
}


Saturday, February 6, 2010

Type Hint in PHP

Type Hint in PHP.
Day by day PHP introduces new strong OOPS concepts earlier i used the Type Hinting (earlier it's available in Hot cup of Java) in type hint we restrict the input type parameter like this:

class DAO{function add(Model $model){}}
here we restrict the input parameter is object type & also object of Model class.
but yet it's have some limitation, available for object and array not for integer, float etc

Sunday, January 24, 2010

PHP Unit Test Case

How to Install PHPUnit Test ?
1. First Create the environment variable of pear:
check where u install the php /usr/local/php/bin/
2. open the file : /etc/environment
3. add the path in PATH
4. logout (otherwise environment not reflect)
5. sudo /usr/local/php/bin/pear channel-discover pear.phpunit.de
6. if after the above command he is asking for upgrade the pear:
7. use this command : sudo usr/local/php/bin/pear upgrade PEAR
8. sudo usr/local/php/bin/pear install phpunit/PHPUnit

now start programming.



Thursday, December 24, 2009

Reliance Broadband+, Tata Photon+ Detects in Ubuntu 9, Detect Plug2surf

Hello,
Sometime it's become a big problem for Ubuntu user to detect the USB broadband device, in some forums everybody suggest KPP installer or some changes in wv.conf file, this is a big myth follow a simple steps and enjoy...:

Plug in your device to computer:

1. Enable your networking.
2. In networking option choose mobile boradband
3. Click ADD and welcome screen appear
4 click forward choose country then service provider
5. if service provider not in list choose another (Reliance not in list).
6. click on summary and apply change then enter / edit the user name & password
or phone number (if required) then save & connect
7. See in the right side of top panel one image start moving and give u welcome message....enjoy internet it works

Monday, December 21, 2009

What is FEDERATED Engine / how use to it.

what is FEDERATED engine.

The FEDERATED storage engine is available beginning with MySQL 5.0.3. It is a storage engine that accesses data in tables of remote databases rather than in local tables.

How to Use FEDERATED Tables

The procedure for using FEDERATED tables is very simple. Normally, you have two servers running, either both on the same host or on different hosts. (It is possible for aFEDERATED table to use another table that is managed by the same server, although there is little point in doing so.)

First, you must have a table on the remote server that you want to access by using aFEDERATED table. Suppose that the remote table is in the federated database and is defined like this:

CREATE TABLE test_table ( id INT(20) NOT NULL AUTO_INCREMENT, name VARCHAR(32) NOT NULL DEFAULT '', other INT(20) NOT NULL DEFAULT '0', PRIMARY KEY (id), INDEX name (name), INDEX other_key (other) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

The example uses a MyISAM table, but the table could use any storage engine.

Next, create a FEDERATED table on the local server for accessing the remote table:

CREATE TABLE federated_table ( id INT(20) NOT NULL AUTO_INCREMENT, name VARCHAR(32) NOT NULL DEFAULT '', other INT(20) NOT NULL DEFAULT '0', PRIMARY KEY (id), INDEX name (name), INDEX other_key (other) ) ENGINE=FEDERATED DEFAULT CHARSET=latin1 CONNECTION='mysql://fed_user@remote_host:9306/federated/test_table';

(Before MySQL 5.0.13, use COMMENT rather than CONNECTION.)

The basic structure of this table should match that of the remote table, except that theENGINE table option should be FEDERATED and the CONNECTION table option is a connection string that indicates to the FEDERATED engine how to connect to the remote server.

Note:

You can improve the performance of a FEDERATED table by adding indexes to the table on the host, even though the tables will not actually be created locally. The optimization will occur because the query sent to the remote server will include the contents of the WHERE clause will be sent to the remote server and executed locally. This reduces the network traffic that would otherwise request the entire table from the server for local processing.

The FEDERATED engine creates only the test_table.frm file in the federateddatabase.

The remote host information indicates the remote server to which your local server connects, and the database and table information indicates which remote table to use as the data source. In this example, the remote server is indicated to be running asremote_host on port 9306, so there must be a MySQL server running on the remote host and listening to port 9306.

Tuesday, November 10, 2009

Using PHP Namespaces

PHP 5.3 introduces a much requested feature for object-oriented programmers: namespaces. At the time of this writing, version 5.3 of PHP was in development, but is planned on being released in the near future.

One of the purposes object-oriented programming is to remove ambiguous development and data access items. This basically means identifying common functionality and creating the most reusable framework possible, typically in the form of classes. When creating this functionality, you will begin to have issues with naming conventions and narrowing down functionality even further. To resolve this scoping issue, namespaces allow you to contain those bits of code even more.


It seems that PHP will be going with a similar namespace setup as C++. In order to declare a namespace, you will use the “namespace” keyword.

PHP
  1. namespace MyNamespace;
  2. class Test {
  3. public function hello() {
  4. echo ‘Hello’;
  5. }
  6. }
  7. ?>

The declaration above simply states that all elements contained in this script will be referenced with the “MyNamespace” namespace. You will need to place the “namespace” declaration at the top of the script.

In order to use a portion of functionality within this script, we will use the Scope Resolution Operator and instantiate the “Test” class.

  1. // Requiring the namespace file is a good indication that you don’t need to use namespaces, but this is only an example!
  2. require(‘the_file_above.php’);
  3. $test = new MyNamespace::Test();
  4. $test->hello();
  5. // Prints ‘hello’
  6. ?>

Monday, October 19, 2009

LAMP - Apache, PHP, MySQL Installation easy steps

Some like it binary some like compiling, I am amongst the compiling ones..
here are some easy steps that I usually follow to compile Apache, PHP to my machine.

  1. Apache
    1. ./configure --prefix=/usr/local/apache2.2.6 --enable-so --enable-proxy --enable-rewrite --enable-expires --enable-headers --enable-deflate --enable-ssl
    2. sudo make
    3. sudo make install
    4. cd /usr/local
    5. ln -s apache2.2.6 apache
    6. cd
  2. PHP
    1. ./configure --prefix=/usr/local/php5.2.5 --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs --with-pdo-mysql --with-gd --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib
    2. sudo make
    3. sudo make install
    4. cd /usr/local
    5. ln -s php5.2.5 php
    6. Configure Apache httpd.conf for PHP module
      1. LoadModule php5_module modules/libphp5.so
      2. AddType application/x-httpd-php .php .phtml