SlideShare a Scribd company logo
1 of 40
Download to read offline
Java for Android
 Development
Object-Oriented Programming Concepts
Comments
/* multiline
   comment */

// singleline comment

/** Description
 *
 * @param input
 * @return output
 */
Primitive Data Types
●   byte (8-bit signed integer between -128 and 127)
●   short (16-bit signed integer between -32,768 and 32,767)
●   int (32-bit signed integer between -2,147,483,648 and 2,147,483,647)
●   long (64-bit signed integer between -9,223,372,036,854,775,808 and
    9,223,372,036,854,775,807)
●   float (32-bit floating point number)
● double (64-bit floating point number)
● boolean (true and false)
● char (single 16-bit Unicode character)
Operators
If


if (a > 0) {
    // ...
} else if (a == 0) {
    // ...
} else {
    // ...
}
boolean a;
if (a == true) ...
if (a == false) ...
if (a) ...
if (!a) ...
switch
switch (code) {
   case 200:
      // ...
      break;
   case 404:
      // ...
      break;
   default:
      // ...
      break;
}
Loops
●   while
●   do-while
●   for
●   for-each
while
int n = 10
while (n > 0) {
    n--;
}
do
n = 10;
do {
   n--;
} while (n > 0);
for
for (int i = 0; i < 100; i++) {
   //...
}
for-each
for (Object o : objects) {
   System.out.print(o.toString());
}
Branching statements
● break
● continue
● return
Arrays
String
● Immutable
● StringBuilder

●   Никогда не
    проверяйте
    равенство строк с
    помощью == !!!
Class
●   class MyClass {...}
●   instance (object)
●   fields
●   methods
●   inner and nested classes
●   this
●   final
●   static
import
●   import java.util.List;
●   import org.apache.http.HttpEntity;
●   import org.json.JSONObject;
●   import android.content.SharedPreferences;
●   import com.inflow.model.Feed;
●   import java.io.IOException;
Access Modifiers
Inheritance
●   class MyClass extends BaseClass {...}
●   super
●   @Override
Abstract Classes and Methods
● abstract class MyClass {...}
● abstract void myMethod {...}
Interfaces
● interface
● class MyClass implements MyInterface
java.lang.Object

  ○   public String toString();

  ○   public boolean equals(Object obj);

  ○   public native int hashCode();

  ○   protected native Object clone() throws CloneNotSupportedException;

  ○   protected void finalize() throws Throwable;

  ○   public final native Class<?> getClass();

  ○   public final native void notify();

  ○   public final native void notifyAll();

  ○   public final native void wait(long timeout) throws InterruptedException;

  ○   public final void wait(long timeout, int nanos) throws InterruptedException;

  ○   public final void wait() throws InterruptedException;
equals()
●   Рефлексивность: x.equals(x) -> true при x не null;

●   Симметричность: x.equals(y) <- -> y.equals(x) при x,y не null;

●   Транзитивность: x.equals(y), y.equals(z) -> x.equals(z) при x,y,z не null;

●   Непротиворечивость (consistency) «одинаковых» вызовов;

●   x.equals(null) – всегда false (при x не null).
hashCode()
●   Метод hashCode() надо переопределять в каждом классе,
    переопределяющем метод equals().
●   Контракт метода hashCode():
        ■   Непротиворечивость (consistency), «осмысленно»
            возвращает то же число;
        ■   Равные по equals() объекты дают равные значения
            hashCode();
Nested Classes
class OuterClass {
  ...
  static class StaticNestedClass {
      ...
  }
}

MyOuterClass.MyStaticNestedClass myObject = new
   MyOuterClass.MyStaticNestedClass();
Inner classes
class OuterClass {
  ...
  static class StaticNestedClass {
      ...
  }
  class InnerClass {
      ...
  }
}

OuterClass.InnerClass innerObject = outerObject.new
  InnerClass();
