n****e 发帖数: 678 | 1 请问一下, 平时用C++编程,现在因工作需要,要开始用Java编程,在有C++的基础下
,如何快速的学习Java?
不知道有什么open source 的project可以练习一下,顺便看看比较好的开源的Java
source codes是如何写的。
多谢! |
Y**G 发帖数: 1089 | 2 java 不就是简化版的c++吗,难的都会...
【在 n****e 的大作中提到】 : 请问一下, 平时用C++编程,现在因工作需要,要开始用Java编程,在有C++的基础下 : ,如何快速的学习Java? : 不知道有什么open source 的project可以练习一下,顺便看看比较好的开源的Java : source codes是如何写的。 : 多谢!
|
l*********s 发帖数: 5409 | 3 java's type erasure is very confusing. The shear number of design
patterns/frameworks is also daunting.
【在 Y**G 的大作中提到】 : java 不就是简化版的c++吗,难的都会...
|
c*********e 发帖数: 16335 | 4 java的东西都很简单的,但是很多术语都很唬人,什么di,就是通过setter来inject.
jsp是最简单的东西,做过一次就知道怎么回事了。
【在 l*********s 的大作中提到】 : java's type erasure is very confusing. The shear number of design : patterns/frameworks is also daunting.
|
l*********s 发帖数: 5409 | 5 yes, overall Java is much more friendly. but there is some aspect like type
erasure/generic very difficult to get used to for C++ programmers.
【在 c*********e 的大作中提到】 : java的东西都很简单的,但是很多术语都很唬人,什么di,就是通过setter来inject. : jsp是最简单的东西,做过一次就知道怎么回事了。
|
w**z 发帖数: 8232 | 6 generic 是不是和c++里的template 差不多?不懂c++,好像在哪看来的。
type
【在 l*********s 的大作中提到】 : yes, overall Java is much more friendly. but there is some aspect like type : erasure/generic very difficult to get used to for C++ programmers.
|
l*********s 发帖数: 5409 | 7 it looks similar, but type erasure is just terrible.
【在 w**z 的大作中提到】 : generic 是不是和c++里的template 差不多?不懂c++,好像在哪看来的。 : : type
|
z*******3 发帖数: 13709 | 8 这个在实际运行时候是不存在的
只是在开发和编译的时候带给你一定的好处
【在 l*********s 的大作中提到】 : it looks similar, but type erasure is just terrible.
|
l*********s 发帖数: 5409 | 9 en, any open source java projects recommended for learning? especially in
terms of design patterns?
【在 z*******3 的大作中提到】 : 这个在实际运行时候是不存在的 : 只是在开发和编译的时候带给你一定的好处
|
t***a 发帖数: 416 | 10 c++的template是编译期或者前面什么期就被替换了,所以vector和vector
>是两个完全不同的class
java语法差不多,但始终是一个class
【在 w**z 的大作中提到】 : generic 是不是和c++里的template 差不多?不懂c++,好像在哪看来的。 : : type
|
|
|
z*******3 发帖数: 13709 | 11 会用就行了,当然你想contribute是很好的
一般情况下,不遇bug不碰源码
【在 l*********s 的大作中提到】 : en, any open source java projects recommended for learning? especially in : terms of design patterns?
|
w**z 发帖数: 8232 | 12 Java generic 后加的,还要backward compatible, 就成现在这样子了。
全不同的class
【在 t***a 的大作中提到】 : c++的template是编译期或者前面什么期就被替换了,所以vector和vector: >是两个完全不同的class : java语法差不多,但始终是一个class
|
l*********s 发帖数: 5409 | 13 Just for self-teaching, :-)
【在 z*******3 的大作中提到】 : 会用就行了,当然你想contribute是很好的 : 一般情况下,不遇bug不碰源码
|
n****e 发帖数: 678 | 14 多谢大家的讨论,我也想看看比较好的open source java projects 的design
patterns。 |
r******r 发帖数: 700 | 15 Strategy Pattern一例,清晰易懂。如果非 OO 设计,就是弄三个 function 了。不过
,代码行数大大增加。
interface Strategy {
int execute(int a, int b);
}
/** Implements the algorithm using the strategy interface */
class Add implements Strategy {
public int execute(int a, int b) {
System.out.println("Called Add's execute()");
return a + b; // Do an addition with a and b
}
}
class Subtract implements Strategy {
public int execute(int a, int b) {
System.out.println("Called Subtract's execute()");
return a - b; // Do a subtraction with a and b
}
}
class Multiply implements Strategy {
public int execute(int a, int b) {
System.out.println("Called Multiply's execute()");
return a * b; // Do a multiplication with a and b
}
}
/** Configured with a ConcreteStrategy object and maintains a reference to a
Strategy object */
class Context {
private Strategy strategy;
public Context(Strategy strategy) {
this.strategy = strategy;
}
public int executeStrategy(int a, int b) {
return strategy.execute(a, b);
}
}
/** Tests the pattern */
class StrategyExample {
public static void main(String[] args) {
Context context;
// Three contexts following different strategies
context = new Context(new Add());
int resultA = context.executeStrategy(3,4);
context = new Context(new Subtract());
int resultB = context.executeStrategy(3,4);
context = new Context(new Multiply());
int resultC = context.executeStrategy(3,4);
System.out.println("Result A : " + resultA );
System.out.println("Result B : " + resultB );
System.out.println("Result C : " + resultC );
}
}
【在 l*********s 的大作中提到】 : en, any open source java projects recommended for learning? especially in : terms of design patterns?
|
l*********s 发帖数: 5409 | 16 many thanks!
【在 r******r 的大作中提到】 : Strategy Pattern一例,清晰易懂。如果非 OO 设计,就是弄三个 function 了。不过 : ,代码行数大大增加。 : interface Strategy { : int execute(int a, int b); : } : /** Implements the algorithm using the strategy interface */ : class Add implements Strategy { : public int execute(int a, int b) { : System.out.println("Called Add's execute()"); : return a + b; // Do an addition with a and b
|
p*****2 发帖数: 21240 | 17
Java可以弄三个function吗?
【在 r******r 的大作中提到】 : Strategy Pattern一例,清晰易懂。如果非 OO 设计,就是弄三个 function 了。不过 : ,代码行数大大增加。 : interface Strategy { : int execute(int a, int b); : } : /** Implements the algorithm using the strategy interface */ : class Add implements Strategy { : public int execute(int a, int b) { : System.out.println("Called Add's execute()"); : return a + b; // Do an addition with a and b
|
n****e 发帖数: 678 | 18 谢谢你的strategy pattern啊。 和C++中的virtual functions 有点像
还有什么其他的design patterns吗?
【在 r******r 的大作中提到】 : Strategy Pattern一例,清晰易懂。如果非 OO 设计,就是弄三个 function 了。不过 : ,代码行数大大增加。 : interface Strategy { : int execute(int a, int b); : } : /** Implements the algorithm using the strategy interface */ : class Add implements Strategy { : public int execute(int a, int b) { : System.out.println("Called Add's execute()"); : return a + b; // Do an addition with a and b
|
n****e 发帖数: 678 | 19 还有,不太理解你说的“如果非 OO 设计,就是弄三个 function 了”。
哪三个functions啊? 能展开说说吗?
【在 r******r 的大作中提到】 : Strategy Pattern一例,清晰易懂。如果非 OO 设计,就是弄三个 function 了。不过 : ,代码行数大大增加。 : interface Strategy { : int execute(int a, int b); : } : /** Implements the algorithm using the strategy interface */ : class Add implements Strategy { : public int execute(int a, int b) { : System.out.println("Called Add's execute()"); : return a + b; // Do an addition with a and b
|
n****e 发帖数: 678 | 20 二爷对学习java有什么建议吗?
【在 p*****2 的大作中提到】 : : Java可以弄三个function吗?
|
|
|
p*****2 发帖数: 21240 | 21
其实java不难学,core java的话看看书就差不多了,语法比较死板,变动不大。
看论坛绝大部分人都是搞j2ee的,这东西我没怎么好好学,感觉不难学,但是很看经验
。不做项目纯学可能够呛。很多概念不做大项目可能理解不好。
【在 n****e 的大作中提到】 : 二爷对学习java有什么建议吗?
|
r******r 发帖数: 700 | 22 用 C++ 的时候,觉得 c++ 很好。看了 template 用得熟的高手的代码,觉得很 cool.
原来 template 能够用得这么广泛。
现在都不弄 c++ 了。作为练习,最近刚刚把自己原来写过一段 code 改成 Strategy
了。三个 load() method, 根据不同文件格式,每个 load() 有所不同。改成
Strategy 试了试,感觉那段代码就好像就高了一个档次。
发现对象,封装做得好的设计,就是不一样,感觉代码就像贵族一样。
【在 n****e 的大作中提到】 : 谢谢你的strategy pattern啊。 和C++中的virtual functions 有点像 : 还有什么其他的design patterns吗?
|
r******r 发帖数: 700 | 23 哦,我就是说这样的;
public static int add (int a, int b){}
public static int subtract(int a, int b){}
public static int multiply(int a, int b){}
public static int divide(int a, int b){}
【在 n****e 的大作中提到】 : 还有,不太理解你说的“如果非 OO 设计,就是弄三个 function 了”。 : 哪三个functions啊? 能展开说说吗?
|
n****e 发帖数: 678 | 24 哈哈,这样啊
cool.
【在 r******r 的大作中提到】 : 用 C++ 的时候,觉得 c++ 很好。看了 template 用得熟的高手的代码,觉得很 cool. : 原来 template 能够用得这么广泛。 : 现在都不弄 c++ 了。作为练习,最近刚刚把自己原来写过一段 code 改成 Strategy : 了。三个 load() method, 根据不同文件格式,每个 load() 有所不同。改成 : Strategy 试了试,感觉那段代码就好像就高了一个档次。 : 发现对象,封装做得好的设计,就是不一样,感觉代码就像贵族一样。
|
n****e 发帖数: 678 | 25 恩,明白了。
【在 r******r 的大作中提到】 : 哦,我就是说这样的; : public static int add (int a, int b){} : public static int subtract(int a, int b){} : public static int multiply(int a, int b){} : public static int divide(int a, int b){}
|
n****e 发帖数: 678 | 26 恩,谢谢二爷指点。我估计也是要用j2ee的。 现在学java都是看oracle的online
tutorial之类的。
【在 p*****2 的大作中提到】 : : 其实java不难学,core java的话看看书就差不多了,语法比较死板,变动不大。 : 看论坛绝大部分人都是搞j2ee的,这东西我没怎么好好学,感觉不难学,但是很看经验 : 。不做项目纯学可能够呛。很多概念不做大项目可能理解不好。
|
p*****2 发帖数: 21240 | 27
没明白你这是什么意思。
【在 r******r 的大作中提到】 : 哦,我就是说这样的; : public static int add (int a, int b){} : public static int subtract(int a, int b){} : public static int multiply(int a, int b){} : public static int divide(int a, int b){}
|
n****e 发帖数: 678 | 28 就是不用面向对象的思想吧,用单个的function来处理吧
【在 p*****2 的大作中提到】 : : 没明白你这是什么意思。
|
p*****2 发帖数: 21240 | 29
跟strategy有啥关系呢?
【在 n****e 的大作中提到】 : 就是不用面向对象的思想吧,用单个的function来处理吧
|
n****e 发帖数: 678 | 30 单个function跟strategy没关系。
那个OO design的codes是遵循的strategy pattern。
【在 p*****2 的大作中提到】 : : 跟strategy有啥关系呢?
|
|
|
p*****2 发帖数: 21240 | 31
Strategy Pattern一例,清晰易懂。如果非 OO 设计,就是弄三个 function 了。
这句话怎么理解?OO设计给了例子。怎么弄三个function?
【在 n****e 的大作中提到】 : 单个function跟strategy没关系。 : 那个OO design的codes是遵循的strategy pattern。
|
n****e 发帖数: 678 | 32 他的意思是说:如果用strategy pattern, codes就是这个样子的:
=====================================================
interface Strategy {
int execute(int a, int b);
}
/** Implements the algorithm using the strategy interface */
class Add implements Strategy {
public int execute(int a, int b) {
System.out.println("Called Add's execute()");
return a + b; // Do an addition with a and b
}
}
class Subtract implements Strategy {
public int execute(int a, int b) {
System.out.println("Called Subtract's execute()");
return a - b; // Do a subtraction with a and b
}
}
class Multiply implements Strategy {
public int execute(int a, int b) {
System.out.println("Called Multiply's execute()");
return a * b; // Do a multiplication with a and b
}
}
/** Configured with a ConcreteStrategy object and maintains a reference to a
Strategy object */
class Context {
private Strategy strategy;
public Context(Strategy strategy) {
this.strategy = strategy;
}
public int executeStrategy(int a, int b) {
return strategy.execute(a, b);
}
}
=====================================================
如果不用strategy pattern,就简单的用单独的functions就可以了。codes是这个样子
的:
=====================================================
public static int add (int a, int b){}
public static int subtract(int a, int b){}
public static int multiply(int a, int b){}
public static int divide(int a, int b){}
======================================================
就是用两种不同的方式来实现 +, -, ×, /
我是这么理解的。
【在 p*****2 的大作中提到】 : : Strategy Pattern一例,清晰易懂。如果非 OO 设计,就是弄三个 function 了。 : 这句话怎么理解?OO设计给了例子。怎么弄三个function?
|
p*****2 发帖数: 21240 | 33
多谢。这次看明白了。看来他对strategy理解有很大的问题呀。
【在 n****e 的大作中提到】 : 他的意思是说:如果用strategy pattern, codes就是这个样子的: : ===================================================== : interface Strategy { : int execute(int a, int b); : } : /** Implements the algorithm using the strategy interface */ : class Add implements Strategy { : public int execute(int a, int b) { : System.out.println("Called Add's execute()"); : return a + b; // Do an addition with a and b
|
n****e 发帖数: 678 | 34 二爷展开说说strategy应该是啥样的啊
【在 p*****2 的大作中提到】 : : 多谢。这次看明白了。看来他对strategy理解有很大的问题呀。
|
p*****2 发帖数: 21240 | 35
你随便wiki一下就可以了。strategy长的确实是那个样子的,但是实际不是那个东西。
我以前没仔细看,我说怎么一直没明白呢。
【在 n****e 的大作中提到】 : 二爷展开说说strategy应该是啥样的啊
|
n****e 发帖数: 678 | 36 我就是看了wiki,觉得那个人写的挺像的。
为啥二爷说“实际不是那个东西”
【在 p*****2 的大作中提到】 : : 你随便wiki一下就可以了。strategy长的确实是那个样子的,但是实际不是那个东西。 : 我以前没仔细看,我说怎么一直没明白呢。
|
p*****2 发帖数: 21240 | 37
In computer programming, the strategy pattern (also known as the policy
pattern) is a software design pattern, whereby an algorithm's behaviour can
be selected at runtime. Formally speaking, the strategy pattern defines a
family of algorithms, encapsulates each one, and makes them interchangeable.
【在 n****e 的大作中提到】 : 我就是看了wiki,觉得那个人写的挺像的。 : 为啥二爷说“实际不是那个东西”
|