Basic java for Android Developer

898 views

Published on

Getting Starts Basic java for Android Developer

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
898
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
82
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Basic java for Android Developer

  1. 1. Basic JAVA for Android Development Nattapong Tonprasert
  2. 2. Reference • Head First Java, O'Reilly
  3. 3. Introduction
  4. 4. The Way Java Works
  5. 5. Installation Java Platform (JDK) • Download : http://www.oracle.com/technetwork/ java/javase/downloads/index.html
  6. 6. Look how easy it is to write java
  7. 7. Look how easy it is to write java
  8. 8. Code structure in Java
  9. 9. Code structure in Java source file class file method 1 statement method 2 statement
  10. 10. Code structure in Java public class Dog { ! ! ! ! } class public class Dog { void bark () { ! ! } } method public class Dog { void bark () { statement1;! ! ! statement2; } } statements
  11. 11. Anatomy of a class
  12. 12. Writing a class with a main public class MyFirstApp { ! public static void main (String[] args) { System.out.println("I Rule!"); System.out.println("The World!"); } }
  13. 13. Statements int x = 3; String name = "Dirk"; x = x * 17; System.out.print("x is " + x); double d = Math.random(); // this is a comment
  14. 14. Condition if (x == 10) { System.out.println("x must be 10"); } else { System.out.println("x isn't 10"); } ! if ((x < 3) && (name.equals("Dirk"))) { System.out.println("Gently"); } ! if ((x < 3) || (name.equals("Dirk"))) { System.out.println("Gently"); }
  15. 15. Looping while (x > 12) { x = x - 1; System.out.println("x is " + x); } ! for (x = 0; x < 10; x = x + 1) { System.out.println("x is " + x); }
  16. 16. Classes and Objects
  17. 17. Classes and Objects
  18. 18. Classes and Objects
  19. 19. Classes and Objects
  20. 20. thinking about objects When you design a class, think about the objects that will be created from that class type. Think about • things the object knows • things the object does
  21. 21. thinking about objects
  22. 22. What’s the difference between a class and an object? • A class is not an object (but it’s used to construct them) • A class is a blueprint for an object
  23. 23. Encapsulation • public • private - self class • protected - self package
  24. 24. Class GoodDog class GoodDog { private int size; public int getSize() { return size; } public void setSize(int s) { size = s; } void bark() { if (size > 60) { System.out.println("Woof! Woof!"); } else if (size > 14) { System.out.println("Ruf! Ruf!"); } else { System.out.println("Yip! Yip!"); } } }
  25. 25. GoodDog Test Drive public class GoodDogTestDrive { public static void main (String[] args) { GoodDog one = new GoodDog(); one.setSize(70); GoodDog two = new GoodDog(); two.setSize(8); System.out.println("Dog one: " + one.getSize()); System.out.println("Dog two: " + two.getSize()); one.bark(); two.bark(); } }
  26. 26. Static variables
  27. 27. Static variables
  28. 28. Static variables class Player { static int playerCount = 0; private String name; ! public Player(String n) { name = n; playerCount++; } } ! public class PlayerTestDrive { public static void main(String[] args) { System.out.println(Player.playerCount); Player one = new Player("Tiger Woods"); System.out.println(Player.playerCount); } ! }

×