??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美日本国产一区,日韩不卡一区二区三区,99国产精品视频免费观看一公开http://www.aygfsteel.com/feng0801/category/54459.html学习交流q_zh-cnTue, 29 Jul 2014 09:12:32 GMTTue, 29 Jul 2014 09:12:32 GMT60Java调用dll文ghttp://www.aygfsteel.com/feng0801/articles/400111.html冯威?/dc:creator>冯威?/author>Mon, 03 Jun 2013 08:15:00 GMThttp://www.aygfsteel.com/feng0801/articles/400111.htmlhttp://www.aygfsteel.com/feng0801/comments/400111.htmlhttp://www.aygfsteel.com/feng0801/articles/400111.html#Feedback0http://www.aygfsteel.com/feng0801/comments/commentRss/400111.htmlhttp://www.aygfsteel.com/feng0801/services/trackbacks/400111.html先说一下我的运行环境:JDK6.0  VC++6体中文版
我运行环境是q个Q对于其他环境我也不知道行不行,可以试一下!

1Q编写Java文gMyDll.java
 1 public class MyDll {
 2     static {
 3         System.loadLibrary("MyDll");
 4     }
 5     public native int sum(int i,int j); 
 6     public static void main(String args[]) {
 7         int i = 10;
 8         int j = 10;
 9         int temp = new MyDll().sum(i, j);
10         System.out.println("10+10的和为:"+temp);
11     }
12 }
13 
2Q编译Java文g 命oQjavac MyDll.java 如果没有报错 Q再q行命oQ?javah MyDll 。前面命令生成MyDll.class文gQ后面命令生成MyDll.h文g
 
3Q在VC++6建立目Q选择Win32 Dynamic-Link Library ,工程?MyDll。然后选择A simple DLL projectQ点?/span>Finish?/span>



4Q将MyDll.h文g复制C目里面Q就是项目名的文件夹里面?br />

在StdAfx文g里面#include <windows.h>后面d
#include <jni.h>
#include "MyDll.h"
配置环境Q选择“工具”Q?#8220;选项”Q?#8220;目录”Q将你安装Java的目录中的include和win32目录d上?br />
5Q将下面代码复制到MyDll.cpp文g的后面,build目Q将目文g夹下的Debug文g夹生成的MyDll.dll文g复制CMyDll.java同一个目录?/div>
1 JNIEXPORT jint JNICALL Java_MyDll_sum
2 (JNIEnv *env, jobject obj, jint _arg_i, jint _arg_j) 
3 {
4     int m_i = _arg_i;
5     int m_j = _arg_j;
6     int temp = m_i+m_j;
7     return temp;
8 }

6Q运行Java文g,输出一下结?br />

7Q?本例中也是参考网上的一些例子,弄了也是好久才做出来Q所以脓出来加深印象。在做的q程中需要注意细节?br /> 


]]> Java 接口和抽象类区别http://www.aygfsteel.com/feng0801/articles/396180.html冯威?/dc:creator>冯威?/author>Fri, 08 Mar 2013 01:03:00 GMThttp://www.aygfsteel.com/feng0801/articles/396180.htmlhttp://www.aygfsteel.com/feng0801/comments/396180.htmlhttp://www.aygfsteel.com/feng0801/articles/396180.html#Feedback0http://www.aygfsteel.com/feng0801/comments/commentRss/396180.htmlhttp://www.aygfsteel.com/feng0801/services/trackbacks/396180.html原文Q?a style="margin: 0px; padding: 0px; color: #336699; text-decoration: none; ">http://blog.csdn.net/sunboard/article/details/3831823

1.概述

一个Y件设计的好坏Q我惛_大程度上取决于它的整体架构,而这个整体架构其实就是你Ҏ个宏观商业业务的抽象框架Q当代表业务逻辑的高层抽象层l构 合理Ӟ你底层的具体实现需要考虑的就仅仅是一些算法和一些具体的业务实现了。当你需要再开发另一个相q的目Ӟ你以前的抽象层说不定q可以再ơ利??strong style="margin: 0px; padding: 0px; ">面对对象的设计,复用的重点其实应该是抽象层的复用Q而不是具体某一个代码块的复?/span>?/p>

说到了抽象,我就不能不提到曾让我头痛的Java接口和Java抽象cMQ这也是本文我想说的重点?/p>

