You are on page 1of 17

INTEGRATIVE PROGRAMMING AND

TECHNOLOGIES
(ITec4121)

CHAPTER ONE
INTRODUCTION TO INTEGRATIVE
PROGRAMMING
Introduction

 A language is a structured means of information exchange for


our purposes
 A language can have the forms of spoken , written, visual and
etc.
 Types of Languages:
1. Natural (Semantic) Languages: English, Afan Oromo,
Amharic, etc.
2. Computer Languages
Binary & Assembly
Compilers & Interpreters
Programming vs. Scripting Languages
2
Compiled and Interpreted languages

 There are thousands of programming languages in this world.


 Programming languages can either compiled or interpreted
 Compiled Language:
 It is a programming language that has compiler which
compiles the source code to native code.
 Compiler parses the instructions into machine code and stores
them in a separate file for later execution.
 Examples of compiled languages are:
C, C++, Objective-C etc.

3
Compiled and Interpreted languages…

 Interpreted Language:
 It is a programming language that has interpreter which
executes instructions directly without compiling a program 
 Examples of Interpreted languages:
 PHP, VBScript, Jscript, etc.
Note:
 Hybrid languages uses both compiled and interpreted languages:
 For examples:
Java, C#, VB.Net, Pyhton, etc
 For every compiled language, an interpreter can be built but the
reverse is impossible. That is, all the interpreted languages cannot
be a compiled language.
4
Compiled and Interpreted languages…

 Advantages and Disadvantages:

Compiled Interpreted
Advantages Disadvantages Advantages Disadvantages

Ready to run Not cross-platforms Cross platform Interpreter required

Often faster Inflexible Simpler to test Often slower

Source code is private Extra step Easier to debug Source code is public

5
Programming Languages vs. Scripting Languages

 A programming language (C, C++, Java) is a language that


provides some means for the programmer to talk directly to a
computers hardware.
 High level programming languages do not allow a programmer
to talk to the hardware directly.
 Low-level programming languages (like Assembly) allows a
programmer to talk to the hardware directly.
 A scripting language (PHP, Python, JavaScript) by contrast only
allows the programmer to create code that will talk to another
existing program or application.
 NOTE: All scripting languages are high-level languages.

6
Programming Languages vs. Scripting Languages…

 Scripting language is designed as integrative language.


 Scripting Languages are classified as server-side or client-side.
 Server-side Scripting Language:
 Can use huge resources of the server
 Complete all processing in the server and send plain pages to the client
 Reduces client-side computation overhead
 Examples: ASP, ASP.NET, JavaScript, PHP, JSP, Java Servlets, etc.
 Client-side Scripting Language
 Does not involve server processing
 Complete application is downloaded to the client browser
 Client browser executes it locally
 Adds functionality to web pages e.g. different menu styles, graphic
displays or dynamic advertisements
 Examples: JavaScript, PHP, HTML, XML, Java Applets ,etc.

7
Generic types and generic (parameterized) programming

 Java Generics is a language feature used to define classes and


methods that are implemented independently.
 Java Generic methods and generic classes enable programmers to
specify, with a single method declaration, a set of related methods
or, with a single class declaration, a set of related types,
respectively.
 It is also used to define types and algorithms that apply in
different contexts.
 Generic types are instantiated to form parameterized types by
providing actual type arguments that replace the formal type
parameters.

8
Generic types and generic (parameterized) programming…

 Syntax to use generic collection:


Class or Interface<Type>   
 Example: Consider the use Generics in java:
ArrayList<E>
is a generic type that has a type parameter E.
 Instantiations:
ArrayList<String> or
ArrayList<Integer>
are called parameterized types where String and
Integer are the respective actual type arguments.

9
Generic types and generic (parameterized) programming…

 Before generics, we can store any type of objects in non-generic.


 Generics forces the java programmer to store specific type of
objects.
 Advantage of Java Generics:
 Type-safety : holding only a single type of objects in generics
& it doesn’t allow to store other objects.
 Type casting is not required: no need to typecast the object.
 Type casting is done before Generics:
Example:
List list = new ArrayList();  
list.add("hello");  
String s = (String) list.get(0) ;//typecasting  
10
Generic types and generic (parameterized) programming…

 After Generics, typecasting of an object is not allowed.


List<String> list = new ArrayList<String>();  
list.add("hello");  
String s = list.get(0);  
 Compile-Time Checking: checking the problem at compile
time so problem will not occur at runtime.
List<String> list = new ArrayList<String>();  
list.add("hello");  
list.add(32); //Compile Time Error  

11
Generic types and generic (parameterized) programming…

Example : Generics Java program:


import java.util.*;  
class TestGenerics1{  
public static void main(String args[]){  
ArrayList<String> list=new ArrayList<String>();  
list.add(“Information” );  
list.add(“Technology");  
//list.add(32);//compile time error  
  
String s=list.get(1); //type casting is not required  
System.out.println("element is: "+s);  
 Iterator<String> itr=list.iterator();  
while(itr.hasNext()){  
System.out.println(itr.next());  
}  
}  
}  

12
Generic types and generic (parameterized) programming…

Generic class
 A class that can refer to any type is known as generic class.
 A generic class declaration looks like a non-generic class
declaration, except that the class name is followed by a type
parameter section.
 Consider the following program in which we are using T type
parameter to create the generic class of specific type.
 The T type indicates that it can refer to any type (like String,
Integer, Float, Double, etc)

13
Generic types and generic (parameterized) programming…

 Example: Define the generic class.


public class Box<T> {
private T t;
public void add(T t) {
this.t = t;
}
public T get() {
return t;
}
  public static void main(String[] args) {
Box<Integer> integerBox = new Box<Integer>();
Box<String> stringBox = new Box<String>();
integerBox.add(new Integer(10));
stringBox.add(new String("Hello World"));
  System.out.printf("Integer Value :%d\n\n", integerBox.get());
System.out.printf("String Value :%s\n", stringBox.get());
}} 14
Generic types and generic (parameterized) programming…

Type Parameters
 The type parameters naming conventions are important to learn generics
 The commonly type parameters are as follows:
1. T - Type
2. E - Element
3. K - Key
4. N - Number
5. V - Value
Generic Method
 Like generic class, we can create generic method that can accept any type of
argument.

15
Generic types and generic (parameterized) programming…

Example : java generic method to print array elements.


public class TestGenerics4{  
     public static < E > void printArray(E[] elements) {  
        for ( E element : elements){          
            System.out.println(element );  
         }  
         System.out.println();  
    }  
    public static void main( String args[] ) {  
        Integer[] intArray = { 10, 20, 30, 40, 50 };  
        Character[] charArray = { 'J', 'A', 'V', 'A', 'T','P','O','I','N','T' };  
  
        System.out.println( "Printing Integer Array" );  
        printArray( intArray  );   
  
       System.out.println( "Printing Character Array" );  
        printArray( charArray );   
    }   

16

You might also like