Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

JAVA 1

Uploaded by

aelshahed2027
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

JAVA 1

Uploaded by

aelshahed2027
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 50

Mobile Application Development

Eng. Nada Mohamed Sarhan


Outline
• Overview
• Java Programming Fundamental & OOP
• Kotlin Programming
• Android Application Development
• Android Security Essentials
• Flutter Applications Development for IOS &
Android
OVERVIEW
• What is programs & programming languages?
• Machine language
• Assembly language
• High-level language
PROGRAM (S/W)
Set of instruction that tell the computer what to
do.

• We use program to interact/talk with computer.


• To writ programs we use programming language.
PROGRAMING LANGUAGES
Language used to write programs.
– Computer are machine.
• They don’t understand human language.
– Programs are written in a language a computer
can understand.
• Programing language.
MACHINE LANGUAGE
A computer’s native language.
• Uses 0|1 -> Binary language
• To add 2 & 3the result: 1101101010011010
– Very hard to use.
• Machine dependent | differs among different
types of machines.
ASSEMBLY LANGUAGE
Was developed to make programming easier.

• Machine dependent.
• Introduced keyword | add, sub, …ect.
HIGH-LEVEL LANGUAGE
A new generation of programming languages
• Use English words | easy to learn & use.
• Machine independent | your program will run
on different machines.
• Instruction are called ‘statements’.
HIGH-LEVEL LANGUAGE
• A program written in high-level language is
called ‘source program’ or ‘source code’.
• To add 2 & 3the result: result = 2 + 3;

• A ‘compiler’ or ‘interpreter’ is used to


translate source code to machine code.
Java Programming Fundamental & OOP
• Sun Microsystem
• Green project, 1991
• Oak.
• JAVA, 1995
• Developed at Sun Microsystem which was
purchased by Oracle in 2010.
Java Programming Fundamental & OOP
Why learn JAVA?
• High-level, general-purpose, OOP Language.
– Easy & used to develop any kind of programs.
• WORA (write once, run anywhere)
• Very popular.
– A huge online community for getting help.
• Can be used in Android development.
• C based Language.
• Learn C, C++ & C# easier.
Java Programming Fundamental & OOP

Java Editions: (assg.)


• J2SE
• J2EE
• J2ME
Java Programming Fundamental & OOP
JAVA Architecture: (assg.)
• JVM (JAVA virtual machine):
– Execute java program on different machine (WORA)
• JER (JAVA Runtime environment)
• JDK (JAVA development kit):
Java Programming Fundamental & OOP
• Programming fundamental
1. Basic syntax
2. Data types
3. Variables
4. Operators
5. Comments
6. Access modifiers
7. Conditions
8. Loops
9. Methods
Basic syntax
• Class name:
– First letter should be Upper case
• Ex: class MyFirstJavaClass {}
• Method name:
– All method name should start with a lower case letter
• Ex: public void myMethodName() {}
• Package name:
– All lower case
– Ex: com.name.applicationname.subpackage
Basic syntax
• Case sensitivity:
– Differentiating bet. Capital & lower case letter.
• Identifier ‘Hello’ & ‘hello’ would have diff meaning
• Program file name:
– Class name & append ‘.java’
• public static void main (String[] args) {}
Data types
• define the type of information a variable can
hold and the operations that can be
performed on it.

1. Primitive
2. Non-primitive
Primitive data types
1. Numeric Types:
• int: Stores whole numbers (integers)
– Ex: int age = 25;
• double: Stores floating-point numbers with
decimals
– Ex: double pi = 3.14159;
• float: Similar to double but uses less memory
– Ex: float distance = 10.5f;
Primitive data types
• byte: Stores small whole numbers (8 bits)
– Ex: byte initial = -128;
• short: Stores whole numbers larger than bytes
(16 bits)
– Ex: short temperature = 30;
• long: Stores very large whole numbers (64
bits)
– Ex: long worldPopulation = 8_000_000_000L;
Primitive data types
2. Character Type:
– char: Stores a single character enclosed in single
quotes
• Ex: char initial = 'A';
3. Boolean Type:
– boolean: Represents logical values (true or false)
• Ex: boolean isComplete = true;
Non-Primitive data types
• complex data structures that can hold collections
of other data or represent real-world entities.
• String: Represents a sequence of characters
– Ex: String name = "Alice";
• Arrays: Ordered collections of elements of the
same data type
– Example: int[] numbers = {1, 5, 9};
• Classes: Blueprints for creating objects
– Example: class Person { ... }
Variables
• like named boxes that hold data.
• Act as containers to store information.
• Each variable has a specific data type.
Variables
• Declaring Variables:
• Data Type: The type of information the
variable will store (e.g., int for
integers, String for text).
• Name: A unique identifier you'll use to refer to
the variable (follows specific naming rules).
Operators
1. Arithmetic Operators
2. Assignment Operators
3. Relational Operators
4. Logical Operators
5. Unary Operators
6. Conditional (Ternary) Operator
7. Bitwise Operators (advanced)
8. Shift Operators (advanced)
9. Instanceof Operator
Arithmetic Operators
• +: Addition (e.g., int sum = 10 + 5;)
• -: Subtraction (e.g., int difference = 20 - 7;)
• *: Multiplication (e.g., int product = 3 * 4;)
• /: Division (e.g., double result = 10.0 / 3.0;)
• %: Modulo (remainder after division) (e.g., int
remainder = 11 % 3;)
Assignment Operators
• These are used to assign values to variables:

