Thursday, April 13, 2017

what is generalization - Specialization

        Generalization and Specialization both are example of  Inheritance

Generalization and Specialization both are example of Inheritance both showing IS-A relationship.

When super-classes shared their features with different sub-classes is known as specialization. It is top-down approach in Inheritance

When more than one sub classes extract their common features and combine them in a one supper class is known as generalization. It is bottom up approach in inheritance
Specialization IS-A relationship

Example: 
Suppose we have a supper class “Person” it has two sub classes “Student” and “Teacher”. Now person having some common attributes like gender, address, age, etc. In general Student is a Person,Student also having the same common attribute of a Person and also some own personal attributes. So, that’s why we say Student IS-A Person or Students extends Person or Students Inherit the Person or Student become a child (sub class) of parent (supper class) Person. The same thing with teacher. Now this is showing Specialization, because a Super class Person shared their properties with Sub Classes Student and Teacher.

Now take same thing but in reverse order like say sub Classes Student and Teacher both having some common attributes, now we extract that common features from both sub classes and combine them to make a Super Class Person this is known as Generalization.
Specialization 

Association HAS-A Relationship

Generally, association is a ‘HAS-A’ relation. In simple word when one object is related to other object to use functionality and services of that object. So, these types of relation between two objects is known as association.

Association provides us one to one, one to many or many to one and many to many relationships between objects. Association has two special forms
o   Aggregation
o   Composition

Specialization

Aggregation
Aggregation is a special form of association and it is week relation of association. when an object ‘HAS-A’ another object, but both are independent to each other is known as an Aggregation.

For example
If we have two classes one is Studentand second is School, now if School is close, then Student still exist. It may change the school. Same way if Student leave the School, then may be another Student take the place of that student. So notice that they both are independent of each other this is known as Aggregation.



Composition strong relation

Composition is a special form of association and it is strong relation of association. when an object ‘HAS-A’ another object and any one object depend upon other object this is known as composition.

For Example:
If we have three Classes which are Human, Hand and Leg. Now in general Human Has-A hand and Human Has-A Leg. If a human has no Hand or has no Leg than that Human will be alive, but Human itself destroy than its Hand and Leg are also destroy because these parts depend upon Human. So notice that Human is independent Class and hand and Leg are dependent Classes. So, this type of association is known as Composition.

Example of Aggregation
We have two classes Employee and Address, Employee HAS-A Address.
Specialization

Address Class:


generalization

In address class I create three String objects city, state and country. Generally, every employee has an address so that’s why I create an address class with it constructor to initialize the value. In constructor I use this keyword, but be confused with this keyword. I will explain it in This Keyword section, right now just understand that This keyword refers the current instance of the class.

Employee Class

generalization



Saturday, December 17, 2016

variable and constant - PHP variable & constant where Use

variable and constant - PHP variable & constant where Use

Important thing about variable 

Let’s first understand that what is variable? or what do you mean by variable? In general term variable means change-able or the capability which storing some data is known as variable. The data may be a number, string, array etc.

Important thing about variable in PHP
·         Like other programming language PHP doesn’t having data types like. (int, float, char, string, array etc..).
·         Its data type will be identifying through its value, means what value you store in PHP variable then that value will decide what type of variable is that.
·         Syntax                  $variable_name
·         every variable in PHP will start with a ‘$’ sign and then follow by variable name


·         In above example I declare two variable $name and $age, $name variable contain string type value and $age contain integer type value. 
·         If you want to know its data types then use “gettype()” method it we show the datatype
·         If you want to know data type with its value, then use “var_dump($varaiblename)” method
·                                     

Types of Variables

There are three different types of variable in PHP

·         Local:    Those variable which are created within function or block of code known as local variable. Local variable will not access outside of the function or block of code because it scope is bound within that function or block of code in which they are declared


·         Global: Those variable which are created outside the function or block of code and are known as global variable. global variable will be access within function or block of code and also outside the function or block of code. If you want to access any global variable inside the function or block of code, then to do this you have to explicitly say that it’s a global variable for this you have to declare variable with global keyword inside of the function or block of code.
·         Example: without global keyword

·         Static:   Those variable which are declare as static is known as static variable. The purpose of these static variable is to access local variable after function execution complete. Let’s see the code you will understand this very well
·         
Note: static variable will occupy memory once so they are alive till the program execution once you declare a variable as a static then if you change its value then its will be saved with previous value.

PHP Constants:

·         In PHP constant is a name or identifier for a simple value, that constant value never during the execution of the PHP script.
·         Constant values are very useful only when we want that the value of variable is never change in entire program
·          It will be very useful when we connect our web application with any database, once we initialize the database name to our application then its name will not be changed again.
·         To create constant in PHP, we will use define() function.
·         Constants are naturally global; you will access them inside or outside of the functions
·         Syntax 
.  Define(name, value, case-insensitive)
.   name:                           Specifies name of the constant variable
.   value:                            Specifies value of the constant variable
.   case-insensitive:      Specifies name of constant should be case-sensitive, by default case-sensitive is false
·         Example:  of constant
·          


