20
A Programme Under the Compumitra Education Series Copyright 2012-14 © Sunmitra Education Technologies Limited, India Programming Fundamentals "Fun of programming doubles if the fundamentals are crystal clear."

Programming Fundamentals In Context of Java - Android

Embed Size (px)

DESCRIPTION

This presentation gives you various types of programming models, A clear concept of object oriented languages, Classes and Object Concept, Different types of programming paradigms, program tokens, statements, expressions, Concepts of Inheritance, Encapsulation, Abstraction, Polymorphism, Interface etc.

Citation preview

Page 1: Programming Fundamentals In Context of Java - Android

A Programme Under the Compumitra Education SeriesCopyright 2012-14 © Sunmitra Education Technologies Limited, India

Programming Fundamentals

"Fun of programming doubles if the fundamentals are crystal clear."

Page 2: Programming Fundamentals In Context of Java - Android

OUTLINE

Programming ConceptsProgramming LogicProgram RunningComponents of a ProgramProgramming ParadigmsStructured ProgrammingObject Oriented Programming InheritanceEncapsulation and AbstractionPolymorphism and

Overloading InterfaceBibliography

Page 3: Programming Fundamentals In Context of Java - Android

Programming Concepts - 1

Computer Programming: It is a predefined way of telling the computer that what task is to be performed. It is the implementation part of the activity of "SOFTWARE DEVELOPMENT"

Computer Program: It is a set of sequence of instructions, that a computer will understand and try to execute. One or a related set of computer programs may be called a "COMPUTER SOFTWARE"

Page 4: Programming Fundamentals In Context of Java - Android

Programming Concepts - 2

Computer Languages (Full-Fledged):

High Level Programming Languages: Usually English Like Instruction set with a power to build application logic. Usually have an extremely strict syntax rules. e.g. C, Java, C++, C# etc.

Low Level Programming Languages: Set of Hardware related Mnemonics for direct control over processing and input/output functions. E.g. Assembly Language

Page 5: Programming Fundamentals In Context of Java - Android

Programming Concepts - 3

Computer Languages (Specific Purpose):

Formatting and Interface Languages: Languages made primarily for the purpose of User side rendering of information. E.g. HTML, DHTML, XML Etc.

Data Query Languages: Languages to get and post to structured system of records called a database. SQL etc.

Data Definition Languages: Languages to define properties of Data or any type of content items. E.g. XML Schema (XSD), SQL-DDL (create table etc.)

Page 6: Programming Fundamentals In Context of Java - Android

Programming Logic and Algorithm

Logic/Algorithm: Formulation Involved in performing a task. For e.g.◦ Fahrenheit to Celsius Conversion

Formula.◦ Writing of Data in a file one character

at a time or one block at a time.◦ Compression of image file to a smaller

size file.◦ Method of following a protocol such as

the HTTP protocol.

Usually these words are interchangeably used but the word algorithm is more suitable for specific tasks now performed as a routine for e.g. image compression is more appropriately called algorithm while writing to a file may just be called a simple logic.

Page 7: Programming Fundamentals In Context of Java - Android

Program Running

Interpretation: ◦ Process of parsing the program

instructions one by one so that it directly produces the desired output.

◦ For e.g. Javascript is interpreted at the browser to run the given functionality.

◦ Errors in the program code are caught at the time of running the program and are likely hinder application workflow.

Compilation: ◦ Process of parsing the program

instructions in one go and produce an intermediate file that can be directly run by the host system.

◦ Errors are required to be removed before compilation is successfully completed.

◦ Application workflow is usually not hindered as basic errors are removed initially. Only unexpected input conditions produce errors.

Page 8: Programming Fundamentals In Context of Java - Android

Programming Instruction Types (Based on Its Purpose)

The Primary Purposes of Programming Instructions are.◦ To take Input.◦ To give Output◦ To perform operations.◦ To run a program section

based on a condition selection.

◦ To repeat a section of code based on condition.

Think that a computer is a generic machine that can emulate other machines based on the program it runs.

INPUT

OUTPUT

OPERATE

SELECTIONREPETITION

Page 9: Programming Fundamentals In Context of Java - Android

/* A Sample Java Program */package com.mycom.appimport java.util.Scanner;

public class Tokens

{

public static final String s = "Java";

public static void main(String[ ] args)

{

int i;

int Sum = 0;

int num ;

Scanner in = new Scanner(System.in);

System.out.print("Enter a no.");

num = in.nextInt();

for (i = 1; i<= num; i++)

{

Sum = Sum + i;

}

System.out.println("Summation of "+num +" is :" +Sum);

}

}

Keywords: The instruction word used in a certain language. For eg. public, class, int, for, static, final, void, while etc.

Literals: User provided strings or numbers etc. Literal do not change.Operators: Things like

+, -, *, /, I , &, ^ etc.

Identifiers: User defined data item or function names etc.

Constants: Value defined using final keyword.

Separators: Things like { }, ( ), [ ] , ; etc.

Comments: Text not to be processed.

Programming Components (Tokens)

Package: Collection of related classes that are unique and in the same scope of usage.

Page 10: Programming Fundamentals In Context of Java - Android

Programming Terms

