mobile computing · introduction to java language. what is java? java is a computer programming...

53
Mobile Computing LECTURE # 2

Upload: others

Post on 29-May-2020

25 views

Category:

Documents


0 download

TRANSCRIPT

Mobile ComputingLECTURE # 2

The CourseCourse Code: IT-4545

Course Title: Mobile Computing

Instructor: JAWAD AHMAD◦ Email Address: [email protected]

Web Address: http://csandituoslahore.weebly.com/mc.html

Term (Semester): Spring 2018

Duration: 15/16 Weeks

Introduction to Java Language

What is Java?Java is a computer programming Language

just like

◦ C

◦ C++

Developed by Sun Microsystems in around

1990s and now Oracle corporation.

Converts Human understandable instructions

to Machine understandable instructions

Java Program Flow

Java Program ComponentsJava Code (.java)

• Set of instructions

• Written by following

Language rules

• A programmer writes

these instructions

• Also called Source

Code

• Saved in a file with

.java extension

• Can be written in any

text Editor

• Notepad

Java Program ComponentsJava Compiler (javac)

• Reads Java Source Code

• Converts into Computer Readable

Form

• Checks for Errors

• Makes sure all the instructions are

in proper order

• Creates Java Byte Code

Java Source Code

(.java)

Java Compiler

(javac)

Java Byte Code

Java Program ComponentsJava Byte Code (.class)

• Set of instructions compiled by

Java Compiler

• These are instructions readable by

JVM (Java Virtual Machine)

• Normally not editable in normal

Text Editors like Notepad

• Special Editors are used

• Java Byte Code Editor

• Programmer does not need to

understand Java Byte Code

Java Compiler

Java Source Code

Java Byte Code

Java Program ComponentsJava Virtual Machine (JVM)

• It’s a platform independent

execution environment

• It is actually a program that reads

other program

• Normally Java Byte Code

• It provides a runtime environment

for Java Byte Code

• According to Sun Microsystems,

there are almost 5.5 Billion JVM

Enabled devices

Java Virtual

Machine

Java Byte Code

Output of a Program

Object Oriented Programming Language(OOP)

Object Oriented ProgrammingOOP has

◦ Objects

◦ Classes

◦ Methods

◦ Encapsulation

◦ Inheritance

◦ Polymorphism

Object in OOP

Everything is an Object

An Object

◦ Knows something

◦ Does something

Knowing something is Instance

Variables

Doing something is Methods

Vehicle• type

• color

• name

Drive()

En

gin

eSta

rt()

Turn()

En

gin

eSto

p()

Variables Methods

What is a Class?• Classes are used to create an Object

• It tells JVM how to make an Object

How to create a Class?

public class HelloWorld

{

public static void main (String[] args)

{

System.out.println("Hello World!");

}

}

Modifier

Identifier

Return TypeMethod Arguments

Class Name

Method Name

Part of Class not Object Print output to console

String to be displayed

Encapsulation

• Makes the data private

• Uses Getters and Setters

• Others can use only the data you want them to use

Access Modifiers

• Private

• Public

• protected

Some other Objects

Button

• Label

• Color

• getLabel()

• getColor()

• setLabel()

• setColor()

• click()

Song

• Title

• Duration

• getTitle()

• getDuration()

• setTitle()

• setDuration()

• play()

Variable

Method

• Programmers normally have getter and setter methods for variables

• Getters

• getLabel()

• getColor()

• getTitle()

• getDuration()

• Setters

• setLabel()

• setColor()

• setTitle()

• setDuration()

Inheritance

• Subclass inherit from Superclass

• Subclass will inherit

• Variable

• Methods

• Subclasses can override the methods of superclass

• Make their own versions of methods

• Backward inheritance is not possible

• Superclass cannot extend methods, variable from subclass

Inheritance

Super class

Sub class

Polymorphism

Polymorphism

Abstract Classes

Abstract Classes• Some classes should not instantiate

• Abstract classes should always be extended

• We will never create an object of that class

• We can however make reference for that class

• Some general classes have no definition as object instantiation

• Vehicle

• Animal

abstract class Vehicle

{

public void drive()

{

}

}

abstract public class Vehicle

{

public void drive()

{

}

}

Abstract Classes

abstract public class Vehicle

{

public void drive()

{

}

}

public class MakeVehicle

{

public void start()

{

Vehicle vehicle;

vehicle = new car();

}

}

public class MakeVehicle

{

public void start()

{

Vehicle vehicle;

vehicle = new vehicle();

}

}

Abstract Methods• An abstract method has no body

• An abstract method can reside in Abstract class only

