随笔分类 -  Java

摘要:不允许扩展的类被称为final类。如果在定义类的时候使用了final修饰符就表明这个类是final类。类中的方法也可以被声明为final,这样子类就不能覆盖这个方法(final类中的所有方法自动地成为final方法)。对于final域来说,构造对象之后就不允许改变它们的值。如果将一个类声明为final,只有其中的方法自动地成为final,而不包括域。将方法或类声明为final主要鉴于以下原因:确保它们不会在子类中改变语义。 阅读全文
posted @ 2011-07-11 10:51 露初晞 阅读(330) 评论(0) 推荐(0)
摘要:所有数据域被初始化为默认值(0、false或null)。按照在类声明中出现的次序,依次执行所有域初始化语句(如:private String name = "";)和初始化块(如:{ id = 1; name = "guest";})。如果构造器第一行调用了第二个构造器,则执行第二个构造器主体。执行这个构造器的主体。 阅读全文
posted @ 2011-07-10 20:26 露初晞 阅读(176) 评论(0) 推荐(1)
摘要:访问控制修饰符:public,private和protected。如果不指定访问控制符,就假设可访问性是包级别。protected域或方法(或类)对子类是可继承的,而且对同一包中的类是可访问的。相当于:protected = package classes + nonpachage subclasses 阅读全文
posted @ 2011-07-06 21:20 露初晞 阅读(136) 评论(0) 推荐(0)
摘要:class ManagerextendsEmployee{addedmethodsandfields}The keyword extends indicates that you are making a new class that derives from an existing class. The existing class is called the superclass, base ... 阅读全文
posted @ 2010-09-16 22:55 露初晞 阅读(232) 评论(0) 推荐(0)
摘要:Always keep data private.This is first and foremost: doing anything else violates encapsulation. You may need to write an accessor or mutator method occasionally, but you are still better off keeping ... 阅读全文
posted @ 2010-09-13 13:41 露初晞 阅读(173) 评论(0) 推荐(0)
摘要:The main reason for using packages is to guarantee the uniqueness of class names.Static ImportsFor example, if you add the directiveto the top of your source file, then you can use static methods and ... 阅读全文
posted @ 2010-09-13 13:31 露初晞 阅读(198) 评论(0) 推荐(0)
摘要:Calling Another ConstructorIf the first statement of a constructor has the form this(. . .), then the constructor calls another constructor of the same class. Here is a typical example:When you call n... 阅读全文
posted @ 2010-09-13 13:11 露初晞 阅读(169) 评论(0) 推荐(0)
摘要:Static FieldsIf you define a field as static, then there is only one such field per class. In contrast, each object has its own copy of all instance fields.class Employee{ . . . private int id; privat... 阅读全文
posted @ 2010-09-13 12:36 露初晞 阅读(275) 评论(0) 推荐(0)
摘要:Employee类The simplest form for a class definition in Java is:classClassName{constructor1constructor2. . .method1method2. . .field1field2. . .}We adopt the style that the methods for the class come fir... 阅读全文
posted @ 2010-09-12 20:25 露初晞 阅读(209) 评论(1) 推荐(0)
摘要:Date类Constructors always have the same name as the class name. Thus, the constructor for the Date class is called Date. To construct a Date object, you combine the constructor with the new operator, a... 阅读全文
posted @ 2010-09-12 18:52 露初晞 阅读(2348) 评论(0) 推荐(0)
摘要:EPIsqrt()abs()sin()cos()tan()toRadians(x)  把x由角度值转化为弧度值toDegree(x)   把x由弧度值转化为角度值log()log10()exp()pow()cbrt()      立方根asin()acos()atan()random()     在区间[0,1)上随机提取一个实数sinh()cosh()tanh() 阅读全文
posted @ 2010-09-11 19:46 露初晞 阅读(122) 评论(0) 推荐(0)
摘要:int length(); 返回字符串的长度(包括字符的数量),该函数不需要参数。char charAt(int index); 返回字符串中第index个编号对应的字符(编号从0开始)。int compareTo(String another); 判断两个字符串是否相同,相同则返回0.int compareToIgnoreCase(String str); 判断两个字符串在忽略字母大小写时是否相... 阅读全文
posted @ 2010-09-11 15:06 露初晞 阅读(166) 评论(0) 推荐(0)
摘要:Integer类:基本成员函数:int parseInt (String s); 该函数的功能是把一个字符串s转化为一个整数。String toString (int i);该函数的功能是把一个整数i转化为一个字符串。int parseInt (String s, int radix); 把字符串s转化为一个radix进制的整数。String toString (int i, int radix)... 阅读全文
posted @ 2010-09-11 14:47 露初晞 阅读(409) 评论(0) 推荐(0)
摘要:无 阅读全文
posted @ 2010-09-05 13:56 露初晞 阅读(144) 评论(6) 推荐(0)