PHP Echo and Print
        . Echo and print these two are different built-in function in PHP
        . Both are used to display data on the browser
        . Syntax of echo:                 echo()   or            echo “”; 
          .Syntax of print:                 print()   or            print “”;
         .Echo statements support multiple parameter and it is non-return type function
         . Print statements support only single parameter and it is return type function
·      
 PHP Operators
The thing which is used to perform some operation on variables or values is known as Operators
PHP support following type of operators.
·         Arithmetic operators
·         Assignment Operators
·         Comparison Operators
·         Increment/Decrement Operators
·         Logical Operators

Arithmetic operators
Simple algebraic operators are known as Arithmetic operators

Operator       Description              Result
+              Add two variables         $a+$b
-              Subtract two variables   $a-$b
*            Multiply two variables    $a*$b
/             Divide two variables       $a/$b
%          of two variables               $a%$b

Assignment Operators 
It is same like arithmetic but after performing arithmetic between to variables it stores the result to left hand variable
Operator
Description
Result
=
It is used to assign value
$x = $y
+=
It will add two variable then result will assign to left variable
$x+=$y or $x=$x+$y
-=
It will subtract two variable then result will assign to left variable
$x-=$y or $x=$x-$y
*=
It will multiply two variable then result will assign to left variable
$x*=$y or $x=$x*$y
/=
It will divide two variable then result will assign to left variable
$x/+=$y or $x=$x/$y
%=
It will remainder two variable then result will assign to left variable
$x%=$y or $x=$x%$y

Comparison Operators
Comparison operators are used to compare the two variables by its value and also by its data types
Operator         Name        Example       Result
==             Equal to         $x == $y          Return true if both are equal
!=            Not Equal to   $x != $y        Return true if both are not equal
===           Identical       $x === $y      Return true if both having same value and same datatype
!==          Not Identical  $x!== $y       Return true if both having same value or same datatype
<>           Not Equal to   $x<>$y       Return true if both are not equal to each other
<            Less than          $x<$y            Return true if $x has value less than $y
<=    Less than or equal to   $x<= $y   Return true if $x has value less or equal to $y
>        Greater than                $x>$y     Return true if $x has value greater than $y
>=  Greater than or equal to  $x>= $y  Return true if $x has value greater or equal to $y

Increment operator is used to increase the value by one and decrement operator is used to decrease the value by one.Increment/Decrement Operators

Operator          Name                    Description
$x++          Post-increment      First print the value then increment by one
++$a          Pre-increment     First increment the value by one then print
$x--           Post-decrement      First print the value then decrement by one
--$x           Pre-decrement      First decrement the value by one then print

Logical Operators
 
Logical operators are used to valid the conditional statements

Operator     Name         Description
and              And             Return True if both variable are true          
or                Or                Return True if any one variable is true
xor              Xor               Return if either any variable is true not both
&&             And               Return True if both variable are true
||                  OR                Return True if any one variable is true
!                  Not                Return True if variable is false

 PHP Decision Making 
Decision making means make a suitable decision and execute that particular part of the program, so for decision making we use if, if else, if elseif and switch. Let’s understand these things in details

IF statements
When you want to execute the particular code then you can use IF statement, if statement is true then block of if statements will execute.
Syntax
                If(some conditions) {
                                Statements
                                statements
                }
IF Else statements
If “if statement” is true, then if statement block will execute otherwise else block will execute
Syntax
                If (some condition) {
                                Statements
                } else {
                                Statements
                }

IF ElseIf Else statements
It contains multiple if conditions, if any if statement is true the if that respected if block will execute otherwise else block will execute 
Syntax
                If (some condition) {
                                Statements
                } elseIf (some condition) {
                                Statements
                } else {
                                Statements
}
                                                                
Switch Statement
Switch statement is also used for decision making. It works same like “If Elseif Else” statement. In switch statement multiple case are defined, if any case match with user input then that matched case will be execute. If none of case will execute then default will execute. Default work like else block.

Syntax:
                Switch (input) {
                                Case n1:
                                                Statements;
                                break;
Case n2:
                                                Statements;
                                break;
Case n3:
                                                Statements;
                                break;
                                . . . . . .
                                default:
                                                Statements;
               

}  

Wednesday, December 14, 2016

use php - what is php & Easy Tutorials learn