Anonymous classes
button.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
       //...
    }
});
Enums
public enum Day {
  SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
  THURSDAY, FRIDAY, SATURDAY
}
Exceptions
●   try
●   catch
●   finally
●   throw
Collections
●   List
●   Set
●   Map
●   Queue
●   Stack
●   ...
Extra topics
● Reflection
● Threading
● Generics
Literature
● Cay Horstmann Core Java
● Bruce Eckel Thinking in Java
Practice
●   любая предметная область
●   наследование
●   абстрактный класс
●   интерфейс

More Related Content

What's hot

Javascript engine performance
Javascript engine performanceJavascript engine performance
Javascript engine performance
Duoyi Wu
 
Native code in Android applications
Native code in Android applicationsNative code in Android applications
Native code in Android applications
Dmitry Matyukhin
 
From Runnable and synchronized To atomically() and parallel()
From Runnable and synchronized To atomically() and parallel()From Runnable and synchronized To atomically() and parallel()
From Runnable and synchronized To atomically() and parallel()
José Paumard
 
Pavel kravchenko obj c runtime
Pavel kravchenko obj c runtimePavel kravchenko obj c runtime
Pavel kravchenko obj c runtime
DneprCiklumEvents
 

What's hot (20)

Datatype in JavaScript
Datatype in JavaScriptDatatype in JavaScript
Datatype in JavaScript
 
Introduzione a .NET / Mono
Introduzione a .NET / MonoIntroduzione a .NET / Mono
Introduzione a .NET / Mono
 
Session 08 - OOP with Java - continued
Session 08 - OOP with Java - continuedSession 08 - OOP with Java - continued
Session 08 - OOP with Java - continued
 
2013 11 CSharp Tutorial Struct and Class
2013 11 CSharp Tutorial Struct and Class2013 11 CSharp Tutorial Struct and Class
2013 11 CSharp Tutorial Struct and Class
 
Javascript engine performance
Javascript engine performanceJavascript engine performance
Javascript engine performance
 
Js training
Js trainingJs training
Js training
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
 
Understanding Javascript Engines
Understanding Javascript Engines Understanding Javascript Engines
Understanding Javascript Engines
 
4.trasformers filters-adapters
4.trasformers filters-adapters4.trasformers filters-adapters
4.trasformers filters-adapters
 
Let's talk about jni
Let's talk about jniLet's talk about jni
Let's talk about jni
 
C++ Advanced Features
C++ Advanced FeaturesC++ Advanced Features
C++ Advanced Features
 
C++ Advanced Features
C++ Advanced FeaturesC++ Advanced Features
C++ Advanced Features
 
Native code in Android applications
Native code in Android applicationsNative code in Android applications
Native code in Android applications
 
Groovy closures
Groovy closuresGroovy closures
Groovy closures
 
From Runnable and synchronized To atomically() and parallel()
From Runnable and synchronized To atomically() and parallel()From Runnable and synchronized To atomically() and parallel()
From Runnable and synchronized To atomically() and parallel()
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
 
core java
core javacore java
core java
 
Pavel kravchenko obj c runtime
Pavel kravchenko obj c runtimePavel kravchenko obj c runtime
Pavel kravchenko obj c runtime
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
Beyond design principles and patterns (muCon 2019 edition)
Beyond design principles and patterns (muCon 2019 edition)Beyond design principles and patterns (muCon 2019 edition)
Beyond design principles and patterns (muCon 2019 edition)
 

Similar to Android Development Course in HSE lecture #2

Csharp In Detail Part2
Csharp In Detail Part2Csharp In Detail Part2
Csharp In Detail Part2
Mohamed Krar
 
Metaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And GrailsMetaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And Grails
zenMonkey
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
HCMUTE
 

Similar to Android Development Course in HSE lecture #2 (20)

core java
 core java core java
core java
 
Java Day-4
Java Day-4Java Day-4
Java Day-4
 
Csharp In Detail Part2
Csharp In Detail Part2Csharp In Detail Part2
Csharp In Detail Part2
 
Groovy AST Transformations
Groovy AST TransformationsGroovy AST Transformations
Groovy AST Transformations
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?
 
