第6讲面向对象特征2内容摘要:

静态变量  public static final InputStream in (标准输入流 )  public static final PrintStream out (标准输出流 )  public static final PrintStream err (标准错误输出流 )  静态方法  public static void arraycopy(Object src, int srcPos, Object dest, int destPos,int length)  public static void exit(int status)  public static void gc()  public static long currentTimeMillis()  … … … … 21  获取当前时间  public static long currentTimeMillis()  Returns: the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC (Universal time coordinated). public static void main(String args[]) { long start = ()。 … … … … long end = ()。 (end start)。 } 22  静态变量  public static final double E  public static final double PI  静态方法  public static double abs(double a)  public static double ceil(double a)  public static double floor(double a)  public static double max(double a, double b)  … … … … 23 基本数据类型的包装类  基本数据类型 : byte, short, int, long, float, double, boolean, char  对应的包装类 : Byte, Short, Integer, Long, Float, Double, Boolean, Character  作用  包装类对象中包含有一个对应基本类型的值  提供有基本类型和字符串 (String)之间的转换函数  定义有一些常数和方法 24  常数定义 byte largestByte =。 //127 short largestShort =。 //32767 int largestInteger =。 //2147483647 long largestLong =。 //9223372036854775807 float largestFloat =。 //+38 double largestDouble =。 //+308 25  基本类型和字符串 (String)之间的转换  Integer类举例  字符串转换为整数  public static int parseInt(String s) throws NumberFormatException  public static int parseInt(String s, int radix) throws NumberFormatException String s = “123”。 int i = (s)。 parseInt(0, 10) parseInt(473, 10) parseInt(0, 10) parseInt(FF, 16) parseInt(1100110, 2) parseInt(2147483647, 10) parseInt(2147483648, 10) parseInt(2147483648, 10) parseInt(99, 8) parseInt(Kona, 10) parseInt(Kona, 27) returns 0 returns 473 returns 0 retur s 255 returns 102 returns 2147483647 returns 2147483648 throws a NumberFormatException throws a NumberFormatException throws a NumberFormatException returns 411787 26  基本类型和字符串 (String)之间的转换  Integer类举例  整数转换为字符串  public static String toString(int i)  public static String toString(int i, int radix)  public static String toBinaryString(int i)  public static String toHexString(int i)  public static String toOctalString(int i) int i = 123。 String s1 = (i)。 String s2 = (i, 10)。 String s3 = (i, 2)。 String s4 = (i, 8)。 String s5 = (i, 16)。 String s6 = (i)。 String s7 = (i)。 String s8 = (i)。 123 123 1111011 173 7b 1111011 7b 173 27 字符串操作类  三个类     不同的应用场合 28  —字符串 /字符序列  构造方法  public String()  public String(byte[] bytes)  public String(byte[] bytes, int offset, int length)  public String(byte[] bytes, String charsetName)  public String(char[] value)  public String(char[] value, int offset, int count)  public String(String original) 29  —字符串 /字符序列  构造方法的使用 String s = new String()。 char c[] = {„a‟, „b‟, „c‟}。 String s = new String(c)。 char c[] = {„语’ , „言’ }。 String s = new String(c)。 byte b[] = {97, 98, 99}。 String s = new String(b)。 String s = “abc”。 String s = “语言”。 30  —字符串 /字符序列  判断字符串相等的方法  public boolean equals(Object anObject)。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。