SlideShare a Scribd company logo
Android Training (Java Review)
JAVA INTRODUCTION
History of Java
1991 Stealth Project for consumer electronics market (later Green
Project) Language called Oak then renamed to Java
What is Java?
Java Technology consists of:
1. Java Language
2. Java Platform
3. Java Tools
JAVA TECHNOLOGY
•

Java language is a general-purpose programming language.

•

It can be used to develop software for
• Mobile devices
• Browser-run applets
• Games
• As well as desktop, enterprise (server-side), and scientific applications.

•

Java platform consists of Java virtual machine (JVM) responsible for
hardware abstraction, and a set of libraries that gives Java a rich
foundation.

•

Java tools include the Java compiler as well as various other helper
applications that are used for day-to-day development (e.g. debugger).
JAVA HELLO WORLD PROGRAM
HelloWorld.java

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

Classes and methods are
always defined in blocks of
code enclosed by curly
braces ({ }).

All other statements are
Java language is case-sensitive!
terminated with a semi-colon
This means that
• All code is contained within a class, in this case HelloWorld. HelloWorld is not
(;).
the .java as helloworld
• The file name must match the class name and have asameextension, for example:
•
•

HelloWorld.java
All executable statements are contained within a method, in this case named main().
Use System.out.println() to print text to the terminal.
JAVA IDENTIFIERS
•

An identifier is the name of a class, variable, field, method, or constructor.
• Cannot be a Java keyword or a literal
• Can contain letters, digits, underscores, and dollar signs
• Cannot start with a digit

•

Valid identifier examples:
HelloWorld.java
HelloWorld, args, String, i, Car, $myVar, employeeList2

•

Invalid public class HelloWorld byte, my-Arg, *z
identifier examples: 1st, {

•

Java naming conventions for identifiers:
System.out.println("Hello World!");
• Use CamelCase for most identifiers (classes, interfaces, variables, and
}
methods).
}
• Use an initial capital letter for classes and interfaces, and a lower case letter
for variables and methods.
• For named constants, use all capital letters separated by underscores.
• Avoid using $ characters in identifiers.