既然面向对象设计的重点在于抽象,那Java接口和Java抽象cd有它存在的必然性了?/p>

Java接口(interface)和Java抽象c?abstract class)代表的就是抽象类型,是我们需要提出的抽象层的具体表现。OOP面向对象的编E,如果要提高程序的复用率,增加E序 的可l护性,可扩展性,必L面向接口的编E,面向抽象的编E,正确C用接口、抽象类q些有用的抽象类型作Zl构层次上的层?/p>

Java接口和Java抽象cL太多怼的地方,又有太多特别的地方,I竟在什么地方,才是它们的最佳位|呢Q把它们比较一下,你就可以发现了?/p>

  1. Java接口和Java抽象cL大的一个区别,在于Java抽象cd以提供某些方法的部分实现Q而Java接口不可?span style="margin: 0px; padding: 0px; color: #ff0000; ">Q就是interface中只能定义方法,而不能有Ҏ的实玎ͼ而在abstract class中则可以既有Ҏ的具体实玎ͼ又有没有具体实现的抽象方法)Q这大概是Java抽象cd一的优点吧Q但q个优点非常有用?strong style="margin: 0px; padding: 0px; ">如果向一个抽象类里加入一个新的具体方法时Q那么它所有的子类都一下子都得Cq个新方法,而Java接口做不到这一点,如果向一个Java接口里加入一?新方法,所有实现这个接口的cd无法成功通过~译了,因ؓ你必让每一个类都再实现q个Ҏ才行Q这昄是Java接口的缺?/u>?/strong>q个在我的另外一博?a style="margin: 0px; padding: 0px; color: #336699; text-decoration: none; ">mapreduce 新旧API 区别中有提到cM的问题,在新的mapreduce api中更們֐于用抽象类Q而不是接口,因ؓq更Ҏ扩展。原因就是上面划UK分所说的?/li>
  2. 一个抽象类的实现只能由q个抽象cȝ子类l出Q也是_q个实现处在抽象cL定义出的l承的等U结构中Q而由于Java语言的单l承性,所以抽象类作ؓcd定义工具的效能大打折扣。在q一点上QJava接口的优势就出来了,M一个实C一个Java接口所规定的方法的c都可以hq个接口的类型,而一个类可以实现L多个Java接口Q从而这个类有了多U类型?span style="margin: 0px; padding: 0px; color: #ff0000; ">Q用抽象类Q那么承这个抽象类的子cȝ型就比较单一Q因为子cd能单l承抽象c;而子c能够同时实现多个接口,因ؓcd比较多。接口和抽象c都可以定义对象Q但是只能用他们的具体实现类来进行实例化。)
  3. 从第2点不隄出,Java接口是定义؜合类型的理想工具Q؜合类表明一个类不仅仅具有某个主cd的行为,而且h其他的次要行为?/li>
  4. l合1?点中抽象cdJava接口的各自优势,L典的设计模式出来了Q声明类型的工作仍然由Java接口承担Q但是同时给Z个Java 抽象c,且实Cq个接口Q而其他同属于q个抽象cd的具体类可以选择实现q个Java接口Q也可以选择l承q个抽象c,也就是说在层ơ结构中QJava 接口在最上面Q然后紧跟着抽象c?/span>Q这下两个的最大优炚w能发挥到极至了。这个模式就?strong style="margin: 0px; padding: 0px; ">“~省适配模式”。在Java语言API中用了这U模式,而且全都遵@一定的命名规范QAbstract Q接口名?span style="margin: 0px; padding: 0px; color: #ff0000; ">QA extends AbstractB implements interfaceCQ那么A卛_以选择实现(@Override)接口interfaceC中的ҎQ也可以选择不实玎ͼA卛_以选择实现(@Override)抽象cAbstractB中的ҎQ也可以选择不实玎ͼ

Java接口和Java抽象cȝ存在是Z用于具体cȝ实现和承的Q如果你准备写一个具体类ȝ承另一个具体类的话Q那你的设计有很大问题了。Java抽象cd是ؓ了承而存在的Q它的抽象方法就是ؓ了强制子cdd实现的?/p>

