Mobile Software Engineering Crash Course - C02 Java Primer

53
Mobile Software Engineering L02 – Java Primer Mohammad Shaker FIT of Damascus - AI dept. [email protected] Mobile SE – August 2012

description

 

Transcript of Mobile Software Engineering Crash Course - C02 Java Primer

Page 1: Mobile Software Engineering Crash Course - C02 Java Primer

Mobile

Software

Engineering

L02 – Java Primer

Mohammad Shaker

FIT of Damascus - AI dept.

[email protected]

Mobile SE – August 2012

Page 2: Mobile Software Engineering Crash Course - C02 Java Primer

IDE

eclipse, netbeans, etc.

Page 3: Mobile Software Engineering Crash Course - C02 Java Primer

eclipse

Page 4: Mobile Software Engineering Crash Course - C02 Java Primer

eclipse Juno, 2012

Page 5: Mobile Software Engineering Crash Course - C02 Java Primer

btw, why eclipse?!

Page 6: Mobile Software Engineering Crash Course - C02 Java Primer

eclipse Downloadhttp://www.eclipse.org/

Page 7: Mobile Software Engineering Crash Course - C02 Java Primer

eclipse Download

Page 8: Mobile Software Engineering Crash Course - C02 Java Primer

eclipse Juno – Packages and Projects

Page 9: Mobile Software Engineering Crash Course - C02 Java Primer

JavaJVM – Java Virtual Machine

Page 10: Mobile Software Engineering Crash Course - C02 Java Primer

JavaWrite once, run anywhere

Page 11: Mobile Software Engineering Crash Course - C02 Java Primer

Javaeverything is an object!

Or is it?

Page 12: Mobile Software Engineering Crash Course - C02 Java Primer

Javaeverything is an object!

Or is it?

Page 13: Mobile Software Engineering Crash Course - C02 Java Primer

APIhttp://java.sun.com/javase/6/docs/api/

Tutorial http://java.sun.com/docs/books/tutorial/java/TOC.html

Page 14: Mobile Software Engineering Crash Course - C02 Java Primer

Variables - Naming

• Subsequent characters also can be numbers

• Case sensitive

• No spaces

• Examples:

name

firstName

phoneNumber

Page 15: Mobile Software Engineering Crash Course - C02 Java Primer

Reserved Words

abstract continue for new switch

assert*** default goto* package synchronized

boolean do if private this

break double implements protected throw

byte else import public throws

case enum**** instanceof return transient

catch extends int short try

char final interface static void

class finally long strictfp** volatile

const* float native super while

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html

Page 16: Mobile Software Engineering Crash Course - C02 Java Primer

Primitive Types

byte

short

int

long

float

double

boolean

char

Page 17: Mobile Software Engineering Crash Course - C02 Java Primer

Primitive Types

byte

short

int

long

float

double

boolean

char

Everything

is an

object?

Page 18: Mobile Software Engineering Crash Course - C02 Java Primer

Primitive Types

byte

short

int

long

float

double

boolean

char

Everything

is an

object?

Page 19: Mobile Software Engineering Crash Course - C02 Java Primer

Objects

String

BigDecimal

Page 20: Mobile Software Engineering Crash Course - C02 Java Primer

Arrays

int[] grades;

grades = new int[15];

Page 21: Mobile Software Engineering Crash Course - C02 Java Primer

Control flow

if (boolean) {

// perform this code

} else {

// otherwise, run this

}

Page 22: Mobile Software Engineering Crash Course - C02 Java Primer

Example on first step!

Car myCar = new Car();

Page 23: Mobile Software Engineering Crash Course - C02 Java Primer

Example on first step!

Car myCar = new Car();

Page 24: Mobile Software Engineering Crash Course - C02 Java Primer

Example on first step!

Car myCar = new Car();

Car yourCar = myCar;

Point loc = myCar.getLocation();

Page 25: Mobile Software Engineering Crash Course - C02 Java Primer

New paradigms

• Stack

• Heap

• Garbage collection

Page 26: Mobile Software Engineering Crash Course - C02 Java Primer

Setters and Getters

Page 27: Mobile Software Engineering Crash Course - C02 Java Primer

Let’s get our hands dirty

Page 28: Mobile Software Engineering Crash Course - C02 Java Primer