public static void main(String[] args) {
RUNNING JAVA PROGRAMS
Android Training (Java Review)
WHAT IS OBJECT ORIENTED PROGRAMMING (OOP)?
•

VIN
License Plate
A software design method that models the characteristics of real or
abstract objects using software classes and objects.

•

Characteristics of objects:
 State (what the objects have)
 Behavior (what the objects do)
Change Gear
 Identity (what makes them unique)

Go
• Definition: an object is a software bundle of related fields (variables)
faster/slower
and methods.
Go in reverse
• In OOP, a program is a collection of objects that act on one another (vs.
Stop
procedures).
Shut-off
Speed
RPM
Gear
Direction
Fuel level
Engine
temperature
WHY OOP?
•

Modularity — Separating entities into separate logical units makes them
easier to code, understand, analyze, test, and maintain.

•

Data hiding (encapsulation) — The implementation of an object’s private
data and actions can change without affecting other objects that
depend on it.

•

Code reuse through:
 Composition — Objects can contain other objects
 Inheritance — Objects can inherit state and behavior of other objects

•

Easier design due to natural modeling
WHY OOP?
“When you learn how to programming you learn how to code
If you learn OOP you learn how to can create & design complex applications “
Simon Allardice
CLASS VS. OBJECT
A class is a template or blueprint for how to build an object.
 A class is a prototype that defines state placeholders and behavior common to
all objects of its kind.
 Each object is a member of a single class — there is no multiple inheritance in
Java.
An object is an instance of a particular class.
 There are typically many object instances for any one given class (or type).
 Each object of a given class has the same built-in behavior but possibly a
different state (data).
 Objects are instantiated (created).
CLASSES IN JAVA
Everything in Java is defined in a class.
In its simplest form, a class just defines a collection of data (like a record or
a C struct).
class Employee {
String name;
String ssn;
String emailAddress;
int yearOfBirth;
}

The order of data fields and methods in a class is not significant.
OBJECTS IN JAVA
To create an object (instance) of a particular class, use
the new operator, followed by an invocation of a constructor for that
class, such as:
new MyClass()

 The constructor method initializes the state of the new object.
 The new operator returns a reference to the newly created object.
the variable type must be compatible with the value type when using object
references, as in:
Employee e = new Employee();

To access member data or methods of an object, use the dot (.) notation:
variable.field or variable.method()
JAVA MEMORY MODEL
Java variables do not contain the actual objects, they contain references to
the objects.
 The actual objects are stored in an area of memory known as the heap.
 Local variables referencing those objects are stored on the stack.
 More than one variable can hold a reference to the same object.
METHOD DECLARATIONS
Each method has a declaration of the following format:
modifiers • The signature of athrows-clause { body } of:
returnType name(params) method consists
modifiers
 The method name
public, private, protected, static,parameter listnative, synchronized
 The final, abstract, (the parameter types and their order)
returnType
• Each method defined in a class must have a unique
A primitive type, object type, or void (no return value)
signature.
name
The name of the • Methods with the same name but different signatures are
method
params
said to be overloaded.
paramType paramName, …
throws-clause
Throws ExceptionType, …
body
The method’s code, including the declaration of local variables, enclosed in braces
Here are some examples of method declarations:
public static void print(Employee e) { ... }
public void print() { ... }
public double sqrt(double n) { ... }
public int max(int x, int y) { ... }
public synchronized add(Employee e) throws DuplicateEntryException { ... }
public int read() throws IOException { ... }
public void println(Object o) { ... }
protected void finalize() throws Throwable { ... }
public native void write(byte[] buffer, int offset, int length) throws IOException { ... }
public boolean equals(Object o) { ... }
private void process(MyObject o) { ... } void run() { ... }
STATIC VS. INSTANCE DATA FIELDS
Static (or class) data fields
 Unique to the entire class
 Shared by all instances (objects) of that class
 Accessible using ClassName.fieldName
 The class name is optional within static and instance methods of the class, unless a
local variable of the same name exists in that scope
 Subject to the declared access mode, accessible from outside the class using the
same syntax
Instance (object) data fields
 Unique to each instance (object) of that class (that is, each object has its own set of
instance fields)
 Accessible within instance methods and constructors using this.fieldName
 The this. qualifier is optional, unless a local variable of the same name exists in that
scope
 Subject to the declared access mode, accessible from outside the class from an
object reference using objectRef.fieldName
STATIC VS. INSTANCE METHODS
Static methods can access only static data and invoke other static
methods.
 Often serve as helper procedures/functions
 Use when the desire is to provide a utility or access to class data only

Instance methods can access both instance and static data and methods.
 Implement behavior for individual objects
 Use when access to instance data/methods is required
An example of static method use is Java’s Math class.
 All of its functionality is provided as static methods implementing mathematical
functions (e.g., Math.sin()).
 The Math class is designed so that you don’t (and can’t) create actual Math
instances.
INHERITANCE
Inheritance allows you to define a class based on the definition of another class.
 The class it inherits from is called a base class or a parent class.
 The derived class is called a subclass or child class.
Subject to any access modifiers, which we’ll discuss later, the subclass gets access to
the fields and methods defined by the base class.
 The subclass can add its own set of fields and methods to the set it inherits from its parent.
Inheritance simplifies modeling of real-world hierarchies through generalization of
common features.
 Common features and functionality is implemented in the base classes, facilitating code
reuse.
 Subclasses can extended, specialize, and override base class functionality.
Inheritance provides a means to create specializations of existing classes. This is
referred to as sub-typing. Each subclass provides specialized state and/or
behavior in addition to the state and behavior inherited by the parent class.
For example, a manager is also an employee but it has a responsibility over a
department, whereas a generic employee does not.
INHERITANCE IN JAVA
You define a subclass in Java using the extends keyword followed by the
base class name. For example:
class Car extends Vehicle { // ... }

 In Java, a class can extend at most one base class. That is, multiple
inheritance is not supported.
 If you don’t explicitly extend a base class, the class inherits from Java’s Object
class.
Java supports multiple levels of inheritance.
 For example, Child can extend Parent, which in turn extends GrandParent, and
so on.
INTERFACES
An interface defines a set of methods, without actually defining their implementation.
 A class can then implement the interface, providing actual definitions for the interface methods.
In essence, an interface serves as a “contract” defining a set of capabilities through method
signatures and return types.
 By implementing the interface, a class “advertises” that it provides the functionality required by the
interface, and agrees to follow that contract for interaction.
The concept of an interface is the cornerstone of object oriented (or modular) programming. Like the
rest of OOP, interfaces are modeled after real world concepts/entities.
For example, one must have a driver’s license to drive a car, regardless for what kind of a car that is
(i.e., make, model, year, engine size, color, style, features etc.).
However, the car must be able to perform certain operations:
 Go forward
 Slowdown/stop (break light)
 Go in reverse
 Turn left (signal light)
 Turn right (signal light)
 Etc.
DEFINING A JAVA INTERFACE
Use the interface keyword to define an interface in Java.
 The naming convention for Java interfaces is the same as for classes: CamelCase
with an initial capital letter.
 The interface definition consists of public abstract method declarations. For example:
public interface Shape {
double getArea();
double getPerimeter();
}

All methods declared by an interface are implicitly public abstract methods.
 You can omit (Remove) either or both of the public and static keywords.
 You must include the semicolon terminator after the method declaration.
Rarely, a Java interface might also declare and initialize public static final fields for
use by subclasses that implement the interface.
Any such field must be declared and initialized by the interface.
You can omit any or all of the public, static, and final keywords in the declaration
IMPLEMENTING A JAVA INTERFACE
You define a class that implements a Java interface using
the implements keyword followed by the interface name. For example:
class Circle implements Shape { // ... }

A concrete class must then provide implementations for all methods
declared by the interface.
 Omitting any method declared by the interface, or not following the same
method signatures and return types, results in a compilation error.
A Java class can implement as many interfaces as needed.
 Simply provide a comma-separated list of interface names following
the implementskeyword. For example:
class ColorCircle implements Shape, Color { // ... }

A Java class can extend a base class and implement one or more
interfaces.
 In the declaration, provide the extends keyword and the base class name,
followed by theimplements keywords and the interface name(s). For example:
class Car extends Vehicle implements Possession { // ... }
ABSTRACT CLASS

1. Abstract classes are meant to be inherited from
2. A class must be declared abstract when it has one or more abstract
methods.
3. A method is declared abstract when it has a method signature, but no
body.
WHEN TO USE ABSTRACT CLASS AND
INTERFACE IN JAVA
•

An abstract class is good if you think you will plan on using inheritance
since it provides a common base class implementation to derived
classes.

•

An abstract class is also good if you want to be able to declare nonpublic members. In an interface, all methods must be public.

•

If you think you will need to add methods in the future, then an abstract
class is a better choice. Because if you add new method headings to an
interface, then all of the classes that already implement that interface
will have to be changed to implement the new methods. That can be
quite a hassle.

•

Interfaces are a good choice when you think that the API will not
change for a while.

•

Interfaces are also good when you want to have something similar to
multiple inheritance, since you can implement multiple interfaces.
PERFORMANCE

• Fast Time
• Light Memory
• Both
EXAMPLES

•

Quiz

•

Loops

•

String
PERFORMANCE QUOTATIONS

1. Always try to limit the scope of Local variable
2. Wherever possible try to use Primitive types instead of
Wrapper classes

3. Avoid creating unnecessary objects and always prefer
to do Lazy Initialization

More Related Content

What's hot (20)

Android App Development 05 : Saving Data
Android App Development 05 : Saving DataAndroid App Development 05 : Saving Data
Android App Development 05 : Saving Data
Anuchit Chalothorn
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
Aakash Ugale
 
Android Data Storagefinal
Android Data StoragefinalAndroid Data Storagefinal
Android Data Storagefinal
Nakka Srilakshmi
 
Android - Data Storage
Android - Data StorageAndroid - Data Storage
Android - Data Storage
MingHo Chang
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
Sourabh Sahu
 
Android-data storage in android-chapter21
Android-data storage in android-chapter21Android-data storage in android-chapter21
Android-data storage in android-chapter21
Dr. Ramkumar Lakshminarayanan
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part II
Eduardo Bergavera
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
Rajeev Uppala
 
Memory management
Memory managementMemory management
Memory management
Vikash Patel
 
Chapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part IChapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part I
Eduardo Bergavera
 
Database in Android
Database in AndroidDatabase in Android
Database in Android
MaryadelMar85
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorial
info_zybotech
 
Databases in Android Application
Databases in Android ApplicationDatabases in Android Application
Databases in Android Application
Mark Lester Navarro
 
Android Database Tutorial
Android Database TutorialAndroid Database Tutorial
Android Database Tutorial
Perfect APK
 
09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)
Oum Saokosal
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
CITSimon
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
info_zybotech
 
Java Array String
Java Array StringJava Array String
Java Array String
Manish Tiwari
 
Handling tree control events
Handling tree control eventsHandling tree control events
Handling tree control events
Hemakumar.S
 
02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)
TECOS
 
Android App Development 05 : Saving Data
Android App Development 05 : Saving DataAndroid App Development 05 : Saving Data
Android App Development 05 : Saving Data
Anuchit Chalothorn
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
Aakash Ugale
 
Android - Data Storage
Android - Data StorageAndroid - Data Storage
Android - Data Storage
MingHo Chang
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part II
Eduardo Bergavera
 
Chapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part IChapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part I
Eduardo Bergavera
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorial
info_zybotech
 
Databases in Android Application
Databases in Android ApplicationDatabases in Android Application
Databases in Android Application
Mark Lester Navarro
 
Android Database Tutorial
Android Database TutorialAndroid Database Tutorial
Android Database Tutorial
Perfect APK
 
09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)
Oum Saokosal
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
info_zybotech
 
Handling tree control events
Handling tree control eventsHandling tree control events
Handling tree control events
Hemakumar.S
 
02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)
TECOS
 

Similar to Android Training (Java Review) (20)

classes-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptxclasses-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
DevaKumari Vijay
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2
Raghu nath
 
Java basics
Java basicsJava basics
Java basics
Shivanshu Purwar
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
Math-Circle
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Madishetty Prathibha
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
AnmolVerma363503
 
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
VinishA23
 
Oops
OopsOops
Oops
Sankar Balasubramanian
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
Abdii Rashid
 
Java mcq
Java mcqJava mcq
Java mcq
avinash9821
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
ssuser8347a1
 
Abstraction encapsulation inheritance polymorphism
Abstraction encapsulation inheritance polymorphismAbstraction encapsulation inheritance polymorphism
Abstraction encapsulation inheritance polymorphism
PriyadharshiniG41
 
Java
JavaJava
Java
Raghu nath
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
rajkamaltibacademy
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Ayes Chinmay
 
JAVA Class Presentation.pdf Vsjsjsnheheh
JAVA Class Presentation.pdf VsjsjsnhehehJAVA Class Presentation.pdf Vsjsjsnheheh
JAVA Class Presentation.pdf Vsjsjsnheheh
AnushreeP4
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 
Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptx
SajidTk2
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
classes-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptxclasses-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2
Raghu nath
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
Math-Circle
 
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
VinishA23
 
Abstraction encapsulation inheritance polymorphism
Abstraction encapsulation inheritance polymorphismAbstraction encapsulation inheritance polymorphism
Abstraction encapsulation inheritance polymorphism
PriyadharshiniG41
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
rajkamaltibacademy
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Ayes Chinmay
 
JAVA Class Presentation.pdf Vsjsjsnheheh
JAVA Class Presentation.pdf VsjsjsnhehehJAVA Class Presentation.pdf Vsjsjsnheheh
JAVA Class Presentation.pdf Vsjsjsnheheh
AnushreeP4
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 
Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptx
SajidTk2
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 

More from Khaled Anaqwa (15)

Android Training (Content Provider)
Android Training (Content Provider)Android Training (Content Provider)
Android Training (Content Provider)
Khaled Anaqwa
 
Android Training (Services)
Android Training (Services)Android Training (Services)
Android Training (Services)
Khaled Anaqwa
 
Android Training (Notifications)
Android Training (Notifications)Android Training (Notifications)
Android Training (Notifications)
Khaled Anaqwa
 
Android Training (Broadcast Receiver)
Android Training (Broadcast Receiver)Android Training (Broadcast Receiver)
Android Training (Broadcast Receiver)
Khaled Anaqwa
 
Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)
Khaled Anaqwa
 
