SlideShare a Scribd company logo
1 of 27
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
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

Android App Development 05 : Saving Data
Android App Development 05 : Saving DataAndroid App Development 05 : Saving Data
Android App Development 05 : Saving DataAnuchit 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 StorageMingHo 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 IIEduardo 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 IEduardo Bergavera
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorialinfo_zybotech
 
Databases in Android Application
Databases in Android ApplicationDatabases in Android Application
Databases in Android ApplicationMark Lester Navarro
 
Android Database Tutorial
Android Database TutorialAndroid Database Tutorial
Android Database TutorialPerfect 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 cursorsinfo_zybotech
 
Handling tree control events
Handling tree control eventsHandling tree control events
Handling tree control eventsHemakumar.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
 

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
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
 
Android Data Storagefinal
Android Data StoragefinalAndroid Data Storagefinal
Android Data Storagefinal
 
Android - Data Storage
Android - Data StorageAndroid - Data Storage
Android - Data Storage
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
 
Android-data storage in android-chapter21
Android-data storage in android-chapter21Android-data storage in android-chapter21
Android-data storage in android-chapter21
 
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
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
 
Memory management
Memory managementMemory management
Memory management
 
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
 
Database in Android
Database in AndroidDatabase in Android
Database in Android
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorial
 
Databases in Android Application
Databases in Android ApplicationDatabases in Android Application
Databases in Android Application
 
Android Database Tutorial
Android Database TutorialAndroid Database Tutorial
Android Database Tutorial
 
09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
 
Java Array String
Java Array StringJava Array String
Java Array String
 
Handling tree control events
Handling tree control eventsHandling tree control events
Handling tree control events
 
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)
 

Similar to Android Training (Java Review)

Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2Raghu nath
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java ProgrammingMath-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 TECHNIQUEVinishA23
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorialrajkamaltibacademy
 
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
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2Rakesh Madugula
 
Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptxSajidTk2
 
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 javaCPD INDIA
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...AnkurSingh340457
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitishChaulagai
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascriptUsman Mehmood
 

Similar to Android Training (Java Review) (20)

Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2
 
Java basics
Java basicsJava basics
Java basics
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
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
 
Oops
OopsOops
Oops
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
Java mcq
Java mcqJava mcq
Java mcq
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Java
JavaJava
Java
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
 
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...
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptx
 
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
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
 

More from 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
 

More from Khaled Anaqwa (15)

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

Recently uploaded

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Recently uploaded (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

Android Training (Java Review)

  • 1.
  • 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) {
  • 7.
  • 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