免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1954 | 回复: 6
打印 上一主题 下一主题

Java和.NET开发语言的不同点 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-06-28 13:17 |只看该作者 |倒序浏览
Java语言和C#语言非常相似,虽然内部会有很多区别,提供的API也不一样,但开发一个具体功能点的思路常用的都差不多,由于对比较新的技术和特性开发过程中接触不多,我所遇到的不同点包括:
1、Java包的名字是和物理文件位置一一对应的, C#里命名空间可以随便写,并且编译出来的程序集也可以随便更改,可以不和命名空间保持一致,程序集和JAVA里单独打出来的jar包是差不多的意思。
2、JAVA的一个文件只能有一个公共类,而C#可以多个公共类在一个文件里。
3、如果找到一个JAR包,Java查看新jar包的方法字段描述,需要有单独的对应jar包的doc文档,才能看到接口调用参数说明,否则看起来不直观,但是如果有源码打出来的jar包,调试的时候可以方便的看到该包的源代码。.NET里只要有了dll文件,就能方便的看到方法元数据调用参数,但是看到参数详细说明,还是需要对应dll的xml文档。
4、对于WEB开发,JAVA里Filter,Servlet,Listener是很常用的,Java里的Filter可以用.NET里的module来实现一些功能,但Filter可以制定作用请求范围,module是全局控制的;Servlet相当于一个具体的handler,可以对制定请求进行处理,Listerner可以用.NET里的Application_Start里来完成一些功能,但是JAVA里集成了部分默认Listerner,它在WEB应用启动的时候就开始执行。它们的具体执行流程为:WEB启动时,Listener的ContextInitialized方法->所有Filter的Init(不管filter-mapping的值)->所有配置了load-on-startup大于等于0的Servlet的init方法(不管servlet-mapping的值),具体请求为:具体Servlet的init(只执行一次)->Filter doFilter(请求配置的filter-mapping的value)->Servlet service; 最后网站释放的执行顺序为:Filter destroy-》Listener contextDestroyed。
5、Java里的Final关键字,当给一个字段时,表示该字段不能修改,构造函数里都不能修改,这个和C#的const有点像,但是const默认是static的。和C#的readonly也比较像,但是readonly可以在构造函数里修改。当它作为一个方法的修饰符时,它类试c#的sealed类,不能重写它。
6、Java里没有静态构造函数,如果要实现一些初始化工作,需要用静态代码块,static{…},里面输入内容即可,C#只有静态构造函数的说法。

论坛徽章:
19
CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-09-18 15:15:15CU大牛徽章
日期:2013-05-20 10:46:44CU大牛徽章
日期:2013-05-20 10:46:38CU大牛徽章
日期:2013-05-20 10:46:31CU大牛徽章
日期:2013-05-20 10:46:25CU大牛徽章
日期:2013-05-20 10:46:18CU大牛徽章
日期:2013-04-17 11:19:51CU大牛徽章
日期:2013-04-17 11:19:42CU大牛徽章
日期:2013-04-17 11:19:37CU大牛徽章
日期:2013-04-17 11:19:32CU大牛徽章
日期:2013-04-17 11:19:28
2 [报告]
发表于 2012-07-01 19:15 |只看该作者
回复 1# easthome1998


    其实都差不多的,这些只是细节方面.

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:57:09
3 [报告]
发表于 2012-07-09 15:30 |只看该作者
C#里的静态成员不允许使用this关键字调用,Java允许。

论坛徽章:
0
4 [报告]
发表于 2012-07-13 01:33 |只看该作者
觉得c#方便

论坛徽章:
0
5 [报告]
发表于 2012-07-22 21:31 |只看该作者
Java里没有静态构造函数,如果要实现一些初始化工作

论坛徽章:
0
6 [报告]
发表于 2012-07-23 17:24 |只看该作者
觉得java灵活.

论坛徽章:
0
7 [报告]
发表于 2012-07-23 20:04 |只看该作者
本帖最后由 isaacxu 于 2012-07-23 20:09 编辑

