- 博客(21)
- 收藏
- 关注
原创 Programming Contest Problem Types (ZZ from usaco)
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and madean amazing discovery: there are only 16 types of programming contestproblems! Furthermore...
2008-12-25 12:24:44
133
POJ1001题解
在学习了BigDecimal之后,看见那一大串数字也不会太发愁了。反正出事有BigDecimal挡着。于是大胆写出程序主体,最先遇到 的问题是BigDecimal的存储问题(见程序注释),它并非对输入的double数精确存储,于是想到先将输入数据转入char[] 然后构造 BigDecimal,果然奏效。在输出 时也遇到 了点小麻烦,即BigDecimal的toString()方法是科学计数法输出...
2008-12-24 14:56:18
270
关于泛型的一些重要事实
不管实际的具体类型是什么样的,一个泛型类是由其所有实例共享的,假定stack1 和stack2按如下方式创建:Stack<String> stack1 = new Stack<String>();Stack<Integer> stack2 = new Stack<Integer>(); 尽管Stack<String>和Stack&...
2008-12-20 10:40:40
134
抽象类实现一个接口
有的时候需要将接口和抽象类配合起来使用,这样可以为用户提供相当的便利性,用户觉得哪个方便就选用哪个。这样的抽象类称为便利类。此时,便利类并不需要实现接口的所有方法,可以留给继承它的子类去实现它们。这么做并非是没有意义的,当你自己写的类想用接口中个别方法的时候(注意不是所有的方法),那么你就可以用一个抽象类先实现这个接口(方法体中为空),然后再用你的类继承这个抽象类,这样就可以达到你的目的了,如果你...
2008-12-17 11:44:54
608
内部类和匿名内部类的特征
内部类有如下特征:内部类被编译成名为OuterClassName$InnerClassName.class的类。内部类可以引用定义在它嵌套的外部类中的数据和方法,所以不需要将外部类对象的引用传递给内部类的构造方法,因此,内部类可以拿程序简单和简洁。声明用可见性修饰符声明内部类,遵从应用于一般类成员的可见性规则。可以将内部类声明为static。一个static内部类可以使用外部类的名字...
2008-12-08 16:31:06
304
原创 如果重写实现的两个接口中拥有相同名称的两个抽象方法?
public interface Valuable { public double getMoney();}interface Protectable { public void beProtected();}interface A extends Protectable { void m(); void getMoney();//A和Valuable拥有同样名称的抽象方法ge...
2008-12-01 16:55:43
444
大小写字母转换
小写字母的统一码从'a'开始,然后是'b' 'c'…'z'的连续整数,大写字母的情形也一样。因此,与小写字母ch对应的大写字母应该是(char)('A' + (ch - 'a' )
2008-11-29 13:40:18
165
Math.random()方法
Math.random()方法生成0.0至1.0(不包含1.0)的double型随机数,一般地, a + Math.random() * b可以返回a到a+b之间的随机数,不包括a+b.
2008-11-29 10:41:06
167
两句话让我明白了Path&CLASSPATH
path: 系统执行命令时要搜寻的路径CLASSPATH: JAVA在编译和运行时要找的class所在路径.马士兵老师的两句话总结恰到好处,胜于看Thinking in java相关章节半天还迷迷糊糊的....
2008-11-22 20:39:37
111
修改Linux的环境变量(CLASSPATH)
在看<Thinking in java>时,需要将其代码文件夹加入到环境变量中,以便import一些自带的方法。作者官方网站只给出了在Windows下的设置方法,却没有Linux的相关设置。难道用linux的朋友就不看这本书了?这点上来看,作者有点狭隘了。我研究了一下午,参照网上一大把设置jdk的环境变量的文章却未成功。最后终于研究出相关设置方法。特写此文,以作备份。先打开终端,输入命令(相关设...
2008-11-20 22:09:13
1952
原创 clone()方法描述
Object (Java 2 Platform SE 5.0)<script type="text/javascript">function windowTitle(){ parent.document.title="Object (Java 2 Platform SE 5.0)";}</script><noscript></noscr...
2008-11-11 12:40:11
115
原创 Random Integer Generation
http://www.devx.com/tips/Tip/25942Random Integer GenerationQuestion: How do I write a Java program that generates random numbers withinlimits, such as 1 to 100, or 1 to 1000?Answer: The ja...
2008-11-11 00:54:19
437
重写equals()方法为什么还要必须重写hashCode方法?
hashCode 的常规协定是: 在 Java 应用程序执行期间,在同一对象上多次调用 hashCode 方法时,必须一致地返回相同的整数,前提是对象上 equals 比较中所用的信息没有被修改。从某一应用程序的一次执行到同一应用程序的另一次执行,该整数无需保持一致。 如果根据 equals(Object) 方法,两个对象是相等的,那么在两个对象中的每个对象上调用 hashCode ...
2008-11-10 18:45:38
92
System.err与System.out的区别
System.out leads the output to the standard output stream (normallymapped to the console screen). System.err leads the output to thestandard error stream (and, by default to the console, as well). T...
2008-11-10 08:25:46
201
什么是fail-fast
if the list is structurally modified at any time after the iterator is created, in any way except through the Iterator's own remove or add methods, the iterator will throw a ConcurrentModificati...
2008-11-09 11:42:41
123
Iterator的remove()方法使用注意事项
void remove()从迭代器指向的集合中移除迭代器返回的最后一个元素(可选操作)。每次调用 next 只能调用一次此方法,也意味着在调用remove()之前必须先调用next()。如果进行迭代时用调用此方法之外的其他方式修改了该迭代器所指向的集合,则迭代器的行为是不明确的。抛出:UnsupportedOperationException - 如果迭代器不支持 r...
2008-11-09 09:22:21
538
equals()方法注意事项
Collection (Java 2 Platform SE 5.0)<script type="text/javascript">function windowTitle(){ parent.document.title="Collection (Java 2 Platform SE 5.0)";}</script><noscript>&l...
2008-11-07 11:09:20
291
List方法总结
indexOf(Objecto):Returns the index in this list of the firstoccurrence of the specified element, or -1 ifthis list does not contain this element. More formally, returns the lowest index i suc...
2008-11-07 10:00:01
166
为容器添加一组元素的方法
Array.asList()Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.) This method acts as bridge between array-based and collection-ba...
2008-11-06 20:37:26
210
内部类思考
一道TJ4的练习题: 创建一个至少一个方法的接口,在某个方法某作用域内定义一个内部类以实现此接口,这个方法返回对此接口的引用.interface Contents{ void value(int i );}public class Destination{ private int i = 0; Contents c(int i ) { if(i >...
2008-11-05 08:12:02
121
JAVA多重继承思考
先贴一段代码(<JAVA编程思想>(中文版)第179页):interface CanFight { void fight();}interface CanSwim { void swim();}interface CanFly { void fly();}interface CanClimb{ void climb();}class Action...
2008-11-02 21:59:29
97
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人