Statements: The actions that a program takes are expressed as Statements. ◦ Declaration and Assignment (int a=0;)◦ Expression (area = 3.14*(radius*radius); )

◦ Selection or Iteration (if, switch, do, for etc.)

◦ Jump (break, continue, return etc.)Expressions: A sequence of one or more

operands and zero or more operators that can be evaluated to a single output.◦ ((x<10)&&(x>5))||((x > 20)&&(x < 25))

Page 11: Programming Fundamentals In Context of Java - Android

Programming Paradigms

Declarative:  What computation should be performed and not how to compute it.

Imperative (requiring attention): That define sequence of tasks to control flow of computational algorithm.◦ Non-Structured: Allows Jumping randomly by line

numbers or labels. E.g. Basic, Assembly, Cobol, Batch Files.

◦ Structured: Use only sequence, selection(condition) or iteration(loop) methods to provide instructions. E.g. C, C#, Java etc.

Page 12: Programming Fundamentals In Context of Java - Android

Structured Programming Models

Procedural:  Grouping of series of instructions as a procedure (routine, function, subroutine, method, module) that can be called from multiple places to undertake the same task again.

Object Oriented: Allows to define templates generally called classes, similar to real life definitions that encapsulates various properties and methods. For. E.g. real life template “CAR” would mean properties like: Colour, Body Style, Fuel Type and Methods like: Driving( ), Changing Gears( ), Opening( ) Doors etc.

The physical interpretations like MARUTI-ALTO, HONDA-CITY, HUNDAI-SANTRO, TATA-NANO are understood as the objects of the class CAR. Thus the name has been given as object oriented programming or OOP.

Page 13: Programming Fundamentals In Context of Java - Android

Object Oriented Programming

Class:  A template definition of data items(properties) and actions(Methods). For Example the Diagram of CAR can be a real world metaphor to a class.

Object:  The physical item based on the class definition is an object. For Example the real CAR would be an Object. So one can say Objects are instances of Class.

It is clear that one can have any number of instances as the physical space permits.

Page 14: Programming Fundamentals In Context of Java - Android

Instance Creation Example

In a real programming situation instance are often created by using the "new" keyword.

Instances which are now called objects can directly call any methods of the class.

14

public class Book{

public int bookNum; public void setNum(int Num){ bookNum =Num;}

public static void main(String[ ] args){ Book myBook=new Book(); myBook.setNum(2); System.out.println("Num of book:"+myBook.bookNum); }}

Page 15: Programming Fundamentals In Context of Java - Android

OOPS - Inheritance

Inheritance:  One can observe that even the template definitions have more definitions of categories within a template. For . E.g. Definition of a "Car" can be the main template and Definition of a "Small_Car" will be as such a category with in "Car" .

It is clear that the definition of a "Small_Car" will have all the definition items included in the definition of a "Car" . So we can say that class "Small_Car" can be inherited from its parent class "Car" . More properties may follow in the definition of "Small_Car" Class Car

Class Car

Class Small_Car

Class Big_Car

Page 16: Programming Fundamentals In Context of Java - Android

OOPS – Encapsulation & Abstraction

Encapsulation: It is the way where actual methodology of achieving a result is hidden from the external world users. For e.g. we can define a class CAR as follows.Class CAR{property colour;Method Steering(turn){if turn is anticlockwise make the front wheel go left;if turn is clockwise make the front wheel go right;}}Here we see that method Steering( ) is actually hidden behind the class CAR and details of the method are hidden to the external world and whenever the designer wants he can change the design of achieving the goal of turning the steering handle. This is called ENCAPSULATION.

Page 17: Programming Fundamentals In Context of Java - Android

OOPS – Encapsulation & Abstraction

Abstraction: In previous example we can see that user is only required to know about turning the steering and he is not required to bother about internal system of turning a wheel. So we can call the Method Steering is as such an ABSTRACT method made by ENCAPSULATING the action that is taken when turning is done. The purpose would be an abstract method would be distinctly different from any other method of the class CAR. The purpose we achieve out by encapsulation is called ABSTRACTION.

Page 18: Programming Fundamentals In Context of Java - Android

OOPS: Polymorphism Polymorphism:  Values of different data types to be handled using a

uniform interface . For e.g. if we assume PedalPush( ) to be method in the class CAR then this method can actually be behaving in a polymorphic manner if the data parameter type are different, a Clutch, a Brake or an Accelerator.Class CAR{ property WheelSize; Method PedalPush(PedalTypeClutch) { Detach Engine Rotor from Wheel Rotation Rod; } Method PedalPush(PedalTypeBrake) {

Initiate Brake Fluid to Brake Drum; } Method PedalPush(PedalTypeClutch, PedalTypeAccelerator) { Control Speed of the Car; }}Overloading can be based on parameter type or number of parameters as is obvious from the above example.

Page 19: Programming Fundamentals In Context of Java - Android

Bibliography

http://en.wikipedia.orghttp://www.landofcode.com http://msdn.microsoft.com http://www.tutorialspoint.com/

java

Page 20: Programming Fundamentals In Context of Java - Android

THANK YOU…

Ask me and guide me at [email protected].

Share this information with as many people as possible.

Keep visiting www.sunmitra.com for programme updates.