4/30/2017

Programming Language: Program Execution

 

When we are writing any program we have three choices

1.Programming Language

2.Scripting

3.Markup Language

Programming Language :

We consider that the example below is for C/C++

We have some basic steps :

1.Write a program

2.Compile it via compiler.

3.Link the program

4.run it

 

We can write the program in any editor even in Notepad++.

Visual Studio is a IDE (Integrated Development Environment) from Microsoft which is able to combined all the above steps.

when we write a program like this

//file: test.cpp

#include <iostream>

using namespace std:

int main(){

cout<<”Hello this is first output”<<endl;

 

 

 

Visual Studio is used to write the above C++ program .

After writing the program , it is being compiled.

Once the program is compiled(compiler) , its create object file similar to test.obj

after that compilation , test.obj is linked with C++ library(Linker perform this ) and executable file is produced.

it will be named like test.exe (In Linux environment it will be test.o)

 

.exe is a special file type in windows , which denote to a program executable.

Once the file is clicked , Operating system gives control to this program .

First line from where the program start is main() ….

all the subsequent line is executed one by one , once it reach to return 0;

or any return int ; on the last statement of program ,

program return the control to Operating system .

 

Visual studio or any other compiler (like GCC ,DevC++)can be used to compile and run the program .

4/23/2017

Programming language categorization

 

mostly all programming language can be defined in two category.

Compiled (Programming)

Interpreted.(Scripted)

Programming (Compiled)

Language like C , C++ etc comes in compiled category while JavaScript ,Lua etc comes in Scripting Category.

Compiled Language has below generic steps for programming

1.Write Code.

2.Compile it with Compiler( Like VisualStudio on Windows for C++ , gcc on linux for C++)

3.Link all the object file.

4.Create executable

5.Run on desired system(Supporting library should be present there )

One the executable is created , after that nothing can be done .User can run it and based on the type of application(UI/non UI) only input can be given.OS takes control of running of the program.

Scripting (Interpreted) : JavaScript,Lua

These are simpler scripts , which runs normally in browser or other Interpreter based environment like JavaScript .Here the interesting thing is that browser is it self written in C++.

These are normal steps in Scripting Language

1.Write Script Code.

2.Compile it with Compiler( Like VisualStudio on Windows for C++ , gcc on linux for C++)

3.Link all the object file.

4.Create executable

5.Run on desired system(Browser or other environment  )

Scripting language has limited feature and very less access of system internals while Programming language has a greater control over system

Scripting language execute line by line ( like a interpreter Convert the speech from one language to another in real time –> English to hindi )

While Programing language are pre translated in Machine code (There is no interpreter and speech is already converted and printed in native language of user)

Programming language are fast.

MARKUP Language : (HTML,XML)

Special syntax , to display the format of data like display the name of user as Table or Bullet , it is presentation of data

XML widely used in creating GUI of Android application.

Java: has a special category which is partially compiled and partially interpreted  .Will be covered later in detail.

Virtual desctructor

We  have two classes

class A{

public :

A(){  cout<<”Base constructor of class A “;

~A(){  cout<<”Base destructor of class A “;

};

Class B : public A{

public :

B(){ cout<<”Derived constructor of class B” ;}

~B(){  cout<<”Derived desstructor of class B“};

};

 

Now in main , we have different way to create object;

int main(){

// Case 1 –> Object Creation

//Proper constructor and destructor will be called , nothing need to be done

A objA;

B objB ;

//Case 2—> Pointer with same class dynamic object

A *pA = new A;

B *pB = new B;

….

…..

delete pA ;delete pB; // no issue ,work properly and destructor of A & B class will be called

//Case 3 –> Base class pointer , derived class memory

//in such case , proper destructor will not be called

A *pBase = new B; ///constructor of B & A is called

---------

……..

delete pBase;   //Destructor of A is called

return 0;

}

Case 3 Output

Base constructor of class A

Derived  constructor of class B

Derived  Destructor of class B

---------------------------------------------------------------

Here Base class destructor is not called.

The only problem case is Base Class pointer with derived class memory.

while we assign the memory by statement A *pBase = new B;  compiler know that it will be B class , so proper constructor is called.

when we called delete pBase , it does not know which class memory it hold in run time. That s why we should have a mechanism so that system can call destructor of class B at run time.

to achieve the same , we need to create the destructor as virtual .Once we declare destructor as virtual system automatically delete proper memory & call the destructor of class B.

to resolve the issue of dynamic memory allocation of derived class in Base class pointer & avoid Memory leak , we need to have virtual destructor.

so we need to define the class like this

class A{

public :

A(){  cout<<”Base constructor of class A “;

virtual ~A(){  cout<<”Base destructor of class A “;

};

Class B : public A{

public :

B(){ cout<<”Derived constructor of class B” ;}

~B(){  cout<<”Derived desstructor of class B“};

};

int main(){

//Case 3 –> Base class pointer , derived class memory

 

A *pBase = new B; 

---------

……..

delete pBase;   //Destructor of A is called

return 0;

}

Case 3 Output

Base constructor of class A

Derived  constructor of class B

Derived  Destructor of class B

Base destructor of class A

4/22/2017

Pure Virtual Function,Abstract Class

 

--------------------------------------

Pure virtual ==> no definition in class 

Class A{

public :

int x ;

void SetData(int a)=0 ; ///Pure virtual function

}

We can not create object of class A.

A objA; //error

All classes which have at least 1 pure virtual function is called Abstract Class

These classes object can not be created.

These classes need to be derived and pure virtual function need to be redefined.

Class D : public B{

void SetData(int a){           //redefine pure virtual function in derived class

x= a ;

///other stufff

}

D objD ; //valid and Ok

Programming Basic--2

 

Programming means creating software

Software can be categorized in many way ..for Simplicity we think it is as

System Software

–> Include all Operating system (OS) development , drivers and OS utility

-> various OS are present , some of famous OS are

Windows by Microsoft

MAC –> by Apple

Linux –> open source community

Android—> Open source for mainly Mobile platform , by google

Application Software

–> All the application where user directly interact.

There are many categorization of application software

starting from

  1. basic utility
  2. small application like calculator ,notepad etc
  3. Server Client based desktop application
  4. Cross platform application which works on multiple OS (on Windows ,linux etc)
  5. Cross Platform(Hardware) application which works on ARM and X86 baord etc
  6. Mobile applications
  7. Enterprise application
  8. Native application (C++)
  9. Hybrid application
  10. Web application
  11. DTV based application

and many more…

There are different language and frameworks are being used to develop different kind of applications .Based on the requirement & nature of application ,several type of  language , tools and IDE are being selected

Some of the language/Framework are

Programming –> C, C++ , Java ,

Scripting->     Java Script , pearl ,

Framework-> .NET , weWidget , node.js ,Ruby on Rails etc ,MFC

 

In next we will check the difference  between languages and framework as well difference in programming and scripting language

4/17/2017

Programming The world of Infinity

 

Computer =Software + Hardware

 

Hardware –>> All things which you can touch like keyboard , mouse ,RAM etc

Two Major parts

1. Input –> Gives input to computer , Like Keyboard , Mouse ,Mike

2.Output-> Gives out from computer—> Printer , Speaker ,Display

 

Software –> Which you can not touch but play a major role (like your mind , your thoughts)

Software consist two major part

System Software –>> Operating System ,Drivers etc

Application Software –> Application software , paint ,MS Office , Photoshop etc

 

Why Programming Language :

For development of software

System Software and Application software are developed using various language ,reason is computer can understand only binary data

For human it is difficult to program in Binary, so there is a need of simpler language which human can work and which can be translated in computers language (Binary)

For the same reason there exist so many language like , C , C++ , Java ,Lua , JavaScript… etc.

Also , a lot of other language ,framework developed over the time to make it easier for work