Calc app

Post on 09-Jul-2015

44 views 0 download

Tags:

description

Android: Beginner

Transcript of Calc app

Android App

CALCULATOR

MUHAMMAD SHAHAB AHMAD R.NO

“142”

ASAD ULLAH R.NO “168”

SECTION „C‟ BS(CS) HONS IBMS

THE UNIVERSITY OF AGRICULTURE,

PESHAWAR,KP.

ANDROID A Java program (such as an

Android application

program) undergoes several

translation steps between

the time you write the

program and the time a

processor runs the program.

One of the reasons is

simple: Instructions that are

convenient for processors to

run are not convenient for

people to write.

JAVA SOURCE CODE:

public static void sum()

{

Int a=3,b=4;

System.out.println(“sum of a

and b”);

System.out.println(a+b);

}

Public static void main(String

arg[]){

Sum();

}

}

ANDROID

The processors in computers, phones, and other devices don‟t normally follow instructions like the instructions in Source code.

i.e processors don‟t follow Java source code instructions.

Instead, processors follow cryptic (having a secret or hidden meaning) instructions like the ones.

Java Byte code

0 aload_0

1 getfield #19

<com/allmycode/samples/MyA

ctivity/room

Lcom/allmycode/samples/Roo

m;>

4 getfield #47

<com/allmycode/samples/Roo

m/numGuests I>

7 ifne 22 (+15)

10 aload_0

……

……

……

ANDROID

ANDROID

When we write a Java program, we write source code instructions.

After writing the source code, we run a program (that is, we apply a tool) to the source code. The program is a COMPILER: It translates the source code instructions into Java byte code instructions.

In other words, the compiler translates code that we can write and understand into code that a computer can

Java Byte code

0 aload_0

1 getfield #19

<com/allmycode/samples/MyA

ctivity/room

Lcom/allmycode/samples/Roo

m;>

4 getfield #47

<com/allmycode/samples/Roo

m/numGuests I>

7 ifne 22 (+15)

10 aload_0

……

……

……

ANDROID

In 2007, Dan Bornstein at

Google created Dalvik

bytecode — another way to

represent instructions for

processors to follow.

Dalvik bytecode is optimized

(best use) for the limited

resources on a phone or a

tablet device.

Dalvik Byte code

.method public

checkVacancy(Landroid/view/

View;)V

.limit registers 4

; parameter[0] : v3

(Landroid/view/View;)

.line 30

iget-object

v0,v2,com/allmycode/samples/

MyActivity.room

Lcom/allmycode/samples/Roo

m;

; v0 :

……

……

……

CREATING AN ANDROID APP

For Creation of An Android App the requirements

are:

JDK (Java Development Kit)

for JAVA

Android SDK (Software Development Kit)

for ANDROID

An IDE (Integrated Development Environment. A

programming environment meshed into a software

program. It provides a text or code editor, a GUI

builder, a compiler, interpreter and debugger)

Eclipse OR

Android Studio

When we create an Android app, Eclipse/Android

Studio performs at least two compilations:

One compilation creates Java bytecode from

our Java source files.

The source filenames have the .java extension;

the Java bytecode filenames have the .class

extension.

Another compilation creates Dalvik bytecode

from our Java bytecode files.

Dalvik bytecode file names have the .dex

extension.

ANDROID

Android app has XML files, java files, and possibly other elements.

Before we install an app on a device.

Eclipse/ Android Studio combines all these elements into a single file — one with the .apk extension

To perform the compilation from source code to Java bytecode, Eclipse uses a program named javac, also known as the Java compiler.

To perform the compilation from Java bytecode to Dalvik code, Eclipse uses a program named dx(known affectionately as “the dx tool”).

To combine all your app‟s files into one .apk file, Eclipse uses a program named apkbuilder.

ANDROID

Open an

ANDROID STUDIO

To Start a Project;

Click on File Menu and then select NEW PROJECT

Name of your

APP

This Dialog box will let you choose the ICON of

your app

Choose which type of Activity you want to work

on

Name your

ACTIVITY

Then Click FINISH

XML file

contains;

•Design

View (Drag

and Drop)

And

•Text View

(Coding of

the Widgets)

Design

View

XML file

contains;

•Design

View (Drag

and Drop)

And

•Text View

(Coding of

the Widgets)

TEXT

View

Java File.

Here is the

actual

coding of the

working of

the app

To RUN your

app, start the

AVD

Manager

By Clicking

On The

ICON

Click on the

available

AVD,

And then

click START

The EMULATOR is Starting

The

EMULATOR

By Clicking on RUN Button. The APP is running

now!