About Java (SE) ore than Beginning                      Jay Xu
Agenda Java History                         Exception OO                                   Primitive Type / Wrapper      O...
Java History I
Java History II
Java History III
Object / Class / Interface I What is an object / class (interface)?    Human VS Jay    Template VS Instance
public class Human {    private int age; // default value?    private String name; // default value?    public void setNam...
Object / Class / Interface II Why OO?   Cohesion / encapsulation   Direct      Human.say(“Hello”) VS say(&Human, “hello”) ...
Inheritance / Polymorphism Inheritance    Code Reusing (copy / extend) Polymorphism    Dynamic Runtime Binding        Dyna...
Polymorphism (Java VS                                C++)public class Human{               class Human{    public void say...
Overload / Override Overload    Different Method Signature       Same Method Name       Different Parameters (?)       Dif...
public class SuperOverrideOverload {    public void overload(int number) {        System.out.println("super int overload")...
public class OverrideOverload extends SuperOverrideOverload {    @Override    public void overload(int number) {        Sy...
Access Level / Visibility public protected private (default)
super / this / static super.xxx() super() this.xxx() this() static      public static void main(String[] args) Instance in...
Inner Class Types    Inner class    Static inner class    Anonymous (parameter) inner class this Access level
(Static) Inner Classpublic class Outer {    private int id;    public class Inner {        private int id;        private ...
Anonymous (Parameter)Inner ClassRunnable runnable = new Runnable() {    public void run() {        ...    }};public void d...
Primitive Type / Wrapper byte - Byte         char - Character     8 bit signed        16 bit unsigned short - Short       ...
Exception Why Exception?    Error Code VS Exception    What’s in an Exception?        Message (String)        Cause (Throw...
Tea Break
Java 6 Architecture http://java.sun.com/javase/6/docs/
New Features Since Java 5 Varargs Enhanced for Loop Annotation Auto Boxing / Unboxing Enum    Constants VS Enum    java.la...
Varargspublic int sum(int... numbers) {    int sum = 0;    for(int number:numbers) {        sum += number;    }    return ...
Enhanced for Loop
Enhanced for LoopList <String> strings = ...;
Enhanced for LoopList <String> strings = ...;
Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {
Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {    String string = strings.get(i);
Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {    String string = strings.get(i);  ...
Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {    String string = strings.get(i);  ...
Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {    String string = strings.get(i);  ...
Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {    String string = strings.get(i);  ...
Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {    String string = strings.get(i);  ...
Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {    String string = strings.get(i);  ...
Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {    String string = strings.get(i);  ...
Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {    String string = strings.get(i);  ...
Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {    String string = strings.get(i);  ...
Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {    String string = strings.get(i);  ...
Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {    String string = strings.get(i);  ...
Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {    String string = strings.get(i);  ...
Annotationpublic class Annotation {    @Override    public String toString() {...}}
Auto Boxing / UnboxingList<Integer> numbers = ...;for(int i = 0;i<100;i++) {    numbers.add(i);}int sum = 0;for(int number...
Enumpublic enum Gender {           public abstract    MALE() {               String toString();        public String      ...
Static Importpublic double calculate (double a, double b, double c){    return Math.sqrt(a * a + b * b) + 2 * Math.PI *Mat...
Generics Type Template    String[] VS List (prev.) Erasing (during compilation) How to Use?    String[] VS List<String> (n...
Generics IList strings = ...;strings.add(“hello”);strings.add(Boolean.TRUE); // error?for(int i = 0;i<strings.length();i++...
Generics II
Generics IIpublic class List<T> {
Generics IIpublic class List<T> {    public void add(T t) {...}
Generics IIpublic class List<T> {    public void add(T t) {...}    public T get(int index) {...}
Generics IIpublic class List<T> {    public void add(T t) {...}    public T get(int index) {...}    ....
Generics IIpublic class List<T> {    public void add(T t) {...}    public T get(int index) {...}    ....}
Generics IIpublic class List<T> {    public void add(T t) {...}    public T get(int index) {...}    ....}
Generics IIpublic class List<T> {    public void add(T t) {...}    public T get(int index) {...}    ....}public static <T ...
Generics IIpublic class List<T> {    public void add(T t) {...}    public T get(int index) {...}    ....}public static <T ...
Generics IIpublic class List<T> {    public void add(T t) {...}    public T get(int index) {...}    ....}public static <T ...
Generics IIpublic class List<T> {    public void add(T t) {...}    public T get(int index) {...}    ....}public static <T ...
Generics IIpublic class List<T> {    public void add(T t) {...}    public T get(int index) {...}    ....}public static <T ...
Generics IIpublic class List<T> {    public void add(T t) {...}    public T get(int index) {...}    ....}public static <T ...
Generics IIpublic class List<T> {    public void add(T t) {...}    public T get(int index) {...}    ....}public static <T ...
Generics IIpublic class List<T> {    public void add(T t) {...}    public T get(int index) {...}    ....}public static <T ...
Touch GC What is Garbage?             “Generation”    Isolated Objects       Memory Leak (in Java)? How to Collect?       ...
Revision Java History                         Inner Class OO                                   Exception      Object / Cla...
Q   A
Upcoming SlideShare
Loading in...5
×

About java

735

Published on

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

  • Be the first to like this

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

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • About java

    1. 1. About Java (SE) ore than Beginning Jay Xu
    2. 2. Agenda Java History Exception OO Primitive Type / Wrapper Object / Class / Interface Tea break Inheritance / Java Architecture at a Polymorphism Glance (Java 6) Override / Overload New Features since JDK 5 Access Level / Visibility Generics this / super / static Touch GC Inner Class
    3. 3. Java History I
    4. 4. Java History II
    5. 5. Java History III
    6. 6. Object / Class / Interface I What is an object / class (interface)? Human VS Jay Template VS Instance
    7. 7. public class Human { private int age; // default value? private String name; // default value? public void setName(String name) { this.name = name; } public void setAge(int age) { this.age = age; }}Human jay = new Human();jay.setName(“Jay”);jay.setAge(28);
    8. 8. Object / Class / Interface II Why OO? Cohesion / encapsulation Direct Human.say(“Hello”) VS say(&Human, “hello”) Inheritance Unit
    9. 9. Inheritance / Polymorphism Inheritance Code Reusing (copy / extend) Polymorphism Dynamic Runtime Binding Dynamic Runtime Binding Java VS C++ (e.g.)
    10. 10. Polymorphism (Java VS C++)public class Human{ class Human{ public void say(){ public: System.out.println(“I virtual void say(){am a human”); cout << “I am a human”; } }} };public class Jay extends Human{ class Jay : public Human{ public void say(){ public: System.out.println(“I void say(){am Jay”); cout << “I am Jay”; } }} };Human human = new Jay(); Human* human = new Jay();human.say(); // which say()? human->say(); // which say()?
    11. 11. Overload / Override Overload Different Method Signature Same Method Name Different Parameters (?) Different Return Type (?) Override Same Method Signature
    12. 12. public class SuperOverrideOverload { public void overload(int number) { System.out.println("super int overload"); } public void overload(Integer number) { System.out.println("super Integer overload"); } public void overload(long number) { System.out.println("super long overload"); } public void overload(Long number) { System.out.println("super Long overload"); } public void overload(Object number) { System.out.println("super Object overload"); } public static void main(String[] args) { new SuperOverrideOverload().overload(100); }}
    13. 13. public class OverrideOverload extends SuperOverrideOverload { @Override public void overload(int number) { System.out.println("int overload"); } @Override public void overload(Integer number) { System.out.println("Integer overload"); } @Override public void overload(long number) { System.out.println("long overload"); } @Override public void overload(Long number) { System.out.println("Long overload"); } @Override public void overload(Object number) { System.out.println("Object overload"); } public static void main(String[] args) { new OverrideOverload().overload(100); }}
    14. 14. Access Level / Visibility public protected private (default)
    15. 15. super / this / static super.xxx() super() this.xxx() this() static public static void main(String[] args) Instance initialize order Default values
    16. 16. Inner Class Types Inner class Static inner class Anonymous (parameter) inner class this Access level
    17. 17. (Static) Inner Classpublic class Outer { private int id; public class Inner { private int id; private int getID() { return this.id; // which id? } }}new Outer().new Inner();public class Outer { public static class Inner {}}new Outer.Inner();
    18. 18. Anonymous (Parameter)Inner ClassRunnable runnable = new Runnable() { public void run() { ... }};public void doRun(Runnable runnable) {...}doRun(new Runnable() { public void run() { ... }});
    19. 19. Primitive Type / Wrapper byte - Byte char - Character 8 bit signed 16 bit unsigned short - Short float - Float 16 bit signed 32 bit signed int - Integer double - Double 32 bit signed 64 bit signed long - Long boolean - Boolean 64 bit signed
    20. 20. Exception Why Exception? Error Code VS Exception What’s in an Exception? Message (String) Cause (Throwable) Stacktrace[] exception location info. (log4j) try / catch / finally
    21. 21. Tea Break
    22. 22. Java 6 Architecture http://java.sun.com/javase/6/docs/
    23. 23. New Features Since Java 5 Varargs Enhanced for Loop Annotation Auto Boxing / Unboxing Enum Constants VS Enum java.lang.Enum Static Import
    24. 24. Varargspublic int sum(int... numbers) { int sum = 0; for(int number:numbers) { sum += number; } return sum;}
    25. 25. Enhanced for Loop
    26. 26. Enhanced for LoopList <String> strings = ...;
    27. 27. Enhanced for LoopList <String> strings = ...;
    28. 28. Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) {
    29. 29. Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) { String string = strings.get(i);
    30. 30. Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) { String string = strings.get(i); ...
    31. 31. Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) { String string = strings.get(i); ...}
    32. 32. Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) { String string = strings.get(i); ...}
    33. 33. Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) { String string = strings.get(i); ...}Iterator<String> iter = string.iterator();
    34. 34. Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) { String string = strings.get(i); ...}Iterator<String> iter = string.iterator();while(iter.hasNext()) {
    35. 35. Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) { String string = strings.get(i); ...}Iterator<String> iter = string.iterator();while(iter.hasNext()) { String string = iter.next();
    36. 36. Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) { String string = strings.get(i); ...}Iterator<String> iter = string.iterator();while(iter.hasNext()) { String string = iter.next(); ...
    37. 37. Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) { String string = strings.get(i); ...}Iterator<String> iter = string.iterator();while(iter.hasNext()) { String string = iter.next(); ...}
    38. 38. Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) { String string = strings.get(i); ...}Iterator<String> iter = string.iterator();while(iter.hasNext()) { String string = iter.next(); ...}
    39. 39. Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) { String string = strings.get(i); ...}Iterator<String> iter = string.iterator();while(iter.hasNext()) { String string = iter.next(); ...}for(String string:strings) {
    40. 40. Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) { String string = strings.get(i); ...}Iterator<String> iter = string.iterator();while(iter.hasNext()) { String string = iter.next(); ...}for(String string:strings) { ...
    41. 41. Enhanced for LoopList <String> strings = ...;for (int i = 0;i<strings.length();i++) { String string = strings.get(i); ...}Iterator<String> iter = string.iterator();while(iter.hasNext()) { String string = iter.next(); ...}for(String string:strings) { ...}
    42. 42. Annotationpublic class Annotation { @Override public String toString() {...}}
    43. 43. Auto Boxing / UnboxingList<Integer> numbers = ...;for(int i = 0;i<100;i++) { numbers.add(i);}int sum = 0;for(int number:numbers) { sum += number;}
    44. 44. Enumpublic enum Gender { public abstract MALE() { String toString(); public String }toString() { return “ ”; switch(gender) { case MALE: ... } case FEMALE: ... }, FEMALE() { } public StringtoString() { if(gender == MALE) {...} return “ ”; } gender.name(); }; Enum.valueOf(Gender.clas s, “MALE”);
    45. 45. Static Importpublic double calculate (double a, double b, double c){ return Math.sqrt(a * a + b * b) + 2 * Math.PI *Math.sin(c);}import static java.lang.Math.*;public double calculate (double a, double b, double c){ return sqrt(a * a + b * b) + 2 * PI * sin(c);}
    46. 46. Generics Type Template String[] VS List (prev.) Erasing (during compilation) How to Use? String[] VS List<String> (now) ?, extends How to Define?
    47. 47. Generics IList strings = ...;strings.add(“hello”);strings.add(Boolean.TRUE); // error?for(int i = 0;i<strings.length();i++) { String string = (String)strings.get(i); ...}List<String> strings = ...;
    48. 48. Generics II
    49. 49. Generics IIpublic class List<T> {
    50. 50. Generics IIpublic class List<T> { public void add(T t) {...}
    51. 51. Generics IIpublic class List<T> { public void add(T t) {...} public T get(int index) {...}
    52. 52. Generics IIpublic class List<T> { public void add(T t) {...} public T get(int index) {...} ....
    53. 53. Generics IIpublic class List<T> { public void add(T t) {...} public T get(int index) {...} ....}
    54. 54. Generics IIpublic class List<T> { public void add(T t) {...} public T get(int index) {...} ....}
    55. 55. Generics IIpublic class List<T> { public void add(T t) {...} public T get(int index) {...} ....}public static <T extends Enum<T>> T valueOf(Class<T> type,String string) {...}
    56. 56. Generics IIpublic class List<T> { public void add(T t) {...} public T get(int index) {...} ....}public static <T extends Enum<T>> T valueOf(Class<T> type,String string) {...}
    57. 57. Generics IIpublic class List<T> { public void add(T t) {...} public T get(int index) {...} ....}public static <T extends Enum<T>> T valueOf(Class<T> type,String string) {...}List<String> strings = ...;
    58. 58. Generics IIpublic class List<T> { public void add(T t) {...} public T get(int index) {...} ....}public static <T extends Enum<T>> T valueOf(Class<T> type,String string) {...}List<String> strings = ...;public addObjects(List<Object> list) {...}
    59. 59. Generics IIpublic class List<T> { public void add(T t) {...} public T get(int index) {...} ....}public static <T extends Enum<T>> T valueOf(Class<T> type,String string) {...}List<String> strings = ...;public addObjects(List<Object> list) {...}addObjects(strings); // error?
    60. 60. Generics IIpublic class List<T> { public void add(T t) {...} public T get(int index) {...} ....}public static <T extends Enum<T>> T valueOf(Class<T> type,String string) {...}List<String> strings = ...;public addObjects(List<Object> list) {...}addObjects(strings); // error?
    61. 61. Generics IIpublic class List<T> { public void add(T t) {...} public T get(int index) {...} ....}public static <T extends Enum<T>> T valueOf(Class<T> type,String string) {...}List<String> strings = ...;public addObjects(List<Object> list) {...}addObjects(strings); // error?public addObjects(List<? extends Object> list) {...}
    62. 62. Generics IIpublic class List<T> { public void add(T t) {...} public T get(int index) {...} ....}public static <T extends Enum<T>> T valueOf(Class<T> type,String string) {...}List<String> strings = ...;public addObjects(List<Object> list) {...}addObjects(strings); // error?public addObjects(List<? extends Object> list) {...}addObjects(strings); // error?
    63. 63. Touch GC What is Garbage? “Generation” Isolated Objects Memory Leak (in Java)? How to Collect? Why? Heap VS Stack How to Avoid? Reference Count Compress and Collect Copy and Collect
    64. 64. Revision Java History Inner Class OO Exception Object / Class / Interface Primitive Type / Wrapper Inheritance / Java Architecture at a Polymorphism Glance (Java 6) Override / Overload New Features since JDK 5 Access Level / Visibility Generics this / super / static Touch GC
    65. 65. Q A
    1. A particular slide catching your eye?

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

    ×