33

Java对象公约

 3 years ago
source link: http://www.cnblogs.com/noneplus/p/13376216.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

灵魂static关键字

Java规定:方法只能由对象来调用。

换句话来说,在面向对象的思维下,方法与对象存在一种强耦合。

static作用:即使没有初始化对象,也可以调用方法。(类比到属性上同样如此)

被static修饰的数据称为类数据,修饰的方法称为类方法。 并且Java推荐使用类名.方法名(或属性名)的方式调用。

对象的存储

  • 寄存器:CPU内存
  • 堆栈:存储对象的引用
  • 堆:存储对象

基本类型的特例

直接存储值,置于堆栈中

Java安全性体现之一:数组的范围检查

通过范围检查,确保数组会被初始化。

【范围检查:以数组上少量的内存开销和运行时的下标检查为代价】

基本类型的默认值

boolean false
int 0
float 0.0f
double 0.0d
char null

初始化并不包括局部变量:

int x;  //编译器会报错

反向域名引用包

import java.util.arrayList

驼峰风格

  • 类名的首字母要大写 >Main

  • 如果类名由几个单词构成,直接并在一起(每个单词的首字母都大写) >TestMain

  • 方法名的首字母小写

    类名:AllTheColorOfTheRainbow
    
    方法名:changeTheHueOfTheColor

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK