eestec android workshops - 101 java, oop and introduction to android
DESCRIPTION
First of a workshop series by EESTEC LC Athens for Android. Introduction to Java, OOP and AndroidTRANSCRIPT
EESTEC Android Workshops
101 - Introduction to OOP, Java and Android
What we’ll cover today
EESTEC, Android, it’s APP to you!
Introduction to OOP
Introduction to Java
Setting up the Android Environment
Running your first App
Android, it’s APP to you!
How do I apply?
Create a great team!
Find an outstanding idea!
Complete a simple form!
Let’s get to the point!OOP, here we come!
Basic ConceptsClass - Blueprint, used to create instances of itself
Object / Instance - Instances are class occurrences
Method - Function / Procedure of an object or class
Attribute - Fields with values (objects) in a object
Pros
Code decoupling, enforces code reusability
Associates data structures with their related methods
Makes real-world object representation easier
Inheritance
Classes can extend other classes
They inherit their attributes and methods
Can extend only one class
Example
HumanWalks, Sleeps
namesurname
sex
AdultWorks
job positioncompanyvat no
KidPlays, Cries
no of toysschool gradeno of friends
Examplepublic class Hello {
public static void main(String[] argv) {
System.out.println(getHelloString()); }
private static String getHelloString() {
return "Hello"; }}
public class HelloWorld extends Hello {
@Override private static String getHelloString() {
return "Hello, world!"; }}
Interfaces
Make a class implement certain functionality
A class can implement more than one interfaces
ExampleMale
Watch footballSnore
Female
CookBe grumpy for
no reason
Male Kid
Female Adult
Female Human
Examplepublic class Human {
abstract void sayHi(); abstract void sayGoodBye();}
public class Eestecer implements Human {
@Override private static String sayHi() {
System.out.println("Hello guys!"); }
@Override private static String sayGoodBye() {
System.out.println("Goodbye... Keep partying!"); } }
OOP Languages
C++
Ruby
Python
C#
VB.NET
...And, wait for it...
Java-dive!Let’s take a fast look
Java, at a glanceC-like syntax
Created in Sun Microsystems, by James Gosling
Now acquired by Oracle
Hello, Java World!
public class HelloJava { public static void main(String[] argv) {
System.out.println(“Hello, Java World!”);}
Great Things about Java
Has a garbage collector, simply do not care about memory leakage!
Your program fails, except exceptions!
Is platform-independent, runs in it’s own VM, the JVM
Garbage Collector
Java objects leave in a heap
When the Garbage Collector needs to release memory, it starts removing dangling objects
Slightly pauses the application threads
Exceptions
Java gives you the chance to get a bit off track, but then makes sure you can handle unwanted situations
You can try something weird and if it turns bad, you handle the exception
Example
try {
something that might destroy the universe
catch (EarlyDestructionExcpetion e) { save the world}
Say hello, to my Green friend
The mystery, explained...Complete software stack
Operating System
Middleware
Key Applications
Open Source Developed by the Open Handset Alliance
Fastest growing market
Platform with the most devices activations
Android, bottoms up!
Setup a new project
Activity
Creates a window, so that the user can interact with the app
Can communicate with the system
Controls the higher level of the user interface
Activity, get a life!
The lifecycle of an Activity is really important.
Listen to Lifecycle events, in order to save and reproduce
the state of the app
Tasks for next time
1. Create an application that asks for the user’s name
2.Then, after hitting a button, it populates a text view with a personalized message for the user
3.When the button is pressed, a clear button appears that resets everything
Hint: Check the following classes: TextView, EditText, Button and OnClickListener