java技术博客

jsp博客
数据加载中……

java中的vector

     摘要: /** *//** *//** *//**  * 我们设计的学生基本类  */ class Student {     private String strName = "";//学生姓名     ...  阅读全文

posted @ 2008-11-07 16:02 郭兴华 阅读(342) | 评论 (0)编辑 收藏
记录类被实例化的次数

/*01*/public class classNumberDemo 
/*02*/{
/*03*/      public static int objNum=0;
/*04*/      public classNumberDemo()
/*05*/      {
/*06*/          classNumberDemo.objNum++;
/*07*/      }

/*08*/      public void show()
/*09*/      {
/*10*/          System.out.println("the No."+classNumberDemo.objNum);
/*11*/      }

/*12*/      
/*13*/        public static void main(String args[])
/*14*/        {
/*15*/             classNumberDemo p=null;
/*16*/             p=new classNumberDemo();
/*17*/             p.show();
/*18*/             p=new classNumberDemo();
/*19*/             p.show();
/*20*/             p=new classNumberDemo();
/*21*/             p.show();             
/*22*/      }

/*23*/}

posted @ 2008-11-05 22:16 郭兴华 阅读(352) | 评论 (0)编辑 收藏
java编程小实例

/**   2005 Aptech Limited
 *     版权所有
 
*/


/**
 * 该程序测试使用 break 关键字来检测的质数
 * 
@version 1.0, 2005 年 5 月 22 日
 * 
@author Michael
 
*/


public class PrimeNumber {

    
/** 构造方法*/
    PrimeNumber() 
{
    }


     
/**
      * 这是一个 main 方法
      * 
@param args 传递至 main 方法的参数
      
*/


    
public static void main(String[] args) {

    
int number = 29;

    
for (int i = 2; i < number; i++{

        
if (number % i == 0{
        System.out.println(
"不是质数");
        
break;
        }
 else {
            System.out.println(
"它是一个质数");
            
break;
           }

       }

    }

}





/*
 * 2005 Aptech Limited
 * 版权所有
 
*/


/**
 * 此类将输出数组中第二个最大的数字
 * 
@version 1.0, 2005 年 5 月 22 日
 * 
@author Michael
 
*/


public class HighestNumber {

    
/** 构造函数. */
    HighestNumber() 
{
    }


     
/**
      * 这是一个 main 方法
      * 
@param args 传递至 main 方法
      
*/


     
public static void main(String[] args) {


     
int[] array = {43798};
     
int greatest = 0;
     
int secondhighest = 0;

     
for (int i = 1; i < 5; i++{

         
if (greatest < array [i]) {

         secondhighest 
= greatest;
         greatest 
= array[i];

         }
 else {

             
if (secondhighest < array[i]) {

                 secondhighest 
= array[i];
                 }

             }

         }

         System.out.println(
"第二大的数字是: " + secondhighest);

     }

}

posted @ 2008-11-04 07:56 郭兴华 阅读(149) | 评论 (0)编辑 收藏
i++与++i的区别

public class ppDemo
{
    
public static void main(String[] args)
    
{
    
int result=0;
    
int p=2*result++;
    System.out.println(p);
    System.out.println(result);
    result
=0;
    
int y=2*++result;
    System.out.println(result);
    System.out.println(y);
    }

}

posted @ 2008-11-03 14:37 郭兴华 阅读(119) | 评论 (0)编辑 收藏
java静态成员

/*01*/public class static_demo
/*02*/{
/*03*/    public static int i=0;
/*04*/    public int j=0;
/*05*/    public void show()
/*06*/    {
/*07*/    System.out.println(i);
/*08*/    System.out.println(j);
/*09*/    }

/*10*/}

/*11*/
/*12*/class test
/*13*/{
/*14*/    public static void main(String args[])
/*15*/    {
/*16*/    static_demo obj1=new static_demo();
/*17*/    obj1.i=100;
/*18*/        obj1.j=200;
/*19*/        obj1.show();
/*20*/        static_demo obj2=new static_demo();
/*21*/    obj2.show();
/*22*/    }

/*23*/}

posted @ 2008-11-03 14:14 郭兴华 阅读(91) | 评论 (0)编辑 收藏
java中的静态代码段

/*01*/public class static_block
/*02*/{
/*03*/    public String name;
/*04*/    public String sex;
/*05*/    public int    age;
/*06*/  public static_block(String na,String se,int ag)
/*07*/  {
/*08*/      name=na;
/*09*/      sex=se;
/*10*/      age=ag;
/*11*/  }

/*12*/    public void show()
/*13*/    {
/*14*/        System.out.println("Name:"+name);
/*15*/        System.out.println("Sex:"+sex);
/*16*/        System.out.println("Age:"+age);
/*17*/    }

/*18*/    static{
/*19*/          System.out.println("hello block");
/*20*/    }

/*21*/    public static void main(String args[])
/*22*/    { System.out.println("hello main");
/*23*/        static_block pObj=new static_block("zhangsan","male",30);
/*24*/        pObj.show();
/*25*/    }

/*26*/}

posted @ 2008-11-03 08:47 郭兴华 阅读(310) | 评论 (0)编辑 收藏
++i与i++

public class ppDemo{
public static void main(String[] args)
{
int i=0;
result
=1+i++;
System.out.println(i);
System.out.println(result);
i
=0;
result
=1+++i;
System.out.println(i);
System.out.println(result);
}

}

posted @ 2008-10-31 11:57 郭兴华 阅读(100) | 评论 (0)编辑 收藏
java代理模式

package orj.jzkangta.proxydemo02;

public class ComputerMaker implements SaleComputer {

    
public void sale(String type) {
        System.out.println(
"卖出了一台"+type+"电脑");

    }


}



package orj.jzkangta.proxydemo02;

import java.lang.reflect.Proxy;

public class ComputerProxy {
    
public static SaleComputer getComputerMaker(){
        ProxyFunction pf
=new ProxyFunction();
        
return (SaleComputer)Proxy.newProxyInstance(ComputerMaker.class.getClassLoader(), ComputerMaker.class.getInterfaces(), pf);
    }

}





package orj.jzkangta.proxydemo02;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class ProxyFunction implements InvocationHandler {
    
private ComputerMaker cm;
    
    
public void youHui(){
        System.out.println(
"我给你一些优惠。。。");
    }

    
    
public void giveMouse(){
        System.out.println(
"我还要送你一个鼠标。。。 ");
    }

    
public Object invoke(Object arg0, Method arg1, Object[] arg2)
            
throws Throwable {
        String type
=(String)arg2[0];
        
if(type.equals("联想")||type.equals("三星")){
            
if(cm==null){
                cm
=new ComputerMaker();
                youHui();
                giveMouse();
                arg1.invoke(cm, type);
            }

        }
else{
            System.out.println(
"我没有你要的这个牌子的电脑。。。。");
        }

        
return null;
    }


}

package orj.jzkangta.proxydemo02;

public interface SaleComputer {
    
public void sale(String type);
}


package orj.jzkangta.proxydemo02;

public class Test {

    
    
public static void main(String[] args) {
        SaleComputer sc
=ComputerProxy.getComputerMaker();
        
//sc.sale("联想");
        
//sc.sale("三星");
        sc.sale("Dell");

    }


}

posted @ 2008-10-31 07:49 郭兴华 阅读(720) | 评论 (0)编辑 收藏
java中的多态

/*01*/public class overdemo1
/*02*/{
/*03*/    public static void main(String args[])
/*04*/    {
/*05*/    Child c=new Child();
/*06*/        int iResult=c.add(1,2);
/*07*/    double dResult=c.add(1.0,2.0);
/*08*/    System.out.println(iResult);
/*09*/    System.out.println(dResult);
/*10*/    }

/*11*/}

/*12*/
/*13*/class Parent
/*14*/{
/*15*/   public int add(int a, int b)
/*16*/   {
/*17*/       return  a+b;
/*18*/   }

/*19*/}

/*20*/
/*21*/class Child extends Parent
/*22*/{
/*23*/   public double add(double a, double b)
/*24*/   {
/*25*/        return a+b;
/*26*/   }

/*27*/}

posted @ 2008-10-30 14:31 郭兴华 阅读(119) | 评论 (0)编辑 收藏
java方法的重载

/*01*/public class calculator
/*02*/{
/*03*/   public int add(int a, int b)   
/*04*/   {
/*05*/        return a+b;
/*06*/   }

/*07*/   public double add(double a, double b)
/*08*/   {
/*09*/         return a+b;
/*10*/   }

/*11*/   public float add(float a, float b)
/*12*/   {
/*13*/         return a+b;
/*14*/   }

/*15*/   public static void main(String args[])
/*16*/   {
/*17*/          calculator cal=new calculator();
/*18*/          int iResult=cal.add(12,13);
/*19*/          double dResult=cal.add(12.0,13.0);
/*20*/          float  fResult=cal.add(12.0f13.0f);
/*21*/          System.out.println(iResult);
/*22*/          System.out.println(dResult);
/*23*/          System.out.println(fResult);
/*24*/   }

/*25*/}

posted @ 2008-10-30 14:23 郭兴华 阅读(71) | 评论 (0)编辑 收藏
仅列出标题
共9页: 上一页 1 2 3 4 5 6 7 8 9 下一页