Java初探
来源:互联网 发布:python 贝叶斯分类器 编辑:程序博客网 时间:2024/05/17 03:48
打起这个念头是在做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 Circle
objects:
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, circle
initially refers to myCircle
. The method changes the x and y coordinates of the object that circle
references (i.e., myCircle
) by 23 and 56, respectively. These changes will persist when the method returns. Then circle
is assigned a reference to a new Circle
object 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 circle
has changed, but, when the method returns, myCircle
still references the same Circle
object 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初探
- 初探JAVA
- 初探Java
- java初探
- java初探
- java 反射机制初探
- java多线程初探
- java 线程初探
- java内存分配初探
- java初探-环境变量设置!
- 初探java内存分配
- java 线程初探
- 初探java内存机制
- java 敏捷开发初探
- java内存分配初探
- Java线程包初探
- java instrument 初探
- linux中fork()函数详解
- ftp报错 200 port command successful. consider using pasv 425 failed to establish connection
- macos+apache+php+phpmyadmin 的整合过程梳理
- 成绩统计--解题思路
- 游戏服务器里GUID的生成算法
- Java初探
- Mashmokh and ACM(Codeforces Round #240)
- Python六大开源框架对比:Web2py略胜一筹
- python 第一课,获取信息
- Oracle忘记用户名和密码的解决方案
- leetcode(word break)
- Linux 之Cut命令详解
- QQ通信原理及QQ是怎么穿透内网进行通信的?
- zoj-3772-Calculate the Function-线段树+矩阵