Define PHP Simple understand & Easy Tutorials learn

 what is php
   . PHP stand for “Hypertext Pre processor”
   . Rasmus Lerdorf is known as the father of P H P (1994)
   . The old name of P H P is “Personal Home Page”
   .  Personal Home page is a software tool which is written in C programming language, this tool is        used for tacking online visits resume
   . Rasmus Lerdorf study on this tool and rewrote same tool with richer implementation
   . In 1994 he produces this model with name “Hypertext Pre processor” and its acronym is P H P.
    .In that time P H P is able to integrate with Database and build dynamic web application.
   . In June 1995 Rasmus Lerdorf released the source code for P H P Tools to the developers for testing.
   . In April 1996 introduced P H P.F I (Forms Interpreter) this is enhancement of past model, then time  to   time they released some other source codes for P H P
    .In 20 Oct 1999 Rasmus Lerdorf with his team released First version known as P H P 3
     . P H P is used to develop dynamic web application 
    .P H P is server side Script language
    .Through this Server side Script language, we will develop dynamic web application, managing the .dynamic content, databases etc.
    .P H P is easy to use, it will be easily embedded in HTML. 
 what is php & Easy Tutorials

Version

Version
Released Date
PHP 3
20 Oct 1999
PHP 4
22 May 2000
PHP 5
13 July 2004
PHP 7
03 Dec 2015

These version contains sub versions for more details please visit P H P official website
http://teachmeprograme.blogspot.com

Environment Setup


P H P is most popular server side script language which is used to create dynamics web pages or applications, in this section you will learn that how to create dynamics web pages or applications using P H P. As I’m suggesting you before start PHP web development you will have complete knowledge of HTML, C.S.S and JAVA SCRIPT so that P H P development will become easy for you to learn. use php

As we know P H P is a server side script language so to execute any P H P program you need web Server, so I’m going to recommend you following programs, install in your local machine and access the P H P environment .use php & Easy Tutorials

·         The Apache Server (http://httpd.apache.org/download.cgi)
·         The MySQL Database Server (http://www.mysql.com/downloads/)

Install above two program in your local machine then you will be able to execute any P H P program. There are also other ways to access P H P environment in your local machine, I’m going to recommended some of them

·         XAMPP server (https://www.apachefriends.org/index.html)
·         WAMP server (http://www.wampserver.com/en/)

XAMPP and WAMP both are web servers; their job is to get web development environment in your local machine. Both are allowing you to create dynamic web application using PHP. Both server contains Apache server, PHP and MySQL database and both servers provide you MySQL database administrative tool which is Php My Admin. PhpMyAdmin will help you to manage your databases using web browser.

what is php & Easy Tutorials

So I’m preferring you to install XAMPP or WAMP server in your local machine rather than install individually Apache server and MySQL database in your local machine. Once you successfully install XAMPP or WAMP server in your local machine then a shortcut of respected server will be created on your desktop, as I installed XAMPP server on my local machine so I double click on XAMPP server control panel shortcut it will look like this:

Start Apache and MySQL
what is php & Easy Tutorials

PHP first Program


Assume you install XAMPP server in E Drive then go to E Drive > xampp > htdocs
Like that:             E:\xampp\htdocs

Htdocs is your main directory where you will create all your PHP dynamic web projects so inside this folder create new folder, then gives suitable name to that folder as you want as for my concerned I’m giving the name “phpdemo” to my folder.

Inside this (phpdemo) folder I’m creating a file with name hello.php

·         Note: (hello is the name of my file and .php is then extension of PHP file)
·         Tip: (whenever you create any PHP file, whatever the name you given but in last you must give the .php extension).
      use php - what is php

Now my directory looks like this:
·         E:\xampp\htdocs\phpdemo\hello.php
·         E drive > xampp > htdocs > phpdemo > hello.php

URL:       http://localhost/
Now this URL directly access your htdocs folder so now type folder name you create inside the htdocs folder as I created “phpdemo” folder so I’m write phpdemo after localhost so my project URL Look like this
URL:       http://localhost/phpdemo
what is php & Easy Tutorials



This project directory will display you all your project files and holders which you will create as for now we create just one file with “hello.php” so it displays the same file now click on “hello.php”, then output will look like this:

Now as you notice nothing is display because we just create file not write any piece of code, so now go to any text editor as you feel comfortable with that and type that code as you shown in below image

Now save your file and refresh the browser

PHP syntext

Syntax
·         Syntax                  <?php….?>
·         you can write PHP code between <?php and  ?>
·         you can write PHP script anywhere in the php file as you want
·         you can also write HTML code inside the PHP file


·         everything inside the PHP script is known as statements, every statements will end with semicolon (;)

PHP Comments
o   Comments are used to provide description of respected statements
o   Comments are not read by server
o   Single Line Comment
§  Double slash “//” is used for single line comment
§  Hash “#” is used for single line comment
o   Multi Line Comment
§  “/*….. */” is used for multi-line comments
·         PHP is Case sensitive only with VARAIBLES
·         PHP is not case sensitive with all keywords, classes, functions etc
·         Below I’m giving you example which is related to Comments and Case sensitivity

Note: in output it shows error on line number 26 and 29 that Undefined variables so if we look at the code I just create one variable “$color”, in echo statements I writes $color, $COLOR and $CoLoR so from this it’s clear variable are case sensitive and other thing except variable are not case sensitiveso if you look at echo statement I write echo in three different ways i.e. (echo, ECHO, EcHo) but output is same.
use php - what is php what is php & Easy Tutorials