Java初探
2014-04-07 02:55
218 查看
打起这个念头是在做CC150时发现好多时候code太complex,不如java来的简单,早晚得学,所以就东一榔头西一棒子的看开了,也没怎么记。
昨天看到了wiki上一个很好的java与C++对比总结,很适合C++ers转向Java,http://en.wikipedia.org/wiki/Comparison_of_Java_and_C%2B%2B
今天又看了一些interfaces,inheritance等。
1. java函数传递,都是by-value,但是由于每个东西都是object的reference,所以就相当于pass-by-reference,一个明证在下:
Reference data type parameters, such as objects, are also passed into methods by value. This means that when the method returns, the passed-in reference still references the same object as before. However,
the values of the object's fields can be changed in the method, if they have the proper access level.
For example, consider a method in an arbitrary class that moves
Let the method be invoked with these arguments:
Inside the method,
by 23 and 56, respectively. These changes will persist when the method returns. Then
was passed in by value and cannot change. Within the method, the object pointed to by
2. 注意primitive,int和double是pass-by-reference的。
3. interface就相当于api,公司出于利益不想把具体的code公布,给出method signature(也就是method name和parameter list),关键词为interface,在具体implement的时候,类名后面加上implement XX (interface name)。
4. class的构建函数,可以不定义,但是每个函数都是object的子类,所以会跑到那里去default,但是如果在子类不定义,会跑到super里找无参数的constructor,如果没有,则complier会complain。
5. 多线程可以implement runnable函数,也可以继承thread的run(), http://stackoverflow.com/questions/541487/implements-runnable-vs-extends-thread
昨天看到了wiki上一个很好的java与C++对比总结,很适合C++ers转向Java,http://en.wikipedia.org/wiki/Comparison_of_Java_and_C%2B%2B
今天又看了一些interfaces,inheritance等。
1. java函数传递,都是by-value,但是由于每个东西都是object的reference,所以就相当于pass-by-reference,一个明证在下:
Reference data type parameters, such as objects, are also passed into methods by value. This means that when the method returns, the passed-in reference still references the same object as before. However,
the values of the object's fields can be changed in the method, if they have the proper access level.
For example, consider a method in an arbitrary class that moves
Circleobjects:
public void moveCircle(Circle circle, int deltaX, int deltaY) { // code to move origin of circle to x+deltaX, y+deltaY circle.setX(circle.getX() + deltaX); circle.setY(circle.getY() + deltaY); // code to assign a new reference to circle circle = new Circle(0, 0); }
Let the method be invoked with these arguments:
moveCircle(myCircle, 23, 56)
Inside the method,
circleinitially refers to
myCircle. The method changes the x and y coordinates of the object that
circlereferences (i.e.,
myCircle)
by 23 and 56, respectively. These changes will persist when the method returns. Then
circleis assigned a reference to a new
Circleobject with
x = y = 0. This reassignment has no permanence, however, because the reference
was passed in by value and cannot change. Within the method, the object pointed to by
circlehas changed, but, when the method returns,
myCirclestill references the same
Circleobject as before the method was called.
2. 注意primitive,int和double是pass-by-reference的。
3. interface就相当于api,公司出于利益不想把具体的code公布,给出method signature(也就是method name和parameter list),关键词为interface,在具体implement的时候,类名后面加上implement XX (interface name)。
4. class的构建函数,可以不定义,但是每个函数都是object的子类,所以会跑到那里去default,但是如果在子类不定义,会跑到super里找无参数的constructor,如果没有,则complier会complain。
5. 多线程可以implement runnable函数,也可以继承thread的run(), http://stackoverflow.com/questions/541487/implements-runnable-vs-extends-thread
相关文章推荐
- Java回调机制初探
- 初探Java装饰者模式和继承模式
- WebMagic Java爬虫框架初探
- JAVA设计模式初探之组合模式
- Java Lambda 表达式初探
- Java NIO和Netty框架(一)初探NIO
- 初探java反射
- 初探java的Proxy+InvocationHandler
- Java封装初探以及Mac下的eclipse操作实现
- 初探java内存机制_堆和栈
- JAVA设计模式初探之——门面模式(外观模式)
- JAVA NIO2模式之Proactor( JDK7 AIO异步网络IO初探)
- 初探12306售票算法(二)-java代码实践
- Windows下使用Java Jni调用C/C++初探
- java 反射初探(1)
- Java 9 平台模块系统初探
- JAVA设计模式初探之装饰者模式
- [转]Java7中的ForkJoin并发框架初探(中)——JDK中实现简要分析
- JAVA设计模式初探之装饰者模式
- 初探JAVA:语言特性(类)