1 / 40

JAVA 程序设计

JAVA 程序设计. 主要内容. Java 可以做什么? 介绍对象 Primitive Types, Wrappers, and Boxing 声明和注释 构造器和可见性 Static, Final, and 枚举类型 命名,操作和精度 继承 异常 接口. Java 可以做什么?. Java 可以做什么? 介绍对象 Primitive Types, Wrappers, and Boxing 声明和注释 构造器和可见性 Static, Final, and 枚举类型 命名,操作和精度 继承 异常 接口. 跨平台.

sondra
Download Presentation

JAVA 程序设计

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JAVA程序设计

  2. 主要内容 • Java可以做什么? • 介绍对象 • Primitive Types, Wrappers, and Boxing • 声明和注释 • 构造器和可见性 • Static, Final, and 枚举类型 • 命名,操作和精度 • 继承 • 异常 • 接口

  3. Java可以做什么? • Java可以做什么? • 介绍对象 • Primitive Types, Wrappers, and Boxing • 声明和注释 • 构造器和可见性 • Static, Final, and 枚举类型 • 命名,操作和精度 • 继承 • 异常 • 接口

  4. 跨平台

  5. 易用性 • Threads • Exceptions • Garbage collection

  6. run-time library • java.lang • java.io • java.net • java.util • java.util.regex • java.sql

  7. Java平台 • J2ME • J2SE • J2EE

  8. A Java Desktop Application

  9. 介绍对象 • Java可以做什么? • 介绍对象 • Primitive Types, Wrappers, and Boxing • 声明和注释 • 构造器和可见性 • Static, Final, and 枚举类型 • 命名,操作和精度 • 继承 • 异常 • 接口

  10. 对象和类 • 类:人 • 对象:张三 • 对象是类的一个实例

  11. 属性和方法 • 属性(人.name) • 方法(人.eat()) • Demo(person1)

  12. Primitive Types, Wrappers, and Boxing • Java可以做什么? • 介绍对象 • Primitive Types, Wrappers, and Boxing • 声明和注释 • 构造器和可见性 • Static, Final, and 枚举类型 • 命名,操作和精度 • 继承 • 异常 • 接口

  13. Primitive Types • boolean (for true/false values) • char (for character data, ultimately to be input or printed) • int, long, byte, short (for arithmetic on whole numbers) • double, float (for arithmetic on the real numbers)

  14. Wrappers • boolean java.lang.Boolean • char java.lang.Character • int java.lang.Integer • long java.lang.Long • byte java.lang.Byte • short java.lang.Short • double java.lang.Double • float java.lang.Float

  15. Autoboxing and Unboxing int i = 27; Integer myInt = i; // autobox! Double dObj = 27.0; // autobox double d = dObj; // unbox, gets value 27.0

  16. java.lang.Object • public java.lang.Object(); // constructor public • java.lang.String toString(); • public boolean equals(java.lang.Object); • public native int hashCode(); • public final Class getClass(); • protected native java.lang.Object clone() throws CloneNotSupportedException; // methods relating to thread programming • public final native void notify(); • public final void wait() throws InterruptedException;

  17. java.lang.String • String drinkPref = new String( "I like tea" ); • String drinkPref = "I like tea"; • String s = "ABCD".toLowerCase();

  18. 声明和注释 • Java可以做什么? • 介绍对象 • Primitive Types, Wrappers, and Boxing • 声明和注释 • 构造器和可见性 • Static, Final, and 枚举类型 • 命名,操作和精度 • 继承 • 异常 • 接口

  19. 声明和注释 • if,else,while,for • 注释 • // This is a comments • /* This is a lot of comments */ • /** This is a lot of comments */

  20. 构造器和可见性 • Java可以做什么? • 介绍对象 • Primitive Types, Wrappers, and Boxing • 声明和注释 • 构造器和可见性 • Static, Final, and 枚举类型 • 命名,操作和精度 • 继承 • 异常 • 接口

  21. 构造器 • Demo(Timestamp)

  22. import and Package • Package • import

  23. 可见性 • private • protected • public

  24. Java robot

  25. Static, Final, and 枚举类型 • Java可以做什么? • 介绍对象 • Primitive Types, Wrappers, and Boxing • 声明和注释 • 构造器和可见性 • Static, Final, and 枚举类型 • 命名,操作和精度 • 继承 • 数据 • 异常 • 接口

  26. What you can make static • Data • Methods • Blocks • Classes

  27. What Field Modifier final Means • Data • Methods • Classes

  28. 枚举类型 enum Bread { wholewheat, ninegrain, rye, french } Bread todaysLoaf; todaysLoaf = Bread.rye;

  29. 命名,操作和精度 • Java可以做什么? • 介绍对象 • Primitive Types, Wrappers, and Boxing • 声明和注释 • 构造器和可见性 • Static, Final, and 枚举类型 • 命名,操作和精度 • 继承 • 异常 • 接口

  30. Keywords

  31. operators • ++ -- • ~ • ! • - + * / % = *= /= %= += -= • << >> >>> • instanceof • <= >< >= • == != • & ^ | • && || ? : • <<= >>= >>>= • &= ^= |=

  32. 继承 • Java可以做什么? • 介绍对象 • Primitive Types, Wrappers, and Boxing • 声明和注释 • 构造器和可见性 • Static, Final, and 枚举类型 • 命名,操作和精度 • 继承 • 异常 • 接口

  33. 继承 • 动物(哺乳动物(猫,狗)) • Demo(animal)

  34. 异常 • Java可以做什么? • 介绍对象 • Primitive Types, Wrappers, and Boxing • 声明和注释 • 构造器和可见性 • Static, Final, and 枚举类型 • 命名,操作和精度 • 继承 • 异常 • 接口

  35. java异常术语

  36. 接口 • Java可以做什么? • 介绍对象 • Primitive Types, Wrappers, and Boxing • 声明和注释 • 构造器和可见性 • Static, Final, and 枚举类型 • 命名,操作和精度 • 继承 • 异常 • 接口

  37. 接口 • 仅仅定义服务和功能 • 干净的(没有任何具体实现) • 一个类可以实现多个接口 • 接口可以继承接口 • 最低限度耦合

  38. 一些原则 • 面向接口编程 • 方法的参数要用接口

  39. Interface java.lang.Comparable public interface Comparable { public int compareTo(Object o); }

  40. 作业 • Why use object wrappers instead of primitive types directly?

More Related