JSPCN主页 | JSP空间 | 网站制作 | JSP下载 | JSP论坛 | JSP教程 | 关于JSPCN | 联系我们
JSP虚拟主机,jsp空间,java空间,java虚拟空间,详细请点击进入
做最专业的JSP中文网站 当前位置首页--JSP技术--教程系列  
文章搜索:
关键字 标题
  
JSP中文网内容管理系统(JCMS)
JSP虚拟主机
网络笔记本
网摘,图片,笔记收藏
虚拟服务器

JSPCN文章目录分类
JSP配置[219]JSP基础[136]
中文问题[69]上传问题[27]
JAVABEAN[46]数据库[212]
文件操作[126]图片声音[17]
JSP其他[57]时间相关[16]
JAVAMAIL[72]STRUTS[144]
开发工具[28]教程系列[157]
JSP实例[89]
JAVA基础[421]APPLET[78]
JAVA网络[179]Applica[115]
Servlet[98]XML[163]
J2ME[257]J2EE[374]
考试相关[63]JAVA线程[90]
EJB[261]Swing[26]
Java API[141]声音图片[28]
异常处理[33]JAVA实例[290]
JAVA类[139]SUN[89]
Hibernate[6]JMX[8]
Spring[34]
本版推荐文章 
本版热点文章 
相关文章链接 
 
《Java就业培训教程》[张孝祥]书内源码(2)
作者:     文章来源:
访问次数:449次     加入时间:2007年02月25日

《Java就业培训教程》P81源码
class Compare
{
  public static void main(String[] args)
   {
   String str1 = new String("abc");
   String str2 = new String("abc");
   String str3 = str1;
   if(str1==str2)
    System.out.println("str1==str2");
   else
    System.out.println("str1!=str2"); 
   if(str1==str3)
    System.out.println("str1==str3");
   else
    System.out.println("str1!=str3"); 
 }
}


《Java就业培训教程》P82源码
class Compare
{
  public static void main(String[] args)
   {
   String str1 = new String("abc");
   String str2 = new String("abc");
   String str3 = str1;
   if(str1.equals(str2))
    System.out.println("str1 equal str2");
   else
    System.out.println("str1 not equal str2"); 
   if(str1.equals(str3))
    System.out.println("str1 equal str3");
   else
    System.out.println("str1 not equal str3"); 
 }
}


《Java就业培训教程》P86源码
class Person
{
 private int age;
 public void setAge(int i)
 {
  if(i<0 || i>130)
   return;
  age = i;
 }
 public int getAge()
 {
  return age;
 }
}
public class TestPerson
{
 public static void main(String args[])
 {
  Person p1 = new Person();
  p1.setAge(3);
  p1.setAge(-6);
  System.out.println(p1.getAge());
 }
}


《Java就业培训教程》P88源码
class Person
{
    public Person()
    {
  System.out.println("the constructor 1 is calling!");
 }
 private int age = 10;
 public void shout()
 {
  System.out.println("age is "+age);
 }
}
class TestPerson
{
 public static void main(String[] args)
 {
  Person p1=new Person();
  p1.shout();
  Person p2=new Person();
  p2.shout();
  Person p3=new Person();
  p3.shout();
 }
}


