0% found this document useful (0 votes)
3 views

Chapter 2_lecture Note

The document is a presentation on mobile application programming and design, specifically focusing on Java and Android programming. It covers topics such as Java programming language features, syntax basics, variables, methods, classes, inheritance, control structures, and project setup in Android Studio. The content is structured into slides, detailing both theoretical concepts and practical steps for creating an Android application.

Uploaded by

21010868
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Chapter 2_lecture Note

The document is a presentation on mobile application programming and design, specifically focusing on Java and Android programming. It covers topics such as Java programming language features, syntax basics, variables, methods, classes, inheritance, control structures, and project setup in Android Studio. The content is structured into slides, detailing both theoretical concepts and practical steps for creating an Android application.

Uploaded by

21010868
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Slide 1 ___________________________________

___________________________________
MOBILE APPLICATION
PROGRAMMING AND DESIGN
___________________________________
Chapter 2: Java and Android programing
MS. DAO TO HIEU
Office: A4 704 Mobile: 0389959524
Email: [email protected]
___________________________________
18/08/2023 1

___________________________________

___________________________________

___________________________________

Slide 2 CONTENTS ___________________________________


Java Programming Language
___________________________________
Programming Structures in Java

Android Project
___________________________________

Java in Android Studio


___________________________________
18/08/2023 2

___________________________________

___________________________________

___________________________________

Slide 3 INTRODUCTION TO JAVA ___________________________________


PROGRAMMING

❑ Developed by Sun Microsystems.


❑ Launched in 1995.
___________________________________
❑ The most widely used language
in the world.
❑ Java is designed for versatility,
___________________________________
capable of running on various
platforms without the need for
recompiling the code. ___________________________________
18/08/2023 3

___________________________________

___________________________________

___________________________________
Slide 4 WHY JAVA? ___________________________________

___________________________________

___________________________________

___________________________________
18/08/2023 4

___________________________________

___________________________________

___________________________________

Slide 5 FEATURES OF JAVA ___________________________________

___________________________________

___________________________________

___________________________________
18/08/2023 5

___________________________________

___________________________________

___________________________________

Slide 6 JAVA SYNTAX BASICS ___________________________________

___________________________________

___________________________________
✓ Everything outside the 8 primitives is an Object (defined by a
class)
✓ Comment a line with // or use /* and */ to create a block
comment.
✓ non-control (program flow) statements end with a “;”
___________________________________
18/08/2023 6

___________________________________

___________________________________

___________________________________
Slide 7 VARIABLES ___________________________________

• Piece of memory
✓ Primitive: int, double, boolean,…
___________________________________
✓ Class: CreatbySenSor, GetTime, …
• Memory and a name for the variable
✓ Classes: usable instance does not exist
yet (variable is null)
✓ Primitives: variable has a default value
___________________________________
(0 or false)
Example:
ElapsedTime runtime;
ElapsedTime runTime = new ElapsedTime(); ___________________________________
18/08/2023 7

___________________________________

___________________________________

___________________________________

Slide 8 VARIABLES ___________________________________

❑ Assignment:Sets variable to ❑ Instantiate


___________________________________
a value. • Setup memory for an
• Literal value: “instance” of a class
int aNumber = 67; ❑ Initialize
• Another variable:
Int aNumber, bNumber;
• Set up starting values (ie:
variables) inside
___________________________________
aNumber =bNumber++;
• Method return: “instance” of the class
Int aNumber; runTime= new ElapsedTime();
aNumber = getValue();
new keyword
(Instantiate)
Constructor
(Initialize)
___________________________________
18/08/2023 8

___________________________________

___________________________________

___________________________________

Slide 9 VARIABLES ___________________________________

Category
byte
Types
+127 to -128
Values Example
byte b = 65;
___________________________________
char c = 'A';
char All Unicode characters
char c = 65;
short +32,767 to -32,768 short s = 65;
Integer
+2,147,483,647 to -
int int i = 65;

long
2,147,483,648
+9,223,372,036,854,775,807 to
-9,223,372,036,854,775,808
long l = 65L; ___________________________________
float 3.402,823,5 E+38 to 1.4 E-45 float f = 65f;
Floating-
1.797,693,134,862,315,7 E+308
point double double d = 65.55;
to 4.9 E-324
boolean false, true boolean b = true;
Other
void -- --
___________________________________
18/08/2023 9

___________________________________

___________________________________

___________________________________
Slide 10 MODIFIERS ___________________________________