使用Java接口和抽象Javac进行变量的cd声明、参数是cd声明、方法的q还cd说明Q以及数据类型的转换{。而不要用具体Javac进行变量的cd声明、参数是cd声明、方法的q还cd说明Q以及数据类型的转换{?br style="margin: 0px; padding: 0px; " />

2.实例

下面l出一个具体的接口ActionQ代码如下所C:

  1. package org.springframework.webflow.execution;  
  2. public interface Action {  
  3.     public Event execute(RequestContext context) throws Exception;  
  4. }  
在这个接口中Q定义了一个没有具体实现的ҎQ方法名叫做execute()Q返回类型是Event。如前面W一条所qͼ接口中的Ҏ都是没有实现的。这些方法的具体实现是在实现(implements)q个接口的类中给出的?/span>

再来看一个实现Action接口的抽象类AbstractActionQ代码如下?/p>

  1. package org.springframework.webflow.action;  
  2.   
  3. import org.apache.commons.logging.Log;  
  4. import org.apache.commons.logging.LogFactory;  
  5. import org.springframework.beans.factory.BeanInitializationException;  
  6. import org.springframework.beans.factory.InitializingBean;  
  7. import org.springframework.util.ClassUtils;  
  8. import org.springframework.webflow.core.collection.AttributeMap;  
  9. import org.springframework.webflow.execution.Action;  
  10. import org.springframework.webflow.execution.Event;  
  11. import org.springframework.webflow.execution.RequestContext;  
  12.   
  13. public abstract class AbstractAction implements Action, InitializingBean {  
  14.   
  15.     protected final Log logger = LogFactory.getLog(getClass());  
  16.   
  17.     public EventFactorySupport getEventFactorySupport() {  
  18.         return new EventFactorySupport();  
  19.     }  
  20.   
  21.     public void afterPropertiesSet() throws Exception {  
  22.         try {  
  23.             initAction();  
  24.         } catch (Exception ex) {  
  25.             throw new BeanInitializationException("Initialization of this Action failed: " + ex.getMessage(), ex);  
  26.         }  
  27.     }  
  28.   
  29.     protected void initAction() throws Exception {  
  30.     }  
  31.   
  32.     protected Event success() {  
  33.         return getEventFactorySupport().success(this);  
  34.     }  
  35.   
  36.     protected Event success(Object result) {  
  37.         return getEventFactorySupport().success(this, result);  
  38.     }  
  39.   
  40.     protected Event error() {  
  41.         return getEventFactorySupport().error(this);  
  42.     }  
  43.   
  44.     protected Event error(Exception e) {  
  45.         return getEventFactorySupport().error(this, e);  
  46.     }  
  47.   
  48.     protected Event yes() {  
  49.         return getEventFactorySupport().yes(this);  
  50.     }  
  51.   
  52.     protected Event no() {  
  53.         return getEventFactorySupport().no(this);  
  54.     }  
  55.   
  56.     protected Event result(boolean booleanResult) {  
  57.         return getEventFactorySupport().event(this, booleanResult);  
  58.     }  
  59.   
  60.     protected Event result(String eventId) {  
  61.         return getEventFactorySupport().event(this, eventId);  
  62.     }  
  63.   
  64.     protected Event result(String eventId, AttributeMap resultAttributes) {  
  65.         return getEventFactorySupport().event(this, eventId, resultAttributes);  
  66.     }  
  67.   
  68.     protected Event result(String eventId, String resultAttributeName, Object resultAttributeValue) {  
  69.         return getEventFactorySupport().event(this, eventId, resultAttributeName, resultAttributeValue);  
  70.     }  
  71.   
  72.     public final Event execute(RequestContext context) throws Exception {  
  73.         Event result = doPreExecute(context);  
  74.         if (result == null) {  
  75.             result = doExecute(context);  
  76.             doPostExecute(context);  
  77.         } else {  
  78.             if (logger.isInfoEnabled()) {  
  79.                 logger.info("Action execution disallowed; pre-execution result is '" + result.getId() + "'");  
  80.             }  
  81.         }  
  82.         return result;  
  83.     }  
  84.   
  85.     protected String getActionNameForLogging() {  
  86.         return ClassUtils.getShortName(getClass());  
  87.     }  
  88.   
  89.     protected Event doPreExecute(RequestContext context) throws Exception {  
  90.         return null;  
  91.     }  
  92.   
  93.     //抽象Ҏ  
  94.     protected abstract Event doExecute(RequestContext context) throws Exception;  
  95.   
  96.     protected void doPostExecute(RequestContext context) throws Exception {  
  97.     }  
  98. }  
在抽象类AbstractAction中,既有具体实现的方法,又有没有具体实现的抽象方?/span>

  1. //抽象Ҏ  
  2. protected abstract Event doExecute(RequestContext context) throws Exception;  
需要注意的是在抽象cMQ如果方法没有具体实玎ͼ是Ҏ后面没有{}Q,那么必须加上abstract来声明这个方法,而接口中不需要用abstract来声?/span>Q抽象类之所以被UCؓ抽象c,是因ؓ它包含有抽象Ҏ。含有抽象方法的cd做抽象类Q?/strong>?/span>

]]>
Collections.sort 使用Ҏhttp://www.aygfsteel.com/feng0801/articles/394350.html冯威?/dc:creator>冯威?/author>Thu, 17 Jan 2013 03:36:00 GMThttp://www.aygfsteel.com/feng0801/articles/394350.htmlhttp://www.aygfsteel.com/feng0801/comments/394350.htmlhttp://www.aygfsteel.com/feng0801/articles/394350.html#Feedback0http://www.aygfsteel.com/feng0801/comments/commentRss/394350.htmlhttp://www.aygfsteel.com/feng0801/services/trackbacks/394350.html 一U是Q重新写一个类q行Comparator接口compareҎ重写
建立Java文g User.java 代码如下Q注意(int没有compareToҎQ需要将intҎIntegerQ?br />
 1 public class User {
 2     private String name;
 3     private Integer age;
 4     public User(String nameTemp,Integer ageTemp)
 5     {
 6         this.name = nameTemp;
 7         this.age = ageTemp;
 8     }
 9     public String getName() {
10         return name;
11     }
12     public void setName(String name) {
13         this.name = name;
14     }
15     public Integer getAge() {
16         return age;
17     }
18     public void setAge(Integer age) {
19         this.age = age;
20     }
21 }

建立SortTest.java文g

 1 import java.util.ArrayList;
 2 import java.util.Collections;
 3 import java.util.Comparator;
 4 import java.util.List;
 5 
 6 public class TestSort {
 7     @SuppressWarnings("unchecked")
 8     public static void main(String args[]) {
 9         List userlist = new ArrayList();
10         userlist.add(new User("dd"4));
11         userlist.add(new User("aa"1));
12         userlist.add(new User("ee"5));
13         userlist.add(new User("bb"2));
14         userlist.add(new User("ff"5));
15         userlist.add(new User("cc"3));
16         
17         Collections.sort(userlist, new Comparator(){
18             public int compare(Object arg1, Object arg2) {
19                 User u1 = (User)arg1;
20                 User u2 = (User)arg2;
21                 int flag = u1.getAge().compareTo(u2.getAge());
22                 return flag;
23             }
24         });
25 
26         for (int i = 0; i < userlist.size(); i++) {
27             User user_temp = (User) userlist.get(i);
28             System.out.println(user_temp.getAge() + "," + user_temp.getName());
29         }
30     }
31 }

另一U是Q在实体对象中实现Comparable接口
建立user.javac?br />
 1 public class User implements Comparable<User> {
 2     private String name;
 3     private Integer age;
 4     public User(String nameTemp,Integer ageTemp)
 5     {
 6         this.name = nameTemp;
 7         this.age = ageTemp;
 8     }
 9     public String getName() {
10         return name;
11     }
12 
13     public void setName(String name) {
14         this.name = name;
15     }
16 
17     public Integer getAge() {
18         return age;
19     }
20 
21     public void setAge(Integer age) {
22         this.age = age;
23     }
24     public String toString() {
25         return "name is "+name+" age is "+age;
26     }
27     public int compareTo(User o) {
28         return this.age.compareTo(o.getAge());
29     }
30 }
建立TestSort.java文g
 1 import java.util.ArrayList;
 2 import java.util.Collections;
 3 import java.util.List;
 4 
 5 public class TestSort {
 6     @SuppressWarnings("unchecked")
 7     public static void main(String args[]) {
 8         List userlist = new ArrayList();
 9         userlist.add(new User("dd"4));
10         userlist.add(new User("aa"1));
11         userlist.add(new User("ee"5));
12         userlist.add(new User("bb"2));
13         userlist.add(new User("ff"6));
14         userlist.add(new User("cc"3));
15         
16         Collections.sort(userlist);
17         for (int i = 0; i < userlist.size(); i++) {
18             User user_temp = (User) userlist.get(i);
19             System.out.println(user_temp.getAge() + "," + user_temp.getName());
20         }
21     }
22 }


]]>
加法和打印时间、查扄LE序http://www.aygfsteel.com/feng0801/articles/308806.html冯威?/dc:creator>冯威?/author>Sat, 09 Jan 2010 02:45:00 GMThttp://www.aygfsteel.com/feng0801/articles/308806.htmlhttp://www.aygfsteel.com/feng0801/comments/308806.htmlhttp://www.aygfsteel.com/feng0801/articles/308806.html#Feedback0http://www.aygfsteel.com/feng0801/comments/commentRss/308806.htmlhttp://www.aygfsteel.com/feng0801/services/trackbacks/308806.html

