Sie sind auf Seite 1von 52

Mobile Application Development

LECTURE # 2
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 Components
Java 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 Components
Java Compiler (javac)

Java Source Code


(.java)
• Reads Java Source Code
• Converts into Computer Readable
Form
• Checks for Errors Java Compiler
• Makes sure all the instructions are (javac)
in proper order
• Creates Java Byte Code

Java Byte Code


Java Program Components
Java Byte Code (.class)

Java Source Code


• Set of instructions compiled by
Java Compiler
• These are instructions readable by
JVM (Java Virtual Machine)
Java Compiler
• Normally not editable in normal
Text Editors like Notepad
• Special Editors are used
• Java Byte Code Editor
• Programmer does not need to Java Byte Code
understand Java Byte Code
Java Program Components
Java Virtual Machine (JVM)

Java Byte Code


• It’s a platform independent
execution environment
• It is actually a program that reads
other program Java Virtual
• Normally Java Byte Code Machine
• It provides a runtime environment
for Java Byte Code
• According to Sun Microsystems,
there are almost 5.5 Billion JVM
Enabled devices Output of a Program
Object Oriented Programming Language
(OOP)
Object Oriented Programming
OOP has

◦ Objects

◦ Classes

◦ Methods

◦ Encapsulation

◦ Inheritance

◦ Polymorphism
Object in OOP
Drive()
Everything is an Object

EngineStart()

EngineStop()
An Object Vehicle
◦ Knows something • type
• color
◦ Does something • name

Knowing something is Instance Turn()


Variables
Variables Methods
Doing something is 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?
Identifier Class Name
Modifier
Method Name
public class HelloWorld
{
Method Arguments
Return Type

public static void main (String[] args)


{
Part of Class not Object Print output to console

System.out.println("Hello World!");
}
} 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 Song
• Label • Title
• Color Variable • Duration
• getLabel() • getTitle()
• getColor() • getDuration()
setLabel() Method
• • setTitle()
• setColor() • setDuration()
• click() • play()

• Programmers normally have getter and setter methods for variables


• Getters • Setters
• getLabel() • setLabel()
• getColor() • setColor()
• getTitle() • setTitle()
• getDuration() • 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 abstract public class Vehicle
{ {
public void drive() public void drive()
{ {

} }
} }
Abstract Classes
abstract public class Vehicle
{
public void drive()
{

}
}

public class MakeVehicle public class MakeVehicle


{ {
public void start() public void start()
{ {
Vehicle vehicle; Vehicle vehicle;

vehicle = new car(); 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() Non- Abstract Method
{

public abstract void idle();


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 Features
Storage
◦ SQLite

Connectivity
◦ GSM
◦ CDMA
◦ LTE
◦ Wi-Fi
◦ WiMax

Messaging

Multitouch

Multitasking
Android Architecture
Android Architecture
Linux 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 Architecture
Libraries
◦ 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 Architecture
Android 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 Architecture
Application 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 Architecture
Applications

◦ 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 Compatibility
Combination 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 Activity

of Activities

◦ Each Application will have at least


one Activity

◦ Activities are like container Hello World !


◦ Code

◦ User Interface

◦ Its like Form for Windows in Vb.net


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

Das könnte Ihnen auch gefallen