易截截图软件、单文件、免安装、纯绿色、仅160KB

九 java面向对象程序设计(this关键字)

九 java面向对象程序设计(this关键字)
/**
 * 面向对象之四
 * this关键字总结
 */
/*this关键字的第一种用法*/
//在方法中调用同类中的方法,这时的this可以省略.
class ThisPointer
{
 public void function1()
 {
  System.out.println("function1 is calling...");
 }
 public void function2()
 {
  System.out.println("function2 is calling...");
  this.function1();//调用同类中的function1;
  //this是指,这个对象的function方法.
 }
 public void function3()
 {
  System.out.println("function3 is calling...");
  function2();//相当于this.function2().传入的是同一个对象,所以this可以省略.
 }
}
/*this关键字的第二种用法*/
//指明类中与方法参数同名的成员变量.
class Pointer
{
 private int i;
 private String str;
 public void function(int i,String str)
 {
  this.i = i;
  this.str = str;
  //通过this,将function方法中同名的i,str和成员变量予以区分.
  System.out.println("i = " + i + " , " + "str = " + str);
 }
}
/*this关键字的第三种用法*/
//作为一个对象,参与到类的方法中
class Container
{
 private String name;
 public void setName(String name)
 {
  this.name = name;
 } 
 public String getName()
 {
  return name;
 }
 private Components com;
 public void addComponents()//在容器中添加部件,
 {
  //com = new Components(new Container());
  //虽然这样写没问题.但表示,在新创建一个部件的同时,又创建一个容器,然后将新部件加到新容器上.
  
  com = new Components(this);
  //用this表示这个容器类的对象,所以我们每次产生新部件是,都是加入到这个容器对象上的.
  System.out.println(" is loading...");
 }
}
class Components
{
 private Container c;
 public Components(Container c)
 {
  this.c = c;//部件类的构造方法指明


相关文档:

JAVA反射小结

1  JAVA的反射,其实就是通过一个实例化的对象反过来去找到一个类的完整信息,比如对于如下的形式:
X x=new X();
   x.getClass().getName();
这里就会输出这个类所在的完整信息,即"包名.类名";
  最常用的三种实例化CLASS类对象
Class<?> c1 = null ;  // 指定泛型
  C ......

java 乱码

1。数据库 
在创建的时候,指定其编码为UTF-8. 
  (1)oracle: 
SQL> select userenv('language') from dual; 
USERENV('LANGUAGE') 
--------------------------------------------- 
SIMPLIFIED CHINESE_CHINA.UTF8 
SQL> 
jdbc url无须指定编码。 
& ......

java 操作XML文件(片段)

//create a new Document
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document d = db.newDocument();

//add root Node
Element noteuser = d.createElement("note-users");
d.appendChil ......

java动态创建数组

  有JAVA中,有时候需要根据条件来生成批处理sqls语句等,需要动态生成数组。方法:
List<String> list=new ArrayList<String>();
if(true){
    list.add("insert.....");
    list.add("update....");
}else{
   list.add("insert....");
}
//这句是关 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号