《JAVA程序设计汇总》由会员分享,可在线阅读,更多相关《JAVA程序设计汇总(41页珍藏版)》请在金锄头文库上搜索。
1、JAVAJAVA程序设计汇总程序设计汇总主要内容nJava可以做什么?n介绍对象 nPrimitive Types, Wrappers, and Boxing n声明和注释 n构造器和可见性 nStatic, Final, and 枚举类型 n命名,操作和精度n继承 n异常n接口Java可以做什么?nJava可以做什么?可以做什么?n介绍对象 nPrimitive Types, Wrappers, and Boxingn声明和注释 n构造器和可见性 nStatic, Final, and 枚举类型 n命名,操作和精度 n继承 n异常n接口跨平台 易用性nThreads nExceptions
2、nGarbage collection run-time library njava.utilnjava.util.regexnjava.sqlJava平台nJ2MEnJ2SEnJ2EEA Java Desktop Application 介绍对象nJava可以做什么?n介绍对象 nPrimitive Types, Wrappers, and Boxing n声明和注释 n构造器和可见性 nStatic, Final, and 枚举类型 n命名,操作和精度n继承 n异常n接口对象和类n类:人n对象:张三n对象是类的一个实例属性和方法n属性(人.name)n方法(人.eat())nDemo(pe
3、rson1)Primitive Types, Wrappers, and Boxing nJava可以做什么?n介绍对象 nPrimitive Types, Wrappers, and Boxing n声明和注释 n构造器和可见性 nStatic, Final, and 枚举类型 n命名,操作和精度 n继承 n异常n接口Primitive Typesnboolean (for true/false values) nchar (for character data, ultimately to be input or printed) nint, long, byte, short (for
4、arithmetic on whole numbers)ndouble, float (for arithmetic on the real numbers)Wrappersnbooleanjava.lang.Booleanncharjava.lang.Characternint java.lang.Integernlongjava.lang.Longnbytejava.lang.Bytenshortjava.lang.Shortndouble java.lang.Doublenfloatjava.lang.FloatAutoboxing and Unboxing int i = 27; In
5、teger myInt = i; / autobox! Double dObj = 27.0; / autobox double d = dObj; / unbox, gets value 27.0 java.lang.Object npublic java.lang.Object(); / constructor public njava.lang.String toString(); npublic boolean equals(java.lang.Object); npublic native int hashCode(); npublic final Class getClass();
6、 nprotected native java.lang.Object clone() throws CloneNotSupportedException; / methods relating to thread programming npublic final native void notify(); npublic final void wait() throws InterruptedException; java.lang.String nString drinkPref = new String( I like tea ); nString drinkPref = I like
7、 tea; nString s = ABCD.toLowerCase(); 声明和注释nJava可以做什么?n介绍对象 nPrimitive Types, Wrappers, and Boxing n声明和注释 n构造器和可见性 nStatic, Final, and 枚举类型 n命名,操作和精度n继承 n异常n接口声明和注释nif,else,while,forn注释n/ This is a commentsn/* This is a lot of comments */n/* This is a lot of comments */构造器和可见性nJava可以做什么?n介绍对象 nPrimi
8、tive Types, Wrappers, and Boxing n声明和注释 n构造器和可见性 nStatic, Final, and 枚举类型 n命名,操作和精度 n继承n异常n接口构造器nDemo(Timestamp)import and PackagenPackagenimport可见性nprivatenprotectednpublic Java robot Static, Final, and 枚举类型nJava可以做什么?n介绍对象 nPrimitive Types, Wrappers, and Boxing n声明和注释 n构造器和可见性 nStatic, Final, and
9、枚举类型 n命名,操作和精度n继承 n数据 n异常n接口What you can make static nData nMethods nBlocks nClasses What Field Modifier final Means nData nMethods nClasses 枚举类型enum Bread wholewheat, ninegrain, rye, french Bread todaysLoaf; todaysLoaf = Bread.rye; 命名,操作和精度nJava可以做什么?n介绍对象 nPrimitive Types, Wrappers, and Boxing n声明
10、和注释 n构造器和可见性 nStatic, Final, and 枚举类型 n命名,操作和精度n继承 n异常n接口Keywords operators n+ -nn!n- + * / % = *= /= %= += -=n ninstanceof n=n= !=n& |n& | ? :n= =n&= = |=继承nJava可以做什么?n介绍对象 nPrimitive Types, Wrappers, and Boxing n声明和注释 n构造器和可见性 nStatic, Final, and 枚举类型 n命名,操作和精度n继承 n异常n接口继承n动物(哺乳动物(猫,狗)nDemo(animal
11、)异常nJava可以做什么?n介绍对象 nPrimitive Types, Wrappers, and Boxing n声明和注释 n构造器和可见性 nStatic, Final, and 枚举类型 n命名,操作和精度n继承 n异常n接口java异常术语 接口nJava可以做什么?n介绍对象 nPrimitive Types, Wrappers, and Boxing n声明和注释 n构造器和可见性 nStatic, Final, and 枚举类型 n命名,操作和精度n继承 n异常n接口接口n仅仅定义服务和功能n干净的(没有任何具体实现)n一个类可以实现多个接口n接口可以继承接口n最低限度耦合一些原则n面向接口编程n方法的参数要用接口Interface java.lang.Comparable public interface Comparable public int compareTo(Object o); 作业nWhy use object wrappers instead of primitive types directly? 结束结束