• Non-Abstract Classes cannot carry Abstract methods

• Abstract class can carry both Abstract and Non-Abstract methods

abstract public class Vehicle

{

public void drive()

{

}

public abstract void idle();

}Abstract Method

Non- Abstract Method

Multiple Inheritance not allowed in Java

Multiple Inheritance not allowed in Java

Interfaces in Java

Replace class with

interface

Interfaces in Java

A class can implement multiple interfaces

Introduction to Android Development

What is Android?

Its an OS for mobile phones

It is a modified form of Linux

It runs on Linux Kernel 3.18

Bought by Google in 2005

Android is open source

Source Code is available at

http://source.android.com/

Different hardware vendors can build their devices

and run Android on them

Android Versions

Android FeaturesStorage

◦ SQLite

Connectivity

◦ GSM

◦ CDMA

◦ LTE

◦ Wi-Fi

◦ WiMax

Messaging

Multitouch

Multitasking

Android Architecture

Android ArchitectureLinux Kernel

◦ Android runs on Linux Kernel 3.18

◦ A Kernel is collection of programs that helps in interaction of software

and hardware. These programs are called drivers.

◦ Android because of its foundation on Linux Kernel contains all the basic

functionality of Linux e.g. Memory Management.

◦ A device with certain hardware should have a proper driver in the Linux

Kernel to work properly

◦ Bluetooth will not work until the driver is available for that hardware.

Android ArchitectureLibraries

◦ Android contains some core libraries which help build different other

libraries.

◦ Some of the most important libraries are

◦ Media Framework

◦ Contains all the codes for media

◦ WebKit

◦ It is a browser engine that runs HTML content

◦ SQLite

◦ Handles storage of data

Android ArchitectureAndroid Runtime

◦ Dalvik Virtual Machine

◦ It is a virtual machine like JVM.

◦ It does not run .class file, instead it runs .dex files

◦ These files are created from .class files at compilation time.

◦ Multiple instances of DVM can run simultaneously.

◦ Core Libraries

◦ It contains different libraries from Java SE and Java ME

Android ArchitectureApplication Framework

◦ As a developer we directly interact with this layer.

◦ This layer contains libraries which provide basic functionality for android

like call, messaging and resource management etc.

◦ Some of them are

◦ Activity Manager

◦ It takes care of the activity life cycle

◦ Location Manager

◦ It handles the location

Android ArchitectureApplications

◦ Based on all the previously mentioned layers, our

applications will be available at Applications Layer.

◦ Almost all the applications are handled at this layer.

◦ Default apps also fall in this category

◦ Some of the default apps are

◦ Phone

◦ Messaging

◦ Mail

Android Smart Phones

Galaxy S II Motorola Atrix 4G, HTC EVO 4G

Android Tablets

Samsung Galaxy Tab 10.1 Asus Eee Pad Transformer TF101

Android EBook Readers

Barnes and Noble’s NOOK Color Amazon’s Kindle Fire

Android Based TV

Scandinavia Android TV

Mashup CompatibilityCombination of two or more service to create an App.

◦ Geolocation + Social networking

◦ Geolocation + Gaming

◦ Camera + Geolocation

◦ Contacts + Maps

Components of Android Programming

Activities

◦ Android Application are composed

of Activities

◦ Each Application will have at least

one Activity

◦ Activities are like container

◦ Code

◦ User Interface

◦ Its like Form for Windows in Vb.net

Hello World !

Activity

Components of Android Programming

Intents

Intent = Action + Data

◦ It can be transition between two activities

◦ It can be launching an app from one app

◦ It’s a message to Android System to tell app

will do something

Components of Android Programming

Cursorless Control

◦ Unlike PCs, no cursor on screen

◦ Fingers are used to perform Screen Actions

◦ Multitouch gestures

◦ Zooming

◦ Dragging

◦ Long Press right click

Components of Android Programming

Views and Widgets

◦ View is a rectangular area on screen for

drawing

◦ Menu

◦ Context Menu

◦ Widgets are advanced UI Controls

◦ Buttons

◦ Checkboxes

◦ DatePickers etc.

Components of Android Programming

Background Service

◦ Service is a program that doesn’t need to have a UI

◦ A background service runs in the background

◦ Antivirus application in windows is a background

service

◦ Alarm app runs in background for mobile phones

Android Hardware Tools

Google APIs

Android can do more than Calls and Messages

It can help in navigating

It can help in showing a friend on map

Android in Cloud

Information can be stored in Cloud

Information can be retrieved from Cloud

Android Development Tools

Requirements

Any PC running◦ Windows

◦ Mac OS X

◦ Linux

Android Studio

JDK