Android Programming Lecture 2 Intro to Java Programming
Android Programming Lecture 2 Intro to Java Programming
Agenda Classes Objects Overview Packages ·| nheritance Abstraction Interfaces Nested Classes o Static nested Inner classes o Local anonymous classes
Agenda • Classes & Objects Overview • Packages • Inheritance • Abstraction • Interfaces • Nested Classes o Static nested & Inner classes o Local & anonymous classes 2
Objectives Identify the basic parts of a Java program Can identify a class and components of a class Read the codes in an app
Objectives • Identify the basic parts of a Java program • Can identify a class and components of a class • Read the codes in an app 3
Dot if the baby is within 1-2 years old if the baby is happy today if the milk is still hot else else else else.1 while(the baby is not 6 years old) A computer would ask you to What is a baby Define it What is a feeding bottle? Define it 我们该如何教授计 算机去理解我们? What is milk? Define! 4
4 Do{ if the baby is within 1-2 years old if the baby is happy today if the milk is still hot if … else … else …. else … else…} while(the baby is not 6 years old) A computer would ask you to: • What is a baby? Define it! • What is a feeding bottle? Define it! • What is milk? Define! 我们该如何教授计 算机去理解我们?
Class and object
Class and Object 5
What is an“ Object An object is a thing that we teach to the computer, so that the computer knows what the thing is Unlike people, a computer cannot see, feel and smell. It can only read codes. We have to define objects(or things)by describing the objects using (programming) languages The way we describe a thing is composed of two parts o Attributes(variables, properties ) What an object has o Methods: what an object can do
What is an “Object” • An object is a thing, that we teach to the computer, so that the computer knows what the thing is • Unlike people, a computer cannot see, feel and smell. It can only read codes. We have to define objects (or things) by describing the objects using (programming) languages. • The way we describe a thing is composed of two parts o Attributes (variables, properties): what an object has o Methods: what an object can do 6
Bicycle Music Music Player
7 Bicycle Music Music Player
Example: Bicycle Define the object for computers by specifying o The properties the object has o The functions the object provides Attributes Method o cadence o set cadence o gear o set the gear o speed o speed up o brake
Example: Bicycle 8 • Attributes: o cadence o gear o speed • Method: o set cadence o set the gear o speed up o brake • Define the object for computers by specifying o The properties the object has o The functions the object provides
package com. example test; //A bicycle class Example taken from Oracle Docs public class Bicycle t public int cadence; public int gear public int speed public Bicycle(int startCadence, int startspeed, int startGear) gear startGearj cadence startCadence; speed startspeed public void setCadence(int newValue)t cadence newValue public void setGear(int newValue)i gear newvaluej public void apply Brake(int decrement )i speed - decrement Bicycle public void speedUp(int increment)t speed + increment;
9 Bicycle
package com. example test; //A bicycle class Example taken from Oracle Docs public class Bicycle t Bicycle Class o can be thought of as a template, a prototype or a blueprint of an object o is the fundamental structure in object-oriented programming 10
10 Class o can be thought of as a template, a prototype or a blueprint of an object o is the fundamental structure in object-oriented programming Bicycle