Java与.net最大的不同就是,在Java的世界里可以看到Erich Gamma这类杰出工程师开发的实际代码,至少到目前还没看到Erich Gamma的C#代码。而阅读高手写的代码,是程序员提高自身的一种有效手段。
  1. /*
  2. * @(#)ChopDiamondConnector.java
  3. *
  4. * Project:                JHotdraw - a GUI framework for technical drawings
  5. *                                http://www.jhotdraw.org
  6. *                                http://jhotdraw.sourceforge.net
  7. * Copyright:        � by the original author(s) and all contributors
  8. * License:                Lesser GNU Public License (LGPL)
  9. *                                http://www.opensource.org/licenses/lgpl-license.html
  10. */

  11. package org.jhotdraw.contrib;

  12. import java.awt.*;
  13. import org.jhotdraw.framework.*;
  14. import org.jhotdraw.standard.ChopBoxConnector;
  15. import org.jhotdraw.util.Geom;

  16. /**
  17. * A ChopDiamondConnector locates connection points by choping the
  18. * connection between the centers of the two figures at the edge of
  19. * a diamond figure.
  20. *
  21. * @see Connector
  22. *
  23. * @author Erich Gamma
  24. * @version <$CURRENT_VERSION$>
  25. */
  26. public class ChopDiamondConnector extends ChopBoxConnector {
  27.         /**
  28.          * Serialization support.
  29.          * Needs to be fixed.
  30.          */
  31.         private static final long serialVersionUID = -1461450322512395462L;

  32.         public ChopDiamondConnector() {
  33.                 // only used for Storable implementation
  34.         }

  35.   public ChopDiamondConnector(Figure owner) {
  36.           super(owner);
  37.         }

  38.         /**
  39.          * Return an appropriate connection point on the edge of a diamond figure
  40.          */
  41.         protected Point chop(Figure target, Point from) {
  42.                 Rectangle r = target.displayBox();
  43.                 // Center point
  44.                 Point c1 = new Point(r.x + r.width/2, r.y + (r.height/2));
  45.                 Point p2 = new Point(r.x + r.width/2, r.y + r.height);
  46.                 Point p4 = new Point(r.x + r.width/2, r.y);

  47.                 // If overlapping, just return the opposite corners
  48.                 if (r.contains(from)) {
  49.                         if (from.y > r.y && from.y < (r.y +r.height/2)) {
  50.                                 return p2;
  51.                         }
  52.                         else {
  53.                                 return p4;
  54.                         }
  55.                 }

  56.                 // Calculate angle to determine quadrant
  57.                 double ang = Geom.pointToAngle(r, from);

  58.                 // Dermine line points
  59.                 Point p1 = new Point(r.x + r.width  , r.y + (r.height/2));
  60.                 Point p3 = new Point(r.x            , r.y + (r.height/2));
  61.                 Point rp = null; // This will be returned

  62.                 // Get the intersection with edges
  63.                 if (ang > 0 && ang < 1.57) {
  64.                         rp = Geom.intersect(p1.x, p1.y, p2.x, p2.y, c1.x, c1.y, from.x, from.y);
  65.                 }
  66.                 else if (ang > 1.575 && ang < 3.14) {
  67.                         rp = Geom.intersect(p2.x, p2.y, p3.x, p3.y, c1.x, c1.y, from.x, from.y);
  68.                 }
  69.                 else if (ang > -3.14 && ang < -1.575) {
  70.                   rp = Geom.intersect(p3.x, p3.y, p4.x, p4.y, c1.x, c1.y, from.x, from.y);
  71.                 }
  72.                 else if (ang > -1.57 && ang < 0) {
  73.                         rp = Geom.intersect(p4.x, p4.y, p1.x, p1.y, c1.x, c1.y, from.x, from.y);
  74.                 }

  75.                 // No proper edge found, we should send one of four corners
  76.                 if (rp == null) {
  77.                         rp = Geom.angleToPoint(r, ang);
  78.                 }

  79.                 return rp;
  80.         }
  81. }
复制代码

githubjavaVsdotnet.png (129.22 KB, 下载次数: 15)

githubjavaVsdotnet.png
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP