基础类和工具类.ppt
《基础类和工具类.ppt》由会员分享,可在线阅读,更多相关《基础类和工具类.ppt(46页珍藏版)》请在三一办公上搜索。
1、面向对象编程,1,4.2.2 对象初始化-静态调用,public class ObjectCreation TestClass testClass=new TestClass(fieldValue);static TestClass testClass2=new TestClass(staticValue);static testClass2.test();public ObjectCreation()System.out.println(ObjectCreation init);public ObjectCreation(String name)System.out.println(Obje
2、ctCreation+name+init);,面向对象编程,2,public static void main(String args)ObjectCreation objectCreation=new ObjectCreation(object1);ObjectCreation objectCreation2=new ObjectCreation(object2);class TestClass public TestClass(String name)System.out.println(TestClass+name+init);void test()System.out.println(
3、makeInner()invoked);,面向对象编程,3,基础类和工具类,面向对象编程,5,主要内容,Java类库 语言基础类 向量类 工具类,面向对象编程,6,Java类库,Java的类库是系统提供的已实现的标准类的集合,是Java编程的API(Application Program Interface),它可以帮助开发者方便、快捷地开发Java程序。这些系统定义好的类根据实现的功能不同,可以划分成不同的集合,每个集合是一个包,合称为类库。Java的类库大部分是由它的发明者SUN公司 提供的,这些类库称为基础类库(JFC)。API 应用程序编程接口面向过程语言 函数库(子程序包)面向对象语
4、言 类库,面向对象编程,7,Java类库,类库的结构java.lang 语言基础类库(System、Math、Thread、基本数据类型类)java.util Java的工具类库(向量、栈、日期)java.io Java的标准输入输出类库java.applet 用于实现Java Applet小程序的类库java.awt 用于构建图形用户界面的类库java.awt.event 界面用户交互控制和事件响应类 库 Java的用于实现网络功能的类库使用JDK Document查看类库,面向对象编程,8,语言基础类库-Object类,Java程序中所有类的直接或间接父类,也是类库中所有类的的父类,所有的
5、其他类都是从Object类派生。构造方法:Object()一般方法:Object clone()生成当前对象的一个拷贝。boolean equals(Object obj)比较两个对象是否 相同。Class getClass()获取当前对象所属的类信息。String toString()用来返回当前对象本身的有关 信息。,面向对象编程,9,public class BasicObjectDemo public static void main(String args)A a1=new A();A a2=new A();A a3=a1;B b=new B();System.out.println
6、(a1.equals(a2);System.out.println(a3.equals(a1);System.out.println(a1.hashCode();System.out.println(a1.toString();class A class B,面向对象编程,10,实例,public class PhoneNumber private String region;private String number;public String toString()return book.ch6.PhoneNumber+region=+region+,number=+number+;,面向对
7、象编程,11,System类,属性public static InputStream in public static PrintStream outpublic static PrintStream err 获取系统信息、完成系统操作的方法public static long currentTimeMillis();获取自1970年1月1日零时至当前系统时刻的微秒数 972370687290public static void exit(int status);强制Java虚拟机退出运行状态,并把状态信息status 返回给运行虚拟机的操作系统。System.exit(0);public s
8、tatic void gc();强制调用Java虚拟机的垃圾回收功能。,面向对象编程,12,语言基础类库:System类,System是一个功能强大的类,它提供了标准输入输出、运行时的系统信息等工具系统功能类获取系统标准输入/输出System.in,System.out,System.err获取系统信息System.currentTimeMillis()执行系统操作System.exit(0);System.gc();,面向对象编程,13,语言基础类库:数据类型类,基本数据类型 vs.数据类型类boolean vs Boolean,char vs Character等数据类型类规定了数据类型的
9、最大值、最小值构造函数:如new Integer(10);完成不同数据类型间转换,注意不同的数据类使用的方法会有不同。Double.toString(0.08)、Integer.parseInt(“123”)、Double.ValueOf(“0.08”).intValue()等,见JDK Doc,面向对象编程,14,语言基础类库:Math类,Math类用来完成常用的数学运算数学常量:E,PI数学运算Math.abs(-8.09);Math.exp(5.7);Math.random();Math.sqrt(9.08);Math.pow(2,3);/乘方Math.round(99.6);均为sta
10、tic,使用时无需创建实例 Math.method(variable);,面向对象编程,15,数学运算的Math类,属性public final static double E;/数学常量epublic final static double PI;/圆周率常量方法(均为静态方法)public static int abs(int i);public static double sin(double a);public static double log(double a);public static double max(double a,double b);public static do
11、uble pow(double a,double b);public static double random();/产生01之间伪 随机数,面向对象编程,16,数学运算的Math类,public static double exp(double a);public static int round(float a);public static double sqrt(double a);例:System.out.println(Math.E);2.718281828.System.out.println(Math.PI);3.14159265System.out.println(Math.p
12、ow(2,3);8.0System.out.println(Math.round(99.6);100System.out.println(Math.abs(-8.09);8.09,面向对象编程,17,public class StringDemo public static void main(String args)String s;s=String test;s=new String(String test);int stringLength=s.length();System.out.println(stringLength=+stringLength);boolean startTes
13、t=s.startsWith(Str);boolean endTest=s.endsWith(est);System.out.println(startTest=+startTest);System.out.println(endTest=+endTest);int blankIndex=s.indexOf();System.out.println(blankIndex=+blankIndex);,字符串相关类String,面向对象编程,18,int subStringIndex=s.indexOf(est);System.out.println(subStringIndex=+subStri
14、ngIndex);int lastIndex=s.lastIndexOf(s);System.out.println(lastIndex=+lastIndex);String s2=String test2;int compare=pareTo(s);System.out.println(compare=+compare);boolean equalTest=s2.equals(s);System.out.println(equalTest=+equalTest);char singleChar=s.charAt(3);System.out.println(singleChar=+single
15、Char);,面向对象编程,19,String subString=s.substring(3);System.out.println(subString=+subString);String trimString=s.trim();System.out.println(trimString=+trimString+);String upperCase=s.toUpperCase();System.out.println(upperCase=+upperCase);String lowerCase=s.toLowerCase();System.out.println(lowerCase=+lo
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基础 工具

链接地址:https://www.31ppt.com/p-6223833.html