Core2 Document - Java SCORE Overview.pptx.pdf
Core2 Document - Java SCORE Overview.pptx.pdfCore2 Document - Java SCORE Overview.pptx.pdf
Core2 Document - Java SCORE Overview.pptx.pdf
 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#
 
Semmle Codeql
Semmle Codeql Semmle Codeql
Semmle Codeql
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing Speed
 
Metaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And GrailsMetaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And Grails
 
CHAPTER 3 part2.pdf
CHAPTER 3 part2.pdfCHAPTER 3 part2.pdf
CHAPTER 3 part2.pdf
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Java 5 New Feature
Java 5 New FeatureJava 5 New Feature
Java 5 New Feature
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
For Beginners - C#
For Beginners - C#For Beginners - C#
For Beginners - C#
 
Static Analysis in IDEA
Static Analysis in IDEAStatic Analysis in IDEA
Static Analysis in IDEA
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 

More from Empatika

More from Empatika (20)

Gamification 101 - Intro
Gamification 101 - IntroGamification 101 - Intro
Gamification 101 - Intro
 
Travel 101 - On Distribution
Travel 101 - On DistributionTravel 101 - On Distribution
Travel 101 - On Distribution
 
Travel Tech 101 - Introduction
Travel Tech 101 - IntroductionTravel Tech 101 - Introduction
Travel Tech 101 - Introduction
 
Subscriptions business model - FAQ
Subscriptions business model - FAQSubscriptions business model - FAQ
Subscriptions business model - FAQ
 
Theories of Innovation
Theories of InnovationTheories of Innovation
Theories of Innovation
 
Lessons learned & not learned at MSU
Lessons learned & not learned at MSULessons learned & not learned at MSU
Lessons learned & not learned at MSU
 
Disruptive Innovations
Disruptive InnovationsDisruptive Innovations
Disruptive Innovations
 
US Commercial Aviation History - 1
US Commercial Aviation History - 1US Commercial Aviation History - 1
US Commercial Aviation History - 1
 
Life in a startup
Life in a startupLife in a startup
Life in a startup
 
Machine Learning - Empatika Open
Machine Learning - Empatika OpenMachine Learning - Empatika Open
Machine Learning - Empatika Open
 
Machine learning 2 - Neural Networks
Machine learning 2 - Neural NetworksMachine learning 2 - Neural Networks
Machine learning 2 - Neural Networks
 
Machine Learning - Introduction
Machine Learning - IntroductionMachine Learning - Introduction
Machine Learning - Introduction
 
Online Travel 3.0 - Mobile Traveler (Rus)
Online Travel 3.0 - Mobile Traveler (Rus)Online Travel 3.0 - Mobile Traveler (Rus)
Online Travel 3.0 - Mobile Traveler (Rus)
 
Flight to 1000000 users - Lviv IT Arena 2016
Flight to 1000000 users - Lviv IT Arena 2016Flight to 1000000 users - Lviv IT Arena 2016
Flight to 1000000 users - Lviv IT Arena 2016
 
introduction to artificial intelligence
introduction to artificial intelligenceintroduction to artificial intelligence
introduction to artificial intelligence
 
Travel inequality - Bayram Annakov
Travel inequality - Bayram AnnakovTravel inequality - Bayram Annakov
Travel inequality - Bayram Annakov
 
App in the Air Travel Hack Moscow - Fall, 2015
App in the Air Travel Hack Moscow - Fall, 2015App in the Air Travel Hack Moscow - Fall, 2015
App in the Air Travel Hack Moscow - Fall, 2015
 
Product Management
Product ManagementProduct Management
Product Management
 
Intro to Exponentials - Part 1
Intro to Exponentials - Part 1Intro to Exponentials - Part 1
Intro to Exponentials - Part 1
 
Singularity University Executive Program - Day 1
Singularity University Executive Program - Day 1Singularity University Executive Program - Day 1
Singularity University Executive Program - Day 1
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 