Let’s get our hands dirty

Objects

Page 29: Mobile Software Engineering Crash Course - C02 Java Primer

Packages vs Namespaces

Page 30: Mobile Software Engineering Crash Course - C02 Java Primer

void main(string[] args)

Page 31: Mobile Software Engineering Crash Course - C02 Java Primer

Instance vs Class methodsvoid shootBall(Point point)

static void main(string[] args)

Page 32: Mobile Software Engineering Crash Course - C02 Java Primer

Inheritance and Polymorphismextends, super, @Override

Page 33: Mobile Software Engineering Crash Course - C02 Java Primer

Some diff.protected in a form of package scope not class scope

Page 34: Mobile Software Engineering Crash Course - C02 Java Primer

Some diff.final vs const vs readonly

Page 35: Mobile Software Engineering Crash Course - C02 Java Primer

interfaces

Page 36: Mobile Software Engineering Crash Course - C02 Java Primer

Interfaces

extends

Page 37: Mobile Software Engineering Crash Course - C02 Java Primer

Collections

Page 38: Mobile Software Engineering Crash Course - C02 Java Primer

http://docs.oracle.com/javase/tutorial/collections/interfaces/index.html

Page 39: Mobile Software Engineering Crash Course - C02 Java Primer

Example

ArrayList<String> arrList = new ArrayList<String>();

arrList.add(“A”);

arrList.add(“AB”);

arrList.add(“ABC”);

arrList.add(“ABCD”);

// using indices

arrList.set(0, arrList.get(1));

arrList.set(1, “foo”);

// out of bound?

arrList.set(9, “bar”);

Page 40: Mobile Software Engineering Crash Course - C02 Java Primer

Example

• Suppose an ArrayList A1

• What does the following line mean?

List<String> list =

new ArrayList<String>(A1);

Page 41: Mobile Software Engineering Crash Course - C02 Java Primer

for-each Construct

• Looping by indices

• for-each, parallel execution

for (Object o : collection)

System.out.println(o);

Page 42: Mobile Software Engineering Crash Course - C02 Java Primer

Collection Operations

List<Type> list1 = new ArrayList<Type>();

// …

List<Type> list2 = new ArrayList<Type>();

// …

List<Type> list3 = new ArrayList<Type>(list1);

list3.addAll(list2);

Page 43: Mobile Software Engineering Crash Course - C02 Java Primer

ListAlgorithms

• sort— sorts a List using a merge sort algorithm, which provides a fast, stable sort. (A stable sort is one that does not reorder equal elements.)

• shuffle— randomly permutes the elements in a List.

• reverse— reverses the order of the elements in a List.

• rotate— rotates all the elements in a List by a specified distance.

• swap— swaps the elements at specified positions in a List.

• replaceAll— replaces all occurrences of one specified value with another.

• fill— overwrites every element in a List with the specified value.

• copy— copies the source List into the destination List.

• binarySearch— searches for an element in an ordered List using the binary search algorithm.

• indexOfSubList— returns the index of the first sublist of one List that is equal to another.

• lastIndexOfSubList— returns the index of the last sublist of one List that is equal to another.

See more @ http://docs.oracle.com/javase/tutorial/collections/interfaces/list.html

Page 44: Mobile Software Engineering Crash Course - C02 Java Primer

Iterators

Page 45: Mobile Software Engineering Crash Course - C02 Java Primer

Multithreadingsynchronized, wait,

notify, notifyall

Page 46: Mobile Software Engineering Crash Course - C02 Java Primer

Exception Handling, IO...

Page 47: Mobile Software Engineering Crash Course - C02 Java Primer

Design PatternsSingleton, Factory, Proxy, Template.. etc.

Page 48: Mobile Software Engineering Crash Course - C02 Java Primer

Gang of four

Page 49: Mobile Software Engineering Crash Course - C02 Java Primer
Page 50: Mobile Software Engineering Crash Course - C02 Java Primer
Page 51: Mobile Software Engineering Crash Course - C02 Java Primer

Implementing Singleton with Java

“live”

Page 52: Mobile Software Engineering Crash Course - C02 Java Primer
Page 53: Mobile Software Engineering Crash Course - C02 Java Primer

Thx for listening