- 博客(30)
- 资源 (1)
- 收藏
- 关注
原创 《JAVA编程思想》学习备忘:Holding Your Objects-1
Its a farily simple program that only has a fixed quantity of objects with known lifetimes.Generics and type-safe containers泛型与类型安全容器One of the problems of using pre-Java SE5 containers was tha
2008-11-11 22:17:00
685
原创 《JAVA编程思想》学习备忘(p345 Inner Classes-3)
续《JAVA编程思想》学习备忘(p345 Inner Classes-2)Closures & callbacksA closure is a callable oject that retains information from the scope in which it was created.The closure provided by the inner class is
2008-08-27 17:19:00
732
原创 《JAVA编程思想》学习备忘(p345 Inner Classes-2)
续《JAVA编程思想》学习备忘(p345 Inner Classes-1)Factory Method revisitedLook at how much nicer the interfaces/Factories.java example comes out when you use anonymous inner classes:interface Service { void
2008-08-27 11:13:00
693
原创 《JAVA编程思想》学习备忘(p345 Inner Classes-1)
Its possible to place a class definition within another class definition.This is called an inner class.The inner class is a valuable feature because it allows you to group classes that logically
2008-08-25 22:55:00
770
原创 《JAVA编程思想》学习备忘(第311页Interfaces-1)
Interfaces and abstract classes provide a more structured way to separate interface from implementation.抽象类是普通类和接口的中继,它是构建一个含有些许未实现方法的类的重要和必须的工具。你不能总是使用一个纯粹的接口。Abstract classes and methods当你需要通过
2008-08-03 18:03:00
496
原创 《JAVA编程思想》学习备忘(第277页Polymorphism-3)
续《JAVA编程思想》学习备忘(第277页Polymorphism-2)Behavior of polymorphic methods inside constructors示例:class Glyph { void draw(){ System.out.println("Glyph.draw()"); } Glyph(){ System.out.println("Glyph(
2008-07-26 23:51:00
482
原创 《JAVA编程思想》学习备忘(第277页Polymorphism-2)
续《JAVA编程思想》学习备忘(第277页Polymorphism-1)Pitfall:"overriding" private methods以下这个例子是重写了私有的方法吗?public class PrivateOverride { private void f(){ System.out.println("private f()"); } public static vo
2008-07-23 20:15:00
573
原创 《JAVA编程思想》学习备忘(第277页Polymorphism-1)
Polymorphism多态Upcasting revisited 示例:public enum Note { MIDDLE_C, C_SHARP, B_FLAT;}class Instrument { public void play(Note n){ System.out.println("Instrument.play()"); }}public class
2008-07-23 00:12:00
697
原创 续《JAVA编程思想》学习备忘(第237页:Reusing Classes)-5
The final keywordJava 中 final 关键字表示不可被改变,无外乎两个理由:定制或者效率。但这两个理由很不同,它很可能造成不当使用final关键字。以下分别讨论三个final关键字可被使用的地方:data,methods 和 classes.final data许多编程语言都有一个方法来告诉编译器某块数据是“常量”。有两个理由说明一个常量非常有用:1、它可做为一个编译时从不改
2008-07-21 23:17:00
625
原创 《JAVA编程思想》学习备忘(第237页:Reusing Classes)-5
续《JAVA编程思想》学习备忘(第237页:Reusing Classes)-4protectedNow that youve been introduced to inheritance,the keyword protected finally has meaning,In an ideal world,the private keyword would be enough.In r
2008-02-21 22:41:00
560
原创 《JAVA编程思想》学习备忘(第237页:Reusing Classes)-4
续《JAVA编程思想》学习备忘(第237页:Reusing Classes)-3Name hidingIf a Java base class has a method name thats overloaded several times,redefining that method name in the derived class will not hide any of the
2008-02-19 00:28:00
683
原创 《JAVA编程思想》学习备忘(第237页:Reusing Classes)-3
续《JAVA编程思想》学习备忘(第237页:Reusing Classes)-2Combining composition and inheritanceIt is very common to use composition and inheritance together.The following example shows the creation of a more comple
2008-02-16 10:16:00
689
原创 《JAVA编程思想》学习备忘(第237页:Reusing Classes)-2
续《JAVA编程思想》学习备忘(第237页:Reusing Classes)-1 Initializing the base class...its essential that the base-class subobject be initialized correctly,and theres only one way to guarantee this:Perform the
2008-02-13 19:03:00
659
原创 《JAVA编程思想》学习备忘(第237页:Reusing Classes)-1
One of the most compelling features about Java is code reuse.But to be revolutionary,youve got to be able to do a lot more than copy code and change it. Composition syntax重写toString()方法的例子://
2008-02-12 22:58:00
615
原创 《JAVA编程思想》学习备忘(第209页:Access Control)-3
续《JAVA编程思想》学习备忘(第209页:Access Control)-2Interface and implementationAccess control is often referred to as implementation hiding.Wrapping data and methods within classes in combination with implem
2008-02-12 14:56:00
748
原创 《JAVA编程思想》学习备忘(第209页:Access Control)-2
续《JAVA编程思想》学习备忘(第209页:Access Control)-1Using imports to change behaviorA feature that is missing from Java is Cs conditional compilation,which allows you to change a switch and get different beha
2008-02-11 21:59:00
823
原创 《JAVA编程思想》学习备忘(第209页:Access Control)-1
Access control(or implementation hiding) is about"not getting it right the first time."存取控制: All good writers-including those who write software-know that a piece of work isnt good until its bee
2008-02-10 10:13:00
797
原创 《JAVA编程思想》学习备忘(第155页:Initialization & Cleanup)-7
续《JAVA编程思想》学习备忘(第155页:Initialization & Cleanup)-6Variable argument lists自从所有的类最终继承于根类Object,你可以创建一个带有Object数组的方法,并且这样调用:例1://:initialization/VarArgs.java//Using array syntax to create variable ar
2008-02-01 22:02:00
725
原创 《JAVA编程思想》学习备忘(第155页:Initialization & Cleanup)-6
续《JAVA编程思想》学习备忘(第155页:Initialization & Cleanup)-5Non-static instance initializationJava 提供一种相似的语法,叫做实例初始化,用来为每个对象初始化非静态变量。举例://:initialization/Mugs.java// Java "Instance Initialization."i
2008-02-01 19:08:00
687
原创 《JAVA编程思想》学习备忘(第155页:Initialization & Cleanup)-5
续《JAVA编程思想》学习备忘(第155页:Initialization & Cleanup)-4Member initialization如果一个类中的属性为原始数据类型,它将会确保有一个初始值。以下程序为一例证:import static staticPrint.Print.print;public class InitialValues{ boolean t;
2008-01-28 18:01:00
649
原创 《JAVA编程思想》学习备忘(第155页:Initialization & Cleanup)-4
续《JAVA编程思想》学习备忘(第155页:Initialization & Cleanup)-3The meaning of static静态的含义With the this keyword in mind,you can more fully understand what it means to make a method static.It means that there
2008-01-08 22:15:00
637
原创 《JAVA编程思想》学习备忘(第155页:Initialization & Cleanup)-3
续《JAVA编程思想》学习备忘(第155页:Initialization & Cleanup)-2Calling constructors from constructorsWhen you write several constuctors for a class,there are times when youd like to call one constructor from
2008-01-01 22:06:00
570
原创 《JAVA编程思想》学习备忘(第155页:Initialization & Cleanup)--2
The this keywordThe this keyword-which can be used only inside a non-static method-produces the reference to the object that the method has been called for.但调用同处一类中的方法时不需要this 。The this keywo
2007-12-21 00:11:00
631
原创 《JAVA编程思想》学习备忘(第135页:Controlling Execution)
Controlling Execution Like a sentient creature,a program must manipulate its world and make choices during execution.In Java you make choices with execution control statements. 像一个有感知的生物体,一个程序在其
2007-12-16 13:06:00
709
原创 《JAVA编程思想》学习备忘(第93页:Operators--3)
续《JAVA编程思想》学习备忘(第93页:Operators--2)Common pitfalls when using operators运算符使用中的“陷井”一个Java中的错误例子:while(x=y){ //...}当x和y是boolean类型是,x=y是一个合法的表达式,能通过编译,如果y的值为true,则此例会产生一个死循环。 Casting
2007-12-14 20:30:00
585
原创 《JAVA编程思想》学习备忘(第93页:Operators--2)
续《JAVA编程思想》学习备忘(第93页:Operators--1)Short-circuiting 使用逻辑运算符时的“短路”现象:在并列逻辑判断项运算过程中得到的值如可明确为最终结果,其后的逻辑运算将不执行。举个例子:import static staticPrint.Print.print;public class ShortCircuit{ stati
2007-12-13 23:55:00
818
原创 《JAVA编程思想》学习备忘(第93页:Operators--1)
在最底层,数据在Java中靠运算符来控制。Simpler print statements 以下为简化了的打印语句包及方法,使用时可导入包:| package staticPrint;| public class Print { | public static void print(Object obj){| System.out.pr
2007-12-12 22:19:00
581
原创 《JAVA编程思想》学习备忘(p61:Everything Is an Object--3)
(接Everything Is an Object--2)Methods,arguments,and return valuesMethods in Java determine the message an object can receive.The fundamental parts of a method are the name,the arguments,the return
2007-12-11 23:01:00
673
原创 《JAVA编程思想》学习备忘(第61页:Everything Is an Object--2)
(接Everything Is an Object--1)You never need to destroy an object 本小节介绍Java中的垃圾清理工作。Scoping 范围(作用域),在Java中用一对花括号来表示:{}举例:| { int x = 12; //x 的作用范围 { int q
2007-12-10 20:22:00
640
原创 《JAVA编程思想》学习备忘(第61页:Everything Is an Object--1)
“If we spoke a different language,we would perceive a somewhat different world” 此为本章开篇引言,大意:如果我们使用另类的语言,我们将追寻一个些许不同的世界。 很多人认为编程语言对于初学者来说大都晦涩难懂,但不要忘掉的是,它仅仅是一门语言,既然是语言,就如同我们日常所说所讲的语言一样
2007-12-09 23:33:00
1084
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人