Android Development Course in HSE lecture #2

  • 1. Java for Android Development
  • 3. Comments /* multiline comment */ // singleline comment /** Description * * @param input * @return output */
  • 4. Primitive Data Types ● byte (8-bit signed integer between -128 and 127) ● short (16-bit signed integer between -32,768 and 32,767) ● int (32-bit signed integer between -2,147,483,648 and 2,147,483,647) ● long (64-bit signed integer between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807) ● float (32-bit floating point number) ● double (64-bit floating point number) ● boolean (true and false) ● char (single 16-bit Unicode character)
  • 6. If if (a > 0) { // ... } else if (a == 0) { // ... } else { // ... }
  • 7. boolean a; if (a == true) ... if (a == false) ... if (a) ... if (!a) ...
  • 8. switch switch (code) { case 200: // ... break; case 404: // ... break; default: // ... break; }
  • 9. Loops ● while ● do-while ● for ● for-each
  • 10. while int n = 10 while (n > 0) { n--; }
  • 11. do n = 10; do { n--; } while (n > 0);
  • 12. for for (int i = 0; i < 100; i++) { //... }
  • 13. for-each for (Object o : objects) { System.out.print(o.toString()); }
  • 14. Branching statements ● break ● continue ● return
  • 16. String ● Immutable ● StringBuilder ● Никогда не проверяйте равенство строк с помощью == !!!
  • 17.
  • 18. Class ● class MyClass {...} ● instance (object) ● fields ● methods ● inner and nested classes ● this ● final ● static
  • 19.
  • 20. import ● import java.util.List; ● import org.apache.http.HttpEntity; ● import org.json.JSONObject; ● import android.content.SharedPreferences; ● import com.inflow.model.Feed; ● import java.io.IOException;
  • 22. Inheritance ● class MyClass extends BaseClass {...} ● super ● @Override
  • 23.
  • 24. Abstract Classes and Methods ● abstract class MyClass {...} ● abstract void myMethod {...}
  • 25.
  • 26.
  • 27. Interfaces ● interface ● class MyClass implements MyInterface
  • 28.
  • 29. java.lang.Object ○ public String toString(); ○ public boolean equals(Object obj); ○ public native int hashCode(); ○ protected native Object clone() throws CloneNotSupportedException; ○ protected void finalize() throws Throwable; ○ public final native Class<?> getClass(); ○ public final native void notify(); ○ public final native void notifyAll(); ○ public final native void wait(long timeout) throws InterruptedException; ○ public final void wait(long timeout, int nanos) throws InterruptedException; ○ public final void wait() throws InterruptedException;
  • 30. equals() ● Рефлексивность: x.equals(x) -> true при x не null; ● Симметричность: x.equals(y) <- -> y.equals(x) при x,y не null; ● Транзитивность: x.equals(y), y.equals(z) -> x.equals(z) при x,y,z не null; ● Непротиворечивость (consistency) «одинаковых» вызовов; ● x.equals(null) – всегда false (при x не null).
  • 31. hashCode() ● Метод hashCode() надо переопределять в каждом классе, переопределяющем метод equals(). ● Контракт метода hashCode(): ■ Непротиворечивость (consistency), «осмысленно» возвращает то же число; ■ Равные по equals() объекты дают равные значения hashCode();
  • 32. Nested Classes class OuterClass { ... static class StaticNestedClass { ... } } MyOuterClass.MyStaticNestedClass myObject = new MyOuterClass.MyStaticNestedClass();
  • 33. Inner classes class OuterClass { ... static class StaticNestedClass { ... } class InnerClass { ... } } OuterClass.InnerClass innerObject = outerObject.new InnerClass();
  • 34. Anonymous classes button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //... } });
  • 35. Enums public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }
  • 36. Exceptions ● try ● catch ● finally ● throw
  • 37. Collections ● List ● Set ● Map ● Queue ● Stack ● ...
  • 38. Extra topics ● Reflection ● Threading ● Generics
  • 39. Literature ● Cay Horstmann Core Java ● Bruce Eckel Thinking in Java
  • 40. Practice ● любая предметная область ● наследование ● абстрактный класс ● интерфейс