《Java就业培训教程》P90源码
class Person
{
 private String name="unknown";
 private int age = -1;
 public Person()
 {
  System.out.println("constructor1 is calling");
 }
    public Person(String n)
 {
        name = n;
        System.out.println("constructor2 is calling");
  System.out.println("name is "+name);
    }
 public Person(String n,int a)
 {
        name = n;
        age = a;
        System.out.println("constructor3 is calling");
  System.out.println("name and age is "+name+";"+age);
    }
        public void shout()
     {
      System.out.println("listen to me!!");
  }
}
class TestPerson
{
 public static void main(String[] args)
 {
  Person p1=new Person();
  P1.shout();
  Person p2=new Person("Jack");
  P2.shout();
  Person p3=new Person("Tom",18);
  P3.shout();
 }
}
《Java就业培训教程》P94源码
class Person
{
    private Person()
    {
  System.out.println("the constructor 1 is calling!");
 }
}
class TestPerson
{
 public static void main(String[] args)
 {
  Person p1=new Person();
 }
}
《Java就业培训教程》P95源码
class A
{
 String name;
 public A(String x)
 { 
  name = x; 
 }
 public void func1()
 {
  System.out.println("func1 of " + name +" is calling");
 }
 public void func2()
 {
  A a2 = new A("a2");
  a2.func1();
 }
}
class TestA
{
 public static void main(String [] args)
 {
  A a1 = new A("a1");
  a1.func2();
 }
}
《Java就业培训教程》P96源码
class A
{
 String name;
 public A(String x)
 {
  name = x;
 }
 public void func1()
 {
  System.out.println("func1 of " + name +" is calling");
 }
 public void func2()
 {
  A a2 = new A("a2");
  this.func1();//使用this关键字调用func1方法
  a2.func1();
 }
}
《Java就业培训教程》P99源码
class Container
{
 Component comp;
 public void addComponent()
 {
  comp = new Component(this);//将this作为对象引用传递
 }
}
class Component
{
 Container myContainer;
 public Component(Container c)
 {
  myContainer = c;
 }
}
《Java就业培训教程》P100源码
public class Person
{
 String name;
 int age;
 public Person(String name)
 {
   this.name = name;
 }
 public Person(String name,int age)
 {
  this(name);
  this.age = age;
 }
}
《Java就业培训教程》P101源码
class Person
{
 public void finalize()
 {
  System.out.println("the object is going!");
 }
 public static void main(String [] args)
 {
  new Person();
  new Person();
  new Person();
  System.out.println("the program is ending!");
 }
}
《Java就业培训教程》P103源码
class PassValue
{
 public static void main(String [] args)
 {
  int x = 5;
  change(x);
  System.out.println(x);
 }
 public static void change(int x)
 {
  x = 3;
 }
}
class  PassRef
{
 int x ;
 public static void main(String [] args)
 {
  PassRef obj = new PassRef();
  obj.x = 5;
  change(obj);
  System.out.println(obj.x);
 }
 public static void change(PassRef obj)
 {
  obj.x=3;
 }
}


《Java就业培训教程》P108源码
class Chinese
{
 static String country="中国";
 String name;
 int age;
 void singOurCountry()
 {
  System.out.println("啊!,亲爱的" + country);
  //类中的成员方法也可以直接访问静态成员变量
 }
}
class TestChinese
{
 public Static void main(String [] args)
 {
  System.out.println("Chinese  country is " + Chinese.country);
  //上面的程序代码直接使用了"类名.成员"的格式
  Chinese ch1 = new Chinese();
  System.out.println("Chines country is " + ch1.country);
  //上面的程序代码直接使用了"对象名.成员"的格式
  ch1.singOurCountry();
 }
}
《Java就业培训教程》P111源码
class StaticCode
{
 static String country;
 static
 {
  country = "china";
  System.out.println("StaticCode is loading");
 }
}
class TestStaticCode
{
 static
 {
  System.out.println("TestStaticCode is loading");
 }
 public static void main(String [] args)
 {
  System.out.println("begin executing main method");
  new StaticCode();
  new StaticCode();
 }
}
《Java就业培训教程》P115源码
class Outer
{
 int outer_i = 100;
 void test()
 {
  Inner in = new Inner();
  in.display();
 }
 class Inner
 {
  void display()
  {
  System.out.println("display: outer_i = " + outer_i);
  }
 }
}
class InnerClassDemo
{
 public static void main(String[] args)
 {
  Outer outer = new Outer();
  outer.test();
 }
}

 
Copyright © 2002-2005 JSPCN.net. All rights reserved.
JSP中文网    备案序号:蜀ICP备05001583号
成都恒海科技发展有限公司    成都市一环路南二段6号新瑞楼三楼8号