• =: Simple assignment (e.g., int age = 25;)

• +=, -=, *=, /=, %=: Combined assignment


operators (e.g., age += 3; is equivalent to age =
age + 3;)
Relational Operators
• These compare values and return true or false:
• ==: Equal to (e.g., x == 10;)
• !=: Not equal to (e.g., y != 20;)
• <: Less than (e.g., a < b;)
• >: Greater than (e.g., c > d;)
• <=: Less than or equal to (e.g., age <= 30;)
• >=: Greater than or equal to (e.g., grade >= 80;)
Logical Operators
• &&: AND (both conditions must be true)
(e.g., (x > 5) && (y < 15);)
• ||: OR (at least one condition must be true)
(e.g., (age >= 18) || (hasAuthorization);)
• !: NOT (inverts the truth value) (e.g., !
(isRegistered);)
Unary Operators
• ++: Increment (increases the value by 1)
(e.g., count++)
• --: Decrement (decreases the value by 1)
(e.g., value--)
• -: Negation (inverts the sign) (e.g., -number;)
• !: Logical NOT (inverts the truth value) (e.g., !
truth;)
Comment
• Comments are lines of text that are ignored by
the compiler
1. Single-line Comments (//):
• Ex: int age = 25; // This is a single-line comment
explaining the age variable
2. Multi-line Comments (/* and */):
• Ex: /*
* This is a multi-line comment
*/
Access modifiers
• keywords that define the accessibility (visibility) of classes,
methods, variables, constructors, and other members of your
program.
1. Public (accessible from anywhere)
2. Private (accessible within the class)
3. Protect (accessible from within the class they are declared in,
as well as from subclasses)
4. Default (accessible from within the same package)
Condition
• Controlling the flow of your program's
execution.
1. if statement
2. if-else statement
3. if-else if ladder
4. switch statement
If statement
• Checks a single condition.
If-else statement
If-else if ladder
Switch statement
Loops
• allow you to execute a block of code repeatedly as
long as a certain condition is met.
1. for loop
2. while loop
3. do-while loop
For loop
• It has three parts within parentheses:
– Initialization: Executes once before the loop starts
(typically used to declare a loop counter variable).
– Condition: Evaluated before each iteration. The loop
continues as long as the condition is true.
– Increment/Decrement: Executed after each iteration
(often used to update the loop counter).
For loop
• Ex:
While loop
• Executes a code block repeatedly as long as a
given condition is true.
• The condition is checked at the beginning of
each iteration.
While loop
• Ex:
Do while loop
• Similar to while, but the code block is
guaranteed to execute at least once, even if
the condition is initially false.
Do while loop
• Ex:
Loops
• Choosing the Right Loop:

• Use for loops when you know the exact number of iterations
beforehand (e.g., iterating over an array).
• Use while loops when the condition for continuing the loop
may change dynamically based on user input or calculations.
• Use do-while loops when you need the code block to execute
at least once, regardless of the initial condition.
Methods
• methods are reusable blocks of code that
perform specific tasks.
Methods
• Structure of methods:
1. Modifiers (optional): Keywords like public, private, or static that control
access and behavior.
2. Return Type: The data type of the value the method will return (can
be void if it doesn't return anything).
3. Method Name: A unique identifier that reflects the method's purpose
(follows naming conventions).
4. Parameters (optional): A comma-separated list of variables enclosed in
parentheses that accept values when the method is called.
5. Method Body: The block of code enclosed in curly braces {} that defines
the actions the method performs.
Methods
• Types of Methods:
• Void Methods: Don't return any value (use void as the return
type).
• Value-Returning Methods: Return a specific data type using
the return statement within the method body
Methods
• Ex:
Methods
• Benefits of Methods:
• Reusability: Write code once and use it multiple times
throughout your program or even in other programs.
• Modularity: Break down complex programs into smaller,
manageable functions.
• Readability: Improve code organization and clarity by
grouping related functionalities.
• Maintainability: Easier to modify or debug specific parts of
the code by focusing on individual methods.
Java Programming Fundamental & OOP
• Object-Oriented Programming (OOP)
1. Classes
2. Objects
3. Abstraction
4. Encapsulation
5. Inheritance
6. Polymorphism
7. Exceptions
8. Abstract classes
9. Interfaces
10. File (I/O)

You might also like