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 a...
Operators
Ifif (a > 0) {    // ...} else if (a == 0) {    // ...} else {    // ...}
boolean a;if (a == true) ...if (a == false) ...if (a) ...if (!a) ...
switchswitch (code) {   case 200:      // ...      break;   case 404:      // ...      break;   default:      // ...      ...
Loops●   while●   do-while●   for●   for-each
whileint n = 10while (n > 0) {    n--;}
don = 10;do {   n--;} while (n > 0);
forfor (int i = 0; i < 100; i++) {   //...}
for-eachfor (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●   sta...
import●   import java.util.List;●   import org.apache.http.HttpEntity;●   import org.json.JSONObject;●   import android.co...
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();...
equals()●   Рефлексивность: x.equals(x) -> true при x не null;●   Симметричность: x.equals(y) <- -> y.equals(x) при x,y не...
hashCode()●   Метод hashCode() надо переопределять в каждом классе,    переопределяющем метод equals().●   Контракт метода...
Nested Classesclass OuterClass {  ...  static class StaticNestedClass {      ...  }}MyOuterClass.MyStaticNestedClass myObj...
Inner classesclass OuterClass {  ...  static class StaticNestedClass {      ...  }  class InnerClass {      ...  }}OuterCl...
Anonymous classesbutton.setOnClickListener(new OnClickListener() {    @Override    public void onClick(View v) {       //....
Enumspublic 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●   любая предметная область●   наследование●   абстрактный класс●   интерфейс
Android Development Course in HSE lecture #2
Android Development Course in HSE lecture #2
Android Development Course in HSE lecture #2
Android Development Course in HSE lecture #2
Android Development Course in HSE lecture #2
Android Development Course in HSE lecture #2
Upcoming SlideShare
Loading in...5
×

Android Development Course in HSE lecture #2

422

Published on

Java for Android Development

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
422
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Android Development Course in HSE lecture #2

  1. 1. Java for Android Development
  2. 2. Object-Oriented Programming Concepts
  3. 3. Comments/* multiline comment */// singleline comment/** Description * * @param input * @return output */
  4. 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)
  5. 5. Operators
  6. 6. Ifif (a > 0) { // ...} else if (a == 0) { // ...} else { // ...}
  7. 7. boolean a;if (a == true) ...if (a == false) ...if (a) ...if (!a) ...
  8. 8. switchswitch (code) { case 200: // ... break; case 404: // ... break; default: // ... break;}
  9. 9. Loops● while● do-while● for● for-each
  10. 10. whileint n = 10while (n > 0) { n--;}
  11. 11. don = 10;do { n--;} while (n > 0);
  12. 12. forfor (int i = 0; i < 100; i++) { //...}
  13. 13. for-eachfor (Object o : objects) { System.out.print(o.toString());}
  14. 14. Branching statements● break● continue● return
  15. 15. Arrays
  16. 16. String● Immutable● StringBuilder● Никогда не проверяйте равенство строк с помощью == !!!
  17. 17. Class● class MyClass {...}● instance (object)● fields● methods● inner and nested classes● this● final● static
  18. 18. 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;
  19. 19. Access Modifiers
  20. 20. Inheritance● class MyClass extends BaseClass {...}● super● @Override
  21. 21. Abstract Classes and Methods● abstract class MyClass {...}● abstract void myMethod {...}
  22. 22. Interfaces● interface● class MyClass implements MyInterface
  23. 23. 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;
  24. 24. 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).
  25. 25. hashCode()● Метод hashCode() надо переопределять в каждом классе, переопределяющем метод equals().● Контракт метода hashCode(): ■ Непротиворечивость (consistency), «осмысленно» возвращает то же число; ■ Равные по equals() объекты дают равные значения hashCode();
  26. 26. Nested Classesclass OuterClass { ... static class StaticNestedClass { ... }}MyOuterClass.MyStaticNestedClass myObject = new MyOuterClass.MyStaticNestedClass();
  27. 27. Inner classesclass OuterClass { ... static class StaticNestedClass { ... } class InnerClass { ... }}OuterClass.InnerClass innerObject = outerObject.new InnerClass();
  28. 28. Anonymous classesbutton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //... }});
  29. 29. Enumspublic enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY}
  30. 30. Exceptions● try● catch● finally● throw
  31. 31. Collections● List● Set● Map● Queue● Stack● ...
  32. 32. Extra topics● Reflection● Threading● Generics
  33. 33. Literature● Cay Horstmann Core Java● Bruce Eckel Thinking in Java
  34. 34. Practice● любая предметная область● наследование● абстрактный класс● интерфейс
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×