E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous...
Transcript of E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous...
![Page 1: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/1.jpg)
E0-245: ASP
Lecture 5: OOPs Classes and Objects
Dipanjan Gope
![Page 2: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/2.jpg)
2
Dipanjan Gope
• Intent is asynchronous
• Sending notification a service?
• SensorEventListener component
• Why does BroadcastReciever not extend service?
• Can 2 activities use same screen space?
• Lifecycle: what is the limit to #of processes?
Questions from Lecture 3
![Page 3: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/3.jpg)
3
Dipanjan Gope
Android Stack
Ref: http://www.tutorialspoint.com/android/android_architecture.htm
![Page 4: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/4.jpg)
4
Dipanjan Gope
JAVA and C++ mainly: (others C# and Objective-C)
• Object oriented programing: Classes and objects
• Inheritance, polymorphism, abstract class, const
• Templates and generics
• Data structures
• Standard library, JCF, STL
• Complexity analysis
• Multithreading and synchronization
• Good programming styles
Module 1: OOPs and DS
![Page 5: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/5.jpg)
5
Dipanjan Gope
• Assembler
• Compiler
• Interpreter
• Just-in-time Compiler
Code Conversion
![Page 6: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/6.jpg)
6
Dipanjan Gope
JAVA VM
http://www.javatpoint.com/features-of-java
![Page 7: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/7.jpg)
7
Dipanjan Gope
JAVA VM
http://www.javatpoint.com/features-of-java
![Page 8: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/8.jpg)
8
Dipanjan Gope
• First Programming Language
- Fortran
- 1957
- IBM
• First OOPs Language
- Simula
- 1967
- Norwegian Computing Center
Fun Facts
![Page 9: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/9.jpg)
9
Dipanjan Gope
• Java
- 1994
- James Gosling, Sun Microsystems
- Licensed by Netscape for navigator
• C language
- 1972
- Dennis Ritchie
- Bell Labs
Fun Facts
![Page 10: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/10.jpg)
10
Dipanjan Gope
Evolution of Programming Languages
Paul Boutin and Bret Hailpern at IBM Research and Todd Proebsting at Microsoft, The Retrocomputing Museum, and Gio Wiederhold at Stanford University.
![Page 11: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/11.jpg)
11
Dipanjan Gope
Top 10 Programming Languages
http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
![Page 12: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/12.jpg)
12
Dipanjan Gope
int a; # how many bytes?
int *pA; # how many bytes?
int &rA = a; # how many bytes?
Recap: Pointers and References
![Page 13: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/13.jpg)
13
Dipanjan Gope
When to use pointers?
- Pointer arithmetic
- NULL initialization
Recap: Pointers vs References
Pointers References
NULL Yes No
Point changed to a different object
Yes No
Initialization Anytime On creation
![Page 14: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/14.jpg)
14
Dipanjan Gope
• Class
• Object
• Polymorphism
• Inheritance
• Abstraction
• Encapsulation
• Overloading
Object Oriented Programming System
![Page 15: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/15.jpg)
15
Dipanjan Gope
• Code Reuse and Recycling
• Encapsulation: Hide details, prevent tampering
• Design benefits
• Software maintenance
• Run-time errors become compiler errors
Advantages of OOPs
https://www.cs.drexel.edu/~introcs/Fa12/notes/06.1_OOP/Advantages.html?CurrentSlide=3
![Page 16: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/16.jpg)
16
Dipanjan Gope
class Rectangle
{
# Methods
Public:
Private:
Protected:
# Field: Member data
Public:
Private:
Protected:
}
Class
Fields: Member data Local Variables: Variables in piece of code Parameters: Variables in function declaration
![Page 17: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/17.jpg)
17
Dipanjan Gope
Public, Protected, Private
JAVA Modifiers C++ Access Specifier
http://docs.oracle.com/javase/tutorial/ java/javaOO/accesscontrol.html
Specifier Class Project Sub-class
public Y Y Y
protected Y N Y
no specifier Same as private
private Y N N
![Page 18: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/18.jpg)
18
Dipanjan Gope
• Instance of a class
• Just like: int i;
• Occupies memory in RAM;
• E.g. Rectangle rectangle1;
Object
![Page 19: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/19.jpg)
19
Dipanjan Gope
class Student
{
private:
float CGPA;
int rollNumber;
double height;
int schoolID; // string schoolName;
}
Object: Example
![Page 20: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/20.jpg)
20
Dipanjan Gope
• Static member data:
- common to all objects of the class
- single memory location for all classes
- e.g. static string schoolName
• Static member function:
- belongs to class rather than object
- may be invoked without object instance
- can access static variables
Static
![Page 21: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/21.jpg)
21
Dipanjan Gope
• Special member function
• Same name as the class
• No return type (not even void)
• Used for:
- variable initialization
- memory allocation (perhaps)
- called on “new” or instantiation
Constructor
![Page 22: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/22.jpg)
22
Dipanjan Gope
• Constructor overloading
- Multiple forms of constructors (polymorph)
- different input arguments
• Special types of constructors:
- Default constructor (different for diff compilers)
- Copy constructor
Constructor
![Page 23: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/23.jpg)
23
Dipanjan Gope
Constructor
Rectangle rectangle1; Rectangle* pRectangle2 = new Rectangle; Rectangle rectangle1(1,1.5); Rectangle* pRectangle2 = new Rectangle(1,1.5);
Rectangle rectangle1 = new Rectangle; Rectangle rectangle2 = new Rectangle(1,1.5);
JAVA reference-based
C++ pointer-based
![Page 24: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/24.jpg)
24
Dipanjan Gope
• Special member function
• Same name as the class with ~
• No return type (not even void)
• Used for:
- memory creation
- called on “out of scope” or “delete”
• JAVA: Garbage collector
Destructor (C++)
![Page 25: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/25.jpg)
25
Dipanjan Gope
Project Organization
JAVA C++
![Page 26: E0-245: ASPdipanjan/E0_245/E0245-ASP... · 2015-01-30 · 2 Dipanjan Gope •Intent is asynchronous •Sending notification a service? •SensorEventListener component •Why does](https://reader033.fdocuments.in/reader033/viewer/2022041911/5e677b35e645b2539c7c51a0/html5/thumbnails/26.jpg)
26
Dipanjan Gope
Code Organization
JAVA C++
Rectangle Class
Main