Android Training (Animation)
Android Training (Animation)Android Training (Animation)
Android Training (Animation)
Khaled Anaqwa
 
Android Training (Touch)
Android Training (Touch)Android Training (Touch)
Android Training (Touch)
Khaled Anaqwa
 
Android Training (Sensors)
Android Training (Sensors)Android Training (Sensors)
Android Training (Sensors)
Khaled Anaqwa
 
Android Training (Media)
Android Training (Media)Android Training (Media)
Android Training (Media)
Khaled Anaqwa
 
Android Training (AdapterView & Adapter)
Android Training (AdapterView & Adapter)Android Training (AdapterView & Adapter)
Android Training (AdapterView & Adapter)
Khaled Anaqwa
 
Android Training (ScrollView , Horizontal ScrollView WebView)
Android Training (ScrollView , Horizontal ScrollView  WebView)Android Training (ScrollView , Horizontal ScrollView  WebView)
Android Training (ScrollView , Horizontal ScrollView WebView)
Khaled Anaqwa
 
Android training (android style)
Android training (android style)Android training (android style)
Android training (android style)
Khaled Anaqwa
 
Android Training (Android UI)
Android Training (Android UI)Android Training (Android UI)
Android Training (Android UI)
Khaled Anaqwa
 
Android Training (Intro)
Android Training (Intro)Android Training (Intro)
Android Training (Intro)
Khaled Anaqwa
 
