Android Programming Lecture 2 Intro to Java Programming
Android Programming Lecture 2 Intro to Java Programming
Agenda Classes Objects Overview 。Packages ·Inheritance 。Abstraction ·Interfaces ·Nested Classes o Static nested Inner classes o Local anonymous classes 2
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 3
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
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! 算机去理解我们? ·Vhat is milk?Define!
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 5
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 public int cadence; public int gear; public int speed; public Bicycle(int startCadence,int startSpeed,int startGear) gear startGear; cadence startCadence; speed startSpeed; public void setCadence(int newvalue){ cadence newValue; } public void setGear(int newValue){ gear newValue; } public void applyBrake(int decrement){ speed -decrement; } Bicycle public void speedUp(int increment){ speed +increment; 9
9 Bicycle
package com.example.test; //A bicycle class Example taken from Oracle Docs... public class Bicycle 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