import java.util.*;
class Student //定义一个类
{
    String xing;
    String xingming;
    void setStu(String xing1,String xingming1)
    {
     xing = xing1;
     xingming = xingming1;
    }
    void printStudent()
    {
     System.out.println(xingming);
    }
    public String toString()
    {
     return xing+" "+xingming;
 }
 }
class YongHu {
    public static void main(String args[])
   {
        Scanner sc = new Scanner(System.in);
        ArrayList a = new ArrayList();
     Student stu = new Student();
  /*有的对象添加到数组里面*/
  Student stu1 = new Student();
        stu1.setStu("?,"张三");
        a.add(stu1);
          
        Student stu2 = new Student();
        stu2.setStu("?,"李四");
             a.add(stu2);
            
        Student stu3 = new Student();
        stu3.setStu("?,"王五");
        a.add(stu3);
            
        Student stu4 = new Student();
        stu4.setStu("?,"李旺");
        a.add(stu4);
            
        Student stu5 = new Student();
        stu5.setStu("?,"张磊");
        a.add(stu5);
            
        Student stu6 = new Student();
        stu6.setStu("?,"张武");
        a.add(stu6);
            
        Student stu7 = new Student();
        stu7.setStu("?,"张杰");
        a.add(stu7);
            
        Student stu8 = new Student();
        stu8.setStu("?,"王石");
        a.add(stu8);

        while(true) {
         System.out.println("a:加法   b:输出当前日期   c:查找姓名  q是退?);
            System.out.print("误入字? ");
         String s = sc.next();
         if(s.equals("a"))
         {
    System.out.print("误入第一个数:");//d下面一?br />     int m=sc.nextInt();
    System.out.print("误入第二个?");
    int n=sc.nextInt();
    int he=m+n;
    System.out.println("它们的和?"+he);
         }
         if(s.equals("b"))
         {
          int Y,M,D,H,m,S;
        Y = Calendar.getInstance().get(Calendar.YEAR);//调用q䆾Ҏ
             M = Calendar.getInstance().get(Calendar.MONTH);//调用月䆾Ҏ
             D = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);//调用天䆾Ҏ
            H = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);//调用Ҏ
            m = Calendar.getInstance().get(Calendar.MINUTE);//调用Ҏ
             S = Calendar.getInstance().get(Calendar.SECOND);
             System.out.println("当前pȝ旉为:" + Y + "q? + (M+1) + "? + D +"? + H+"?+m + "?+S+ "U?);
             System.out.println();
         }
         if(s.equals("c"))
         {  
          System.out.print("误入姓? ");
          String name = sc.next();
    //System.out.println(name.length());q是看看它的长度
          if(name.length()==2) //字节来限?br />           {
              Iterator it = a.iterator(); // q代导引
        while(it.hasNext())
              {
                  Student h = (Student)it.next();//转化为Student对象
       if(h.xingming.equals(name))
      {
          h.printStudent();
      }
         }
          }
          if(name.length()==1) //字节来限?br />           {
              Iterator it = a.iterator();  
              while(it.hasNext())
              {
       Student h = (Student)it.next();//转化为Student对象
      if(h.xing.equals(name))
            {
                h.printStudent();
  
            }
   
         } 
          }
          }
          if(s.equals("q"))
          {
           break;
          }
        }
    }
}
q是E序的全?有点陋请大家不见W,请多多指教?/p>

]]>
վ֩ģ壺 | | ̶| | | | | ԭ| ƽ| | | | | | | ɽ| | ƽ½| ̨| | | ׿| Ӫɽ| Ӧ| | گ| ̨ǰ| | ˮ| | ٹ| | ɽ| ƽ| | Զ| | | ʯ| Զ| |