RGU:Software Development Society

0010101011110011010101010110000111 { Learning Programming; }

By: Ahmed Sammy Hegab founder of umicom.com

Introduction I've created this short course for the absolute beginner someone who has no idea about software development but is keen to learn, we will cover the main fundamental principles of programming Why Learn Programming? You may have your own personnel reason but here is a few I thought of myself • • Learning a programming language can be fun specially when you start seeing your development come to life It can be financially lucrative as technology advances with the likes of iPhone development, Android and new web technologies you can potential sit at home create a new App and see it bring in few hundred to few thousand every month while you sleep. Learning Programming can really benefit you in your journey of personnel development, to write code you have to be a good planner, creative, methodical, patient, problem solver and many more..

RGU:Software Development Society

- Introduction to programming - Ahmed Sammy Hegab

Introduction to programming .. the fundamental building block in C is exactly the same across all languages as they all inherited from C language. C/C++. for example PHP is a very good easy to learn web development scripting language. C.Ahmed Sammy Hegab . What is common across all languages? The common between all languages is the C language. which was developed first then shortly after they introduced the Object Orientated concepts and called it C++. etc. unlike PHP which can run on free Open Source Apache Server. if an error occurs it stops at the line with the error. For this reason some recommend learning C language first. 1.e. so which one should you learn.NET frameworks making it a very powerful language used in developing advanced applications main strength for developing windows based applications. However from this course we will cover the concepts more than writing codes which once you understand programming concept everything else should start to become easy and with this knowledge you can pick up other programming languages with speed. Non-Object programming languages can be interpreted or compiled this is also common in Object Programming language too. C#.Which Language should I learn? There are hundreds if not thousands of programming languages out there. are examples of what is known as a procedural languages or linear programming languages. its most common for most of the websites JAVA is great for network programming and now its the language for Android development and if you want to get into iPhone Development then you must know Objective C C++ is universal one of the oldest Object based languages which is in much use today across all fields. Objective C. An Interpreter type – Executes one line at a time. you can also develop web applications but they will need to run on a Windows based server which can be expensive. more on Object and non Object languages little later Then comes C# a Microsoft creation simplifying C++ language and enriching it with . Difference in programming languages We will cover the differences then you can start to class languages based on their types Non-object programming languages I. For this reason I will give you a quick intro in the main five programming languages. Pascal. A Compiler type language – Converts all the source code into mainly binary format then runs or in the case of a language like JAVA it converts into Byte-code which gets executed with a JVM (Java Virtual Machine) RGU:Software Development Society . JAVA and PHP In general each language was developed for a specific purpose.

it will make sense when we start to go through programming building blocks but for now all I want you to know is when ever you see an open '{' you will have the end of block curly brace '}' The Quotation Marks ( “ ' ) In programming most strings of text are surrounded by quotation marks you can use single or double they have the same purpose but different effects depending on the purpose you use them for for the moment all I want you to remember is when ever you open a “ you must have an end “ of same time and if you wanted to for example to print out a “ you if you simply write “ “ “ it would cause an error because the compiler or interpreter will find the start of quote and end of quote then complain about the third quotation mark with no end. RGU:Software Development Society .write a block comment here -.Ahmed Sammy Hegab . Comments ( \\ /* */ # <!-. those comments will be ignored and have no effect on the actual program when executed. Escape Character ( \ ) For the case of quotations or having the program to ignore an effect of any kind of character you would use the escape character '\' for example “ \” “ the program will ignore the middle quotation mark.' The Curly Brace ( { } ) You will see the open curly bracket this would be start of a block of code. Just like when we end a sentence with a period.--> ) Comment characters can be used in the code as a way to leave comments for other programmers and yourself. full stop '. In most programming languages a single line comment is \\ followed by the comment if you want to leave a large block comment then you would include it in /* write a block comment */ Html comments would be between <!-.--> <!-.Introduction to programming .> Perl uses # hash symbol for comments so if you ever end up looking at a Perl script and find the # now you will know its only a comment.Programming Grammar (Syntax) Just like any language there are some fundamental grammar in programming we need to adapt to inorder for our instructions to execute. ) In all programming languages we end with a semi colon '.' The Semi colon ( .