Access
Modifiers
Non-Access
Modifiers
Other Modifiers ___________________________________
• Public • Static (class- • Transient
• Private level) not • native


Protected
default
instance-level.
• Finalabstract
• strictfp ___________________________________
• Synchronized
• Volatile

public static final double value_type = 10.2; ___________________________________


18/08/2023 Modifiers Type Name value 10

___________________________________

___________________________________

___________________________________

Slide 11 SCOPE DETERMINES VISIBILITY ___________________________________

❑ Local Scope
public class LocalScopeExample { public static void main(String[] args) {
int localVar = 10; // only main System.out.println(localVar); //} }
___________________________________
❑ Instance Scope
public class InstanceScopeExample {
int instanceVar = 20; // variable instance, anywhere in this class
public void printInstanceVar() {
System.out.println(instanceVar); }
public static void main(String[] args) {
InstanceScopeExample obj = new InstanceScopeExample();
obj.printInstanceVar(); // call method print instance } }
___________________________________
❑ Class Scope
public class ClassScopeExample {
static int classVar = 30; // variable class, anywhere in program
public static void main(String[] args) {
System.out.println(classVar); // In ra giá trị của biến class } }
___________________________________
18/08/2023 11

___________________________________

___________________________________

___________________________________

Slide 12 METHODS ___________________________________

public class MethodExample {


// This is the main method, where the program execution starts
public static void main(String[] args) {
int result = addNumbers(5, 7); // Calling the addNumbers method and storing the result in the 'result' variable
___________________________________
System.out.println("Sum: " + result); }
/* This is the addNumbers method, performing addition of two numbers and returning the result */
public static int addNumbers(int a, int b)
{ int sum = a + b; return sum;
}}

• The main method is the starting point of program execution. ___________________________________


• The addNumbers method performs the addition of two
numbers and returns the result.
• The parameters a and b are input parameters for the
addNumbers method.
• The return type of the addNumbers method is int.
___________________________________
18/08/2023 12

___________________________________

___________________________________

___________________________________
Slide 13 CLASS IN JAVA ___________________________________

Definition Attributes
Methods ___________________________________
Object Constructor
Creation

Access ___________________________________
Modifiers
Polymorphism

Inheritance Encapsulation
___________________________________
18/08/2023 13

___________________________________

___________________________________

___________________________________

Slide 14 CLASS IN JAVA ___________________________________


public class Student { // Attributes
private String name;
private int age;
private String studentId;
// Constructor
___________________________________
public Student(String name, int age, String studentId) {
this.name = name;
this.age = age;
this.studentId = studentId; }
// Method to display student information
public void displayInfo() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
___________________________________
System.out.println("Student ID: " + studentId);}
// Main method
public static void main(String[] args) {
// Create a student object
Student student1 = new Student("Alice", 20, "12345");
// Call the method to display student information
student1.displayInfo(); }}
___________________________________
18/08/2023 14

___________________________________

___________________________________

___________________________________

Slide 15 INHERITANCE/SUBCLASSING ___________________________________

Inheritance or subclassing in Java allows a new class


(subclass) to be built based on an existing class ___________________________________
(superclass), inheriting its attributes and methods while
enabling extension, overriding, and polymorphism,
promoting code reusability and effective project organization.

❖ Superclass and Subclass


___________________________________
❖ Inheritance
❖ Function Extension
❖ Polymorphism
❖ Code Reusability ___________________________________
18/08/2023 15

___________________________________

___________________________________

___________________________________
Slide 16 INHERITANCE/SUBCLASSING ___________________________________
Example of Inheritance in Java:
class Vehicle {
void start() { ___________________________________
System.out.println("Vehicle is starting..."); } }

class Car extends Vehicle {


void accelerate() {
System.out.println("Car is accelerating..."); } } ___________________________________
public class InheritanceExample {
public static void main(String[] args) {
Car myCar = new Car(); myCar.start(); // Inherited
// Method specific to Car class
method from Vehicle class myCar.accelerate(); } }
___________________________________
18/08/2023 16

___________________________________

___________________________________

___________________________________

Slide 17 ALGORITHM FLOWCHART ___________________________________

Start/End Execution Flow ___________________________________

Input/Output
Processing
___________________________________
Data

Connect Conditional ___________________________________


18/08/2023 17

___________________________________

___________________________________

___________________________________

Slide 18 CONTROL STRUCTURES JAVA ___________________________________


if, else if, else, while & fo/while, for

___________________________________

___________________________________

___________________________________
18/08/2023 18

___________________________________

___________________________________

___________________________________
Slide 19 CONTROL STRUCTURES JAVA ___________________________________

switch(expression) {
case constant1:
___________________________________
code_block1();
break; //exit
case constant-expression:
code_block2();
___________________________________
break; //exit
default : //Optional

}
default_code;
___________________________________
18/08/2023 19

___________________________________

___________________________________

___________________________________

Slide 20 CONTROL STRUCTURES JAVA ___________________________________

switch(expression) {
case constant1:
___________________________________
code_block1();
break; //exit
case constant-expression:
code_block2();
___________________________________
break; //exit
default : //Optional

}
default_code;
___________________________________
18/08/2023 20

___________________________________

___________________________________

___________________________________

Slide 21 PROJECT STARTLOGO ___________________________________

___________________________________

___________________________________

___________________________________
18/08/2023
Create new project with Empty Activity 21

___________________________________

___________________________________

___________________________________
Slide 22 PROJECT STARTLOGO ___________________________________

___________________________________

___________________________________

___________________________________
18/08/2023
Name and location 22

___________________________________

___________________________________

___________________________________

Slide 23 PROJECT STARTLOGO ___________________________________


Create an activity for the startup screen named "StartActivity" by right-clicking on the
ScreenWaitingStart directory, then selecting New > Activity > Empty Activity. In the
"New Android Activity" window, set the Activity Name to "StartActivity" and the Layout
Name to "activity_start", choose Java as the source language. ___________________________________

___________________________________

___________________________________
18/08/2023 23

___________________________________

___________________________________

___________________________________

Slide 24 PROJECT STARTLOGO ___________________________________


Create an activity for the startup screen named "StartActivity" by right-clicking on the
ScreenWaitingStart directory, then selecting New > Activity > Empty Activity. In the
"New Android Activity" window, set the Activity Name to "StartActivity" and the Layout
Name to "activity_start", choose Java as the source language. ___________________________________

___________________________________

___________________________________
18/08/2023 24

___________________________________

___________________________________

___________________________________
Slide 25 PROJECT STARTLOGO ___________________________________
Create an image (or vector) icon named "icon.png" (or "icon.xml") and save it in the
drawable directory. Path: ".../ScreenWaitingStart/app/src/main/res/drawable/".

___________________________________

___________________________________

___________________________________
18/08/2023 25

___________________________________

___________________________________

___________________________________

Slide 26 PROJECT STARTLOGO ___________________________________


Open activity_start.xml and drag and drop an ImageView widget to add an image.

___________________________________

___________________________________

___________________________________
18/08/2023 26

___________________________________

___________________________________

___________________________________

Slide 27 PROJECT STARTLOGO ___________________________________


Continuing in the "Pick a resource" window, select "icon.xml" or "icon.png“, press OK.

___________________________________

___________________________________

___________________________________
18/08/2023 27

___________________________________

___________________________________

___________________________________
Slide 28 PROJECT STARTLOGO ___________________________________
Create a styles.xml file in the values directory. Navigate to
".../ScreenWaitingStart/app/src/main/res/values/".

___________________________________

___________________________________

___________________________________
18/08/2023 28

___________________________________

___________________________________

___________________________________

Slide 29 PROJECT STARTLOGO ___________________________________


Add the following code snippet to the styles.xml file. Note that "AppTheme"
will be referenced later. If you make changes in this section, you'll need to
correspondingly update the subsequent references.
___________________________________

___________________________________

___________________________________
18/08/2023 29

___________________________________

___________________________________

___________________________________

Slide 30 PROJECT STARTLOGO ___________________________________


Open AndroidManifest.xml and change the position between the two
activities.
___________________________________

___________________________________

___________________________________
18/08/2023 30

___________________________________

___________________________________

___________________________________
Slide 31 PROJECT STARTLOGO ___________________________________
Add the line android:theme="@style/AppTheme" after the "StartActivity" entry.

___________________________________

___________________________________

___________________________________
18/08/2023 31

___________________________________

___________________________________

___________________________________

Slide 32 PROJECT STARTLOGO ___________________________________


Open StartActivity.java and add a sequence of commands to load content on
the startup screen as desired over a certain period of time.
___________________________________

___________________________________

___________________________________
18/08/2023 32

___________________________________

___________________________________

___________________________________

Slide 33 PROJECT STARTLOGO ___________________________________


And Result….

___________________________________

___________________________________

___________________________________
18/08/2023 33

___________________________________

___________________________________

___________________________________

You might also like