Android Training (android fundamental)
Android Training (android fundamental)Android Training (android fundamental)
Android Training (android fundamental)
Khaled Anaqwa
 
Android Training (Content Provider)
Android Training (Content Provider)Android Training (Content Provider)
Android Training (Content Provider)
Khaled Anaqwa
 
Android Training (Services)
Android Training (Services)Android Training (Services)
Android Training (Services)
Khaled Anaqwa
 
Android Training (Notifications)
Android Training (Notifications)Android Training (Notifications)
Android Training (Notifications)
Khaled Anaqwa
 
Android Training (Broadcast Receiver)
Android Training (Broadcast Receiver)Android Training (Broadcast Receiver)
Android Training (Broadcast Receiver)
Khaled Anaqwa
 
Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)
Khaled Anaqwa
 
Android Training (Animation)
Android Training (Animation)Android Training (Animation)
Android Training (Animation)
Khaled Anaqwa
 
Android Training (Touch)
Android Training (Touch)Android Training (Touch)
Android Training (Touch)
Khaled Anaqwa
 
Android Training (Sensors)
Android Training (Sensors)Android Training (Sensors)
Android Training (Sensors)
Khaled Anaqwa
 
Android Training (Media)
Android Training (Media)Android Training (Media)
Android Training (Media)
Khaled Anaqwa
 