4956 etc. int is the data type-array x is the variable name 5 is the value incase of reference type (pointer) RGU:Software Development Society . just imagine a box that contains certain type of object in computer memory.c or any other keyboard character. What ever value we assign it. String is a collection of characters. words and would include spaces too etc.b.Variables A variable is basically a container.Introduction to programming . decimal numbers). 2.Ahmed Sammy Hegab .5. which is known as an array. this can be a number. More on Data Types Char means Character data type for example a variable that would hold characters like a. we simply put a $ dollar sign in front of a word and it becomes a variable name. As an example of what variables look like in PHP is as follows $i. The main value types we will cover are different types of numbers (whole number. boolean values (true/false).2. Please note the only languages which we would be covering in this course that does not need any declaration of data type is PHP the web scripting languages. decimal..3 and in the above statement we are declaring the 'i' to be a variable that would hold whole value numbers. Boolean or bool take up the value of true or false All the above are common examples of primitive data types User defined data type The other data type is user defined data type also known as reference type (pointer) lets look at the difference between a normal variable data type and a pointer int x =5. a string or characters and we will look into all the kind of values and objects a variable can hold as we progress in the course. double.. It is also good to give meaningful names when creating variables. int means integer which is whole number value type such as 1. 5. Variables can be any name as long as they start with letters and not numbers. When declaring a variable you would define its data types that you intend for it to hold. characters.99. strings and we will also cover a variable that contains several values of a certain value type. float are decimal point numbers such as 1. it will take that value type dynamically. for example int i.

int * p=5. $s). PHP echo (“The salary is”.Ahmed Sammy Hegab . which basically means p is a pointer which points to the value in memory Dynamic data structures Other than the usual primitive data types and pointers we can also create all sorts of dynamic data structures such as: 1. C# System. if (condition) { do something….s).s). Objective C NSLog (@”The Salary is %d \n”. ELSE and ELSE IF If statement is used to test for a condition. Linked List ( each node will hold data and pointer to the next node) 4. Stack (FILO = First in last out) 2. Double Linked List ( each node will hold data and pointer that points both ways) 5.Console. 1.out. Queue (FIFO = First in First out) 3. 6. 3.h library file or use the following) cout <<”The Salary is “<<s. if the condition is true do something else if not do something else. Circular linked lists ( a chain of nodes) For the moment we are taking an overview and we will cover more of these concepts in a more advanced course. 4. 2. We will briefly introduce it now and then elaborate further later on.Introduction to programming .s). } else { do something else … } RGU:Software Development Society .. Now we covered some basic concepts lets now look next at printing on screen results and then we can dive into the fundamental building blocks also known as program constructs. What are the programming building blocks? Building blocks in programming also known as programming constructs which are common in syntax in all programming languages are really just four. Java System. C Printf(“The salary is %d \n”. C++ (you can use the same as c depending if you include in your project stdio.writeLine(“The Salary is {0}”. Printing results to screen 1. Conditions : The IF condition.println(“The Salary is “+S). 5.

do something break. i++) { do something. i<5.} 3.until ' i ' is not less than 5 } 2.. 1.. case 2: …. While loop : while a condition is true do something While ( x<10) {… do something and until x is not less than 10. Do { …... so for each array element do something y={1.Introduction to programming . print the exception or do something to continue with program . For loop for (int i=0.... Loops We have four different types of loops we can use in our program which perform a repeat of a block of code a number of times while a condition is not true.Ahmed Sammy Hegab . } 4. do something break. switch (x) { case 1: …. in php it would be $x=4. default: …. case 3: …. Do …. Exceptions (Error Handling) try { do something like try connect to database } catch (exception e) { . While loop Do while loop is very similar to the while loop but just opposite way of doing test.2.7}.5.2. it will execute a block of code then test for condition at the end. foreach (int x in y) {… do something } 3.} RGU:Software Development Society .do something … } while (x <10) 4.. do something break. Foreach loop Used with an array list or database entries. int x = 4. do something for a default break. Switch / case statement One of the four cases can be true otherwise do some default case.

while it can be true in the fundamental building blocks (the non object coding) it is not true for the Object programming syntax as it is completely different. RGU:Software Development Society . very simply Object Language is procedural language + Object Orientated Concepts. Objective C the languages used for Apple Mac. Object Language fall into the same category of either an interpreter based language or a compiler based language. one will take in hours worked and wage_per_hour and other Get-salary takes in four parameters I. iphone.Ahmed Sammy Hegab . length. Everything can be classified as an object. make. Overloading Overloading is when you overload a method with a different signature lets assume we have two methods which are both called Get-salary. weight The function of the pen is it writes.Introduction to programming . Encapsulation We already mentioned that encapsulation is the very nature of an object (The encapsulation of properties and methods (function or procedures). Object Orientated Concepts There are five main concepts in object orientated programming languages which we will briefly introduce and discuss further in the course 1. for example a Pen is an object The properties of a pen can be the colour. The concept of programming is the same only the implementation of Object concepts can be different and we will look into that in more detail as we progress in the course. While you might be thinking C++ is the same as Objective C so learning one of those languages would be sufficient to program in both. 3. For example like I mentioned before about C language plus Object concepts is C++ language. 2. ipad development is also just C Language plus Object concepts. What is an Object? An object is simply the encapsulation of properties and methods. Inheritance Inheritance is when an Object inherits some properties / methods or characteristics from another Object which is known as a super class or a parent object. this purpose is what we term as the method Methods can be a function when it is required to return a value when executed or it can be a procedure if it just performs a task and does not return a value.e.What is Object Orientated Programming Language? Before we dive into programming building blocks (which is common across all major programming languages) lets first get a brief overview of what is Object Orientated Programming Languages. it can also take in overtime_hours and overtime_rate.

double s=e1. Polymorphism An Instance of an object taking many forms. // constructor e1.Introduction to programming . for example lets assume for an employee we take in the hours worked and multiply it to the hourly-rate but in the came of a manager we also add a bonus amount. C# & C++) Public class employee { public int employee_number. Overriding Overriding is using same method which we inherited from a parent object but the way we do the calculation would be different. public double getSalary(int hour.getSalary(40.employee_number=5. C#. 5. Object Orientated Programming : Encapsulation We will demonstrate the concept in five different languages. public string employee_name. e1. } } Note ** In C++ the difference is simply we add a semi-colon at the last curly brace }. C++) Public static void main() { employee e1 = new employee(). for example Manager object taking characteristics of an employee or creating a manager with an employee object.25).20.employee_name=”bob. double rate) { return hour * rate. // Put printing statement here based on the language you are using } RGU:Software Development Society .4.Ahmed Sammy Hegab . Creating an Instance of the Object (constructor in Java. so lets get started :) Creating an Object (JAVA.

RGU:Software Development Society . [e1 employee_number:5]. [pool drain]. $rate) { return $hour*$rate. [e1 release].Introduction to programming . $employee_name. function getSalary($hour. [e1 employee_name:@”Bob”]. } Creating Object in PHP <HTML> …. double s=[e1 getSalary:40 andRate:20.Creating Object in Objective C @interface employee:NSObject { int employee_number. } -(double) getSalary:(int)hour andRate:(double)rate. string employee_name.25]. NSLog(@”The salary is %d””. <BODY> <? class employee { $employee_number.Ahmed Sammy Hegab . s). employee *e1=[[employee alloc] init]. return 0. @end @implementation employee -(double) getSalary:(int) hour andRate:(double)rate { return hour * rate } @end Creating an Instance of the Object (constructor in Objective C) int main() { NSAutoreleasepool *pool:[[NSAutoreleasepool alloc] init].

Introduction to programming .Ahmed Sammy Hegab .} RGU:Software Development Society .

echo (“The salary “. </BODY> </HTML> Object Orientated Concept 2: Inheritance (C++. $s=$employee->getSalary(40. } C++ public class manager::employee { public double bonus. RGU:Software Development Society . } In the above we are basically saying that this new object type called manager inherited everything from employee plus a manager has the property called bonus.Creating an Instance of the Object (constructor in PHP) $employee = new employee(). C#.Introduction to programming . ?> …. PHP) Lets assume we will create a new object called Manager and a manager has all the characteristics of an employee because a manager is an employee Java public class manager extends employee { public double bonus.$s). }. because only managers get bonus ontop of salary.Ahmed Sammy Hegab ..25).20. Java. } C# public class manager:employee { public double bonus. $ename=$employee->employee_name=”Bob”. PHP class manager extends employee { $bonus. $eno=$employee->employee_number=5.. OBJECTIVE C.

Ahmed Sammy Hegab .Introduction to programming .RGU:Software Development Society .

double overtime_rate) { return hour * rate. } Depending on the signature the users passes then the program will select the appropriate method to use. double rate) { return hour * rate. for example public double getSalary(int hour. public string employee_name. } public double getSalary(int hour.Objective C @interface manager:employee { double bonus. double rate.Introduction to programming . double rate) { return hour * rate+bonus. double rate) { return hour * rate. public double getSalary(int hour. // notice here we add bonus when calculating getSalary } RGU:Software Development Society . } @end Object Orientated Concept 3: Overloading Like we explained before overloading is when you have one or more objects with the same method except for the signature.Ahmed Sammy Hegab . public double getSalary(int hour. int overtime_hours. Object Orientated Concept 4:Overriding Like overloading we will use identical method name but this time we will have getSalary in employee exactly same as getSalary in manager Public class employee { public int employee_number. } } Public class manager extends employee { public double bonus.

Introduction to programming .} RGU:Software Development Society .Ahmed Sammy Hegab .

emp2=new employee(). Here we will learn the common used SQL commands/keywords – Create a database in SQL create database staff. we will briefly look at database SQL language (Structured Query Language).emp2. in java.man4.Introduction to programming .emp3. emp1=new employee(). man4=new manager(). RGU:Software Development Society . php. employee_address text. employee_name varchar(20). emp2. emp3=new employee(). c++. “Sammy”. – To add records to the table we just created insert into employee(001.emp3.Ahmed Sammy Hegab . primary key(employee_id)). the database we just created called staff) use staff. } Database basics (SQL) Now we briefly covered the main concepts in programming.Object Orientated Concept 5:Polymorphism Poly means many so here we can have an object taking many forms as it goes through stages the best way we can understand this is an employee can become a manager and then can be promoted to director. – To select a database (I. “65 Naylor Road”). – To see existing databases show databases. Lets assume we have two objects. // now we will create instances of the emp1. an employee object and a manager object which inherits from employee object public static void main() { employee emp1. – To create a table create table employee(employee_id int.e.man4. c#. objective c and other languages you can write programs that will communicate with a database system and you can also pass SQL commands.

You should now be able to create a basic object in Java. Basic programming syntax I. – Deleting unwanted records delete from employee where employee_id=1. Learning Objective C. – To update a record in the table update employee set employee_name = “Imran” where employee_id=1. C#. – To delete the whole table and/or delete the whole database we can use the following drop table employee. Basic Database commands Now you can proceed to learn any specific language with the basic background in general programming you been taught. compiler. Learning JavaScript and many more titles to come soon. Programming Constructs 4. 3. – Assuming we wish to drop just part of the table for example we no longer need to hold National Insurance information we can use the following statement alter table employee drop NI. The five Object Orientated Programming concepts 5.. Objective C and PHP 6. I will soon create other course titles such as the following.– If we want to see all records select * from employee – To add an extra field to the employee table alter table employee add NI varchar(10). C++. object and non object languages. RGU:Software Development Society .Introduction to programming .e. Learning Java. What you should know 1. Learning PHP. The difference between types of languages interpreter. Learning Python. drop database staff. – Lets imagine we hold accumulated hours worked in the table and we want to list only the employees that have worked over 1000 hours at the company since they started we can do the following select * from employee where total_hours_worked > 1000.Ahmed Sammy Hegab . Learning C++. { } // . 2. please contact me to express your interest Learning C..

Ahmed Sammy Hegab .Introduction to programming .umicom.com/softwaredevelopmentsociety Or you can email on admin@umicom.Add me on www.com or visit www.com RGU:Software Development Society .facebook.

Sign up to vote on this title
UsefulNot useful