bulktree
欢迎走进有风的地方~
BlogJava
首页
新文章
新随笔
聚合
管理
posts - 38, comments - 103, trackbacks - 0
Thinking in Java notebook
import
java.util.
*
;
import
java.io.
*
;
/** */
/**
A class comment
*/
public
class
Test
{
/**/
/*
public static void main(String[] args)
{
double i = 0;
while(i<0.99d)
{
i = Math.random();
System.out.println(i);
}
}
*/
/**/
/*
public static void main(String[] args)
{
for(int i=0;i<128;i++)
if(Character.isLowerCase((char)i))
System.out.println("value:"+i+"char:"+(char)i);
}
*/
/**/
/*
public static void main(String[] args)
{
for(int i=1,j=i+10;i<5;i++,j=i*2)
{
System.out.println("i="+i+"j="+j);
}
}
*/
public
static
void
main(String[] args)
{
//
new BreakAndContinue();
//
new LableFor();
//
new SwitchTest();
/**/
/*
OverLoading ol = new OverLoading();
ol.testConstVal();
ol.testChar();
ol.testByte();
ol.testShort();
ol.testInt();
ol.testLong();
ol.testFloat();
ol.testDouble();
*/
/**/
/*
ThisTest1 tt = new ThisTest1();
tt.increment().increment().increment().increment().print();
*/
//
ThisTest2 tt = new ThisTest2();
/**/
/*
Bath b = new Bath();
System.out.println(b);
*/
/**/
/*
Detergent d = new Detergent();
d.dilute();d.apply();d.scrub();d.foam();
System.out.println(d);
System.out.println("Testing base class");
*/
//
Cartoon c = new Cartoon();
//
Chess c = new Chess();
//
PlaceSetting ps = new PlaceSetting(2);
//
CADSystem cs = new CADSystem(8);
/**/
/*
Bart b = new Bart();
b.doh(1);
b.doh('x');
b.doh(1.0f);
b.doh(new Milhouse());
*/
/**/
/*
Orc o = new Orc("bulktree",23);
System.out.println(o);
o.change("oakertree",22);
System.out.println(o);
*/
//
Beetle b = new Beetle();
/**/
/*
RandomShapeGenerator rsg = new RandomShapeGenerator();
Shape[] s = new Shape[9];
for(int i=0;i<s.length;i++)
s[i] = rsg.next();
for(int i=0;i<s.length;i++)
s[i].draw();
*/
/**/
/*
Instrument[] i = new Instrument{
new Wind(),
new Percussion(),
new Stringed(),
new Brass(),
new WoodWind()
};
*/
//
new Sandwich();
/**/
/*
System.out.println(RandVals.randomInt);
System.out.println(RandVals.randomLong);
System.out.println(RandVals.randomFloat);
System.out.println(RandVals.randomDouble);
*/
/**/
/*
A a = new A();
A a2 = new A();
a2.receiveD(a.getD());
*/
/**/
/*
Parcel1 p = new Parcel1();
p.ship("xiangtan");
p.ship("湘潭");
*/
/**/
/*
Parcel2 p = new Parcel2();
p.ship("湘潭");
Parcel2 q = new Parcel2();
Parcel2.Contents c = q.getContents();
Parcel2.Destination d = q.getDestination("南方");
d.readLabel();
*/
/**/
/*
MNA mna = new MNA();
mna.f();
MNA.A mnaa = mna.new A();
mnaa.g();
MNA.A.B mnaab = mnaa.new B();
mnaab.h();
*/
/**/
/*
WithInner wi = new WithInner();
InheritInner ii = new InheritInner(wi);
*/
/**/
/*
Callee1 c1 = new Callee1();
Callee2 c2 = new Callee2();
MyIncrement.f(c2);
Caller caller1 = new Caller(c1);
Caller caller2 = new Caller(c2.getCallbackReference());
caller1.go();
caller1.go();
caller2.go();
caller2.go();
*/
/**/
/*
try
{
ExtraFeatures.f();
}
catch(MyException e)
{
e.printStackTrace();
}
try
{
ExtraFeatures.g();
}
catch(MyException e)
{
e.printStackTrace();
}
try
{
ExtraFeatures.h();
}
catch(MyException e)
{
e.printStackTrace();
System.out.println("e.val()="+e.val());
}
*/
//
new ArraySize();
/**/
/*
new IceCream();
for(int i=0;i<20;i++)
System.out.println("flavorSet("+i+")=");
String[] f1 = flavorSet(flavors.length);
for(int j=0;j<fl.length;j++)
System.out.println("\t"+f1[j]);
*/
/**/
/*
System.out.println(PrintCollection.fill(new ArrayList()));
System.out.println(PrintCollection.fill(new HashSet()));
System.out.println(PrintCollection.fill(new HashMap()));
*/
//
new FillingLists();
/**/
/*
List list = new ArrayList();
for(int i=0;i<3;i++)
{
list.add(new Hamster(i));
System.out.println(list.iterator().next());
}
*/
//
new SimpleCollection();
/**/
/*
try
{
new IOStreamDemo();
}
catch(IOException e)
{
e.printStackTrace();
}
*/
try
{
new
StreamTest();
}
catch
(IOException e)
{
System.out.println(e);
}
}
}
/**/
/*
class BreakAndContinue
{
BreakAndContinue()
{
for(int i=0;i<100;i++)
{
if(i==74)
break;
if(i%9!=0)
continue;
System.out.println("i="+i);
}
int i = 0;
while(true)
{
i++;
int j = i*27;
if(j==1269)
break;
if(i%10!=0)
continue;
System.out.println("i="+i);
}
}
}
*/
/**/
/*
class LableFor
{
LableFor()
{
int i=0;
outer:
for(;true;)
{
inner:
for(;i<10;i++)
{
System.out.println("i="+i);
if(i==2)
{
System.out.println("continue");
continue;
}
if(i==3)
{
System.out.println("break");
i++;
break;
}
if(i==7)
{
System.out.println("continue outer");
i++;
continue outer;
}
if(i==8)
{
System.out.println("break outer");
break outer;
}
for(int k=0;k<5;k++)
{
if(k==3)
{
System.out.println("continue inner");
continue inner;
}
}
}
}
}
}
*/
/**/
/*
class SwitchTest
{
SwitchTest()
{
for(int i=0;i<100;i++)
{
char c = (char)(Math.random()*26+'a');
System.out.println(c+":");
switch(c)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println("vowel");
break;
case 'y':
case 'w':
System.out.println("sometime a vowel");
break;
default:
System.out.println("consonant");
}
}
}
}
*/
/**/
/*
class OverLoading
{
void f1(char x)
{
System.out.println("f1(char)");
}
void f1(byte x)
{
System.out.println("f1(byte)");
}
void f1(short x)
{
System.out.println("f1(short)");
}
void f1(int x)
{
System.out.println("f1(int)");
}
void f1(long x)
{
System.out.println("f1(long)");
}
void f1(float x)
{
System.out.println("f1(float)");
}
void f1(double x)
{
System.out.println("f1(double)");
}
void f2(byte x)
{
System.out.println("f1(byte)");
}
void f2(short x)
{
System.out.println("f1(short)");
}
void f2(int x)
{
System.out.println("f2(int)");
}
void f2(long x)
{
System.out.println("f2(long)");
}
void f2(float x)
{
System.out.println("f2(float)");
}
void f2(double x)
{
System.out.println("f2(double)");
}
void f3(short x)
{
System.out.println("f3(short)");
}
void f3(int x)
{
System.out.println("f3(int)");
}
void f3(long x)
{
System.out.println("f3(long)");
}
void f3(float x)
{
System.out.println("f3(float)");
}
void f3(double x)
{
System.out.println("f3(double)");
}
void f4(int x)
{
System.out.println("f4(int)");
}
void f4(long x)
{
System.out.println("f4(long)");
}
void f4(float x)
{
System.out.println("f4(float)");
}
void f4(double x)
{
System.out.println("f4(double)");
}
void f5(long x)
{
System.out.println("f5(long)");
}
void f5(float x)
{
System.out.println("f5(float)");
}
void f5(double x)
{
System.out.println("f5(double)");
}
void f6(float x)
{
System.out.println("f6(float)");
}
void f6(double x)
{
System.out.println("f6(double)");
}
void f7(double x)
{
System.out.println("f7(double)");
}
void testConstVal()
{
System.out.println("Test With 5");
f1(5);f2(5);f3(5);f4(5);f5(5);f6(5);f7(5);
}
void testChar()
{
char x='x';
System.out.println("char argument");
f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
}
void testByte()
{
byte x = 0;
System.out.println("byte argument");
f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
}
void testShort()
{
short x = 0;
System.out.println("short argument");
f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
}
void testInt()
{
int x = 0;
System.out.println("int argument");
f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
}
void testLong()
{
long x = 0;
System.out.println("long argument");
f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
}
void testFloat()
{
float x = 0;
System.out.println("float argument");
f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
}
void testDouble()
{
double x = 0;
System.out.println("double argument");
f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
}
}
*/
/**/
/*
class ThisTest1
{
int i = 0;
ThisTest1 increment()
{
i++;
return this;
}
void print()
{
System.out.println("i="+i);
}
}
*/
/**/
/*
class ThisTest2
{
int count = 0;
String s = new String("null");
ThisTest2(int number)
{
count = number;
System.out.println("Constructor int arg only,count="+count);
}
ThisTest2(String ss)
{
s = ss;
System.out.println("Constructor String arg only,s="+s);
}
ThisTest2(String s,int number)
{
this(number);
this.s = s;
System.out.println("String & int args");
}
ThisTest2()
{
this("hi",47);
System.out.println("default constructor(no args)");
System.out.println("count="+count+" "+"s="+s);
}
}
*/
/**/
/*
class Soap
{
private String s;
Soap()
{
System.out.println("Soap()");
s = new String("Constructed");
}
public String toString()
{
return s;
}
}
class Bath
{
private String s1 = new String("Happy"),
s2 = "Happy",s3,s4;
private Soap castille;
private int i;
private float toy;
public Bath()
{
System.out.println("Inside Bath()");
s3 = new String("Joy");
i = 47;
toy = 3.14f;
castille = new Soap();
}
public String toString()
{
if(s4==null)
s4 = new String("Joy");
return
"s1="+s1+"\n"+
"s2="+s2+"\n"+
"s3="+s3+"\n"+
"s4="+s4+"\n"+
"i="+i+"\n"+
"toy="+toy+"\n"+
"castille="+castille;
}
}
*/
/**/
/*
class Cleanser
{
private String s = new String("Cleanser");
public void append(String a)
{
s += a;
}
public void dilute()
{
append("dilute()");
}
public void apply()
{
append("apply()");
}
public void scrub()
{
append("scrub()");
}
public String toString()
{