Android Training (AdapterView & Adapter)
Android Training (AdapterView & Adapter)Android Training (AdapterView & Adapter)
Android Training (AdapterView & Adapter)
Khaled Anaqwa
 
Android Training (ScrollView , Horizontal ScrollView WebView)
Android Training (ScrollView , Horizontal ScrollView  WebView)Android Training (ScrollView , Horizontal ScrollView  WebView)
Android Training (ScrollView , Horizontal ScrollView WebView)
Khaled Anaqwa
 
Android training (android style)
Android training (android style)Android training (android style)
Android training (android style)
Khaled Anaqwa
 
Android Training (Android UI)
Android Training (Android UI)Android Training (Android UI)
Android Training (Android UI)
Khaled Anaqwa
 
Android Training (Intro)
Android Training (Intro)Android Training (Intro)
Android Training (Intro)
Khaled Anaqwa
 
Android Training (android fundamental)
Android Training (android fundamental)Android Training (android fundamental)
Android Training (android fundamental)
Khaled Anaqwa
 

Recently uploaded (20)

Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 

Android Training (Java Review)

  • 2. JAVA INTRODUCTION History of Java 1991 Stealth Project for consumer electronics market (later Green Project) Language called Oak then renamed to Java What is Java? Java Technology consists of: 1. Java Language 2. Java Platform 3. Java Tools
  • 3. JAVA TECHNOLOGY • Java language is a general-purpose programming language. • It can be used to develop software for • Mobile devices • Browser-run applets • Games • As well as desktop, enterprise (server-side), and scientific applications. • Java platform consists of Java virtual machine (JVM) responsible for hardware abstraction, and a set of libraries that gives Java a rich foundation. • Java tools include the Java compiler as well as various other helper applications that are used for day-to-day development (e.g. debugger).
  • 4. JAVA HELLO WORLD PROGRAM HelloWorld.java public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } Classes and methods are always defined in blocks of code enclosed by curly braces ({ }). All other statements are Java language is case-sensitive! terminated with a semi-colon This means that • All code is contained within a class, in this case HelloWorld. HelloWorld is not (;). the .java as helloworld • The file name must match the class name and have asameextension, for example: • • HelloWorld.java All executable statements are contained within a method, in this case named main(). Use System.out.println() to print text to the terminal.
  • 5. JAVA IDENTIFIERS • An identifier is the name of a class, variable, field, method, or constructor. • Cannot be a Java keyword or a literal • Can contain letters, digits, underscores, and dollar signs • Cannot start with a digit • Valid identifier examples: HelloWorld.java HelloWorld, args, String, i, Car, $myVar, employeeList2 • Invalid public class HelloWorld byte, my-Arg, *z identifier examples: 1st, { • Java naming conventions for identifiers: System.out.println("Hello World!"); • Use CamelCase for most identifiers (classes, interfaces, variables, and } methods). } • Use an initial capital letter for classes and interfaces, and a lower case letter for variables and methods. • For named constants, use all capital letters separated by underscores. • Avoid using $ characters in identifiers. public static void main(String[] args) {
  • 8. WHAT IS OBJECT ORIENTED PROGRAMMING (OOP)? • VIN License Plate A software design method that models the characteristics of real or abstract objects using software classes and objects. • Characteristics of objects:  State (what the objects have)  Behavior (what the objects do) Change Gear  Identity (what makes them unique) Go • Definition: an object is a software bundle of related fields (variables) faster/slower and methods. Go in reverse • In OOP, a program is a collection of objects that act on one another (vs. Stop procedures). Shut-off Speed RPM Gear Direction Fuel level Engine temperature
  • 9. WHY OOP? • Modularity — Separating entities into separate logical units makes them easier to code, understand, analyze, test, and maintain. • Data hiding (encapsulation) — The implementation of an object’s private data and actions can change without affecting other objects that depend on it. • Code reuse through:  Composition — Objects can contain other objects  Inheritance — Objects can inherit state and behavior of other objects • Easier design due to natural modeling
  • 10. WHY OOP? “When you learn how to programming you learn how to code If you learn OOP you learn how to can create & design complex applications “ Simon Allardice
  • 11. CLASS VS. OBJECT A class is a template or blueprint for how to build an object.  A class is a prototype that defines state placeholders and behavior common to all objects of its kind.  Each object is a member of a single class — there is no multiple inheritance in Java. An object is an instance of a particular class.  There are typically many object instances for any one given class (or type).  Each object of a given class has the same built-in behavior but possibly a different state (data).  Objects are instantiated (created).
  • 12. CLASSES IN JAVA Everything in Java is defined in a class. In its simplest form, a class just defines a collection of data (like a record or a C struct). class Employee { String name; String ssn; String emailAddress; int yearOfBirth; } The order of data fields and methods in a class is not significant.
  • 13. OBJECTS IN JAVA To create an object (instance) of a particular class, use the new operator, followed by an invocation of a constructor for that class, such as: new MyClass()  The constructor method initializes the state of the new object.  The new operator returns a reference to the newly created object. the variable type must be compatible with the value type when using object references, as in: Employee e = new Employee(); To access member data or methods of an object, use the dot (.) notation: variable.field or variable.method()
  • 14. JAVA MEMORY MODEL Java variables do not contain the actual objects, they contain references to the objects.  The actual objects are stored in an area of memory known as the heap.  Local variables referencing those objects are stored on the stack.  More than one variable can hold a reference to the same object.
  • 15. METHOD DECLARATIONS Each method has a declaration of the following format: modifiers • The signature of athrows-clause { body } of: returnType name(params) method consists modifiers  The method name public, private, protected, static,parameter listnative, synchronized  The final, abstract, (the parameter types and their order) returnType • Each method defined in a class must have a unique A primitive type, object type, or void (no return value) signature. name The name of the • Methods with the same name but different signatures are method params said to be overloaded. paramType paramName, … throws-clause Throws ExceptionType, … body The method’s code, including the declaration of local variables, enclosed in braces Here are some examples of method declarations: public static void print(Employee e) { ... } public void print() { ... } public double sqrt(double n) { ... } public int max(int x, int y) { ... } public synchronized add(Employee e) throws DuplicateEntryException { ... } public int read() throws IOException { ... } public void println(Object o) { ... } protected void finalize() throws Throwable { ... } public native void write(byte[] buffer, int offset, int length) throws IOException { ... } public boolean equals(Object o) { ... } private void process(MyObject o) { ... } void run() { ... }
  • 16. STATIC VS. INSTANCE DATA FIELDS Static (or class) data fields  Unique to the entire class  Shared by all instances (objects) of that class  Accessible using ClassName.fieldName  The class name is optional within static and instance methods of the class, unless a local variable of the same name exists in that scope  Subject to the declared access mode, accessible from outside the class using the same syntax Instance (object) data fields  Unique to each instance (object) of that class (that is, each object has its own set of instance fields)  Accessible within instance methods and constructors using this.fieldName  The this. qualifier is optional, unless a local variable of the same name exists in that scope  Subject to the declared access mode, accessible from outside the class from an object reference using objectRef.fieldName
  • 17. STATIC VS. INSTANCE METHODS Static methods can access only static data and invoke other static methods.  Often serve as helper procedures/functions  Use when the desire is to provide a utility or access to class data only Instance methods can access both instance and static data and methods.  Implement behavior for individual objects  Use when access to instance data/methods is required An example of static method use is Java’s Math class.  All of its functionality is provided as static methods implementing mathematical functions (e.g., Math.sin()).  The Math class is designed so that you don’t (and can’t) create actual Math instances.
  • 18. INHERITANCE Inheritance allows you to define a class based on the definition of another class.  The class it inherits from is called a base class or a parent class.  The derived class is called a subclass or child class. Subject to any access modifiers, which we’ll discuss later, the subclass gets access to the fields and methods defined by the base class.  The subclass can add its own set of fields and methods to the set it inherits from its parent. Inheritance simplifies modeling of real-world hierarchies through generalization of common features.  Common features and functionality is implemented in the base classes, facilitating code reuse.  Subclasses can extended, specialize, and override base class functionality. Inheritance provides a means to create specializations of existing classes. This is referred to as sub-typing. Each subclass provides specialized state and/or behavior in addition to the state and behavior inherited by the parent class. For example, a manager is also an employee but it has a responsibility over a department, whereas a generic employee does not.
  • 19. INHERITANCE IN JAVA You define a subclass in Java using the extends keyword followed by the base class name. For example: class Car extends Vehicle { // ... }  In Java, a class can extend at most one base class. That is, multiple inheritance is not supported.  If you don’t explicitly extend a base class, the class inherits from Java’s Object class. Java supports multiple levels of inheritance.  For example, Child can extend Parent, which in turn extends GrandParent, and so on.
  • 20. INTERFACES An interface defines a set of methods, without actually defining their implementation.  A class can then implement the interface, providing actual definitions for the interface methods. In essence, an interface serves as a “contract” defining a set of capabilities through method signatures and return types.  By implementing the interface, a class “advertises” that it provides the functionality required by the interface, and agrees to follow that contract for interaction. The concept of an interface is the cornerstone of object oriented (or modular) programming. Like the rest of OOP, interfaces are modeled after real world concepts/entities. For example, one must have a driver’s license to drive a car, regardless for what kind of a car that is (i.e., make, model, year, engine size, color, style, features etc.). However, the car must be able to perform certain operations:  Go forward  Slowdown/stop (break light)  Go in reverse  Turn left (signal light)  Turn right (signal light)  Etc.
  • 21. DEFINING A JAVA INTERFACE Use the interface keyword to define an interface in Java.  The naming convention for Java interfaces is the same as for classes: CamelCase with an initial capital letter.  The interface definition consists of public abstract method declarations. For example: public interface Shape { double getArea(); double getPerimeter(); } All methods declared by an interface are implicitly public abstract methods.  You can omit (Remove) either or both of the public and static keywords.  You must include the semicolon terminator after the method declaration. Rarely, a Java interface might also declare and initialize public static final fields for use by subclasses that implement the interface. Any such field must be declared and initialized by the interface. You can omit any or all of the public, static, and final keywords in the declaration
  • 22. IMPLEMENTING A JAVA INTERFACE You define a class that implements a Java interface using the implements keyword followed by the interface name. For example: class Circle implements Shape { // ... } A concrete class must then provide implementations for all methods declared by the interface.  Omitting any method declared by the interface, or not following the same method signatures and return types, results in a compilation error. A Java class can implement as many interfaces as needed.  Simply provide a comma-separated list of interface names following the implementskeyword. For example: class ColorCircle implements Shape, Color { // ... } A Java class can extend a base class and implement one or more interfaces.  In the declaration, provide the extends keyword and the base class name, followed by theimplements keywords and the interface name(s). For example: class Car extends Vehicle implements Possession { // ... }
  • 23. ABSTRACT CLASS 1. Abstract classes are meant to be inherited from 2. A class must be declared abstract when it has one or more abstract methods. 3. A method is declared abstract when it has a method signature, but no body.
  • 24. WHEN TO USE ABSTRACT CLASS AND INTERFACE IN JAVA • An abstract class is good if you think you will plan on using inheritance since it provides a common base class implementation to derived classes. • An abstract class is also good if you want to be able to declare nonpublic members. In an interface, all methods must be public. • If you think you will need to add methods in the future, then an abstract class is a better choice. Because if you add new method headings to an interface, then all of the classes that already implement that interface will have to be changed to implement the new methods. That can be quite a hassle. • Interfaces are a good choice when you think that the API will not change for a while. • Interfaces are also good when you want to have something similar to multiple inheritance, since you can implement multiple interfaces.
  • 25. PERFORMANCE • Fast Time • Light Memory • Both
  • 27. PERFORMANCE QUOTATIONS 1. Always try to limit the scope of Local variable 2. Wherever possible try to use Primitive types instead of Wrapper classes 3. Avoid creating unnecessary objects and always prefer to do Lazy Initialization