Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java基础知识笔记(1) #4

Open
hsipeng opened this issue Jul 5, 2017 · 0 comments
Open

java基础知识笔记(1) #4

hsipeng opened this issue Jul 5, 2017 · 0 comments
Labels

Comments

@hsipeng
Copy link
Owner

hsipeng commented Jul 5, 2017

首先确定以下概念:

  • 对象:对象是一个类的实例
  • :类是一个模块,它描述一类对象的行为和状态
  • 方法:方法就是行为,逻辑运算,数据修改,所有动作都是在方法中完成的
  • 实例变量:每个对象都有独特的实例变量,用于保存对象的状态。

类型变量

  • 局部变量 : 声明和初始化都在方法中
  • 成员变量: 定义在类中,方法体外
  • 类变量: static 修饰

数据类型

  • 内置数据类型:

    • byte(-2^7 ~ 2^7-1)
    • short(-2^15 ~ 2^15-1)
    • int(-2^31 ~ 2^31-1)
    • log(-2^63 ~ 2^63-1)
    • float(0.0f 32位)
    • double(0.0d 64位)
    • boolean
    • char(\u0000 ~ \uffff)
  • 引用类型:

    引用类型指向一个对象,指向对象的变量就是引用变量。如site

    Site site = new Site("http://lirawx.cn");
    

自动类型转换

  • 转换顺序
byte,short,char -> int -> long -> float -> double
  1. 不能对boolean转换
  2. 不能把对象转成不相关的类
  3. 容量大的转换成小的,转换过程总会溢出或损失精度
    int i = 128;
    byte b = (byte)i;
    byte最大127,会溢出
  4. 浮点数到整数,会舍弃小数,不是简单的四舍五入
    (int)12.7 == 12
    (int)-25.89f == -45

修饰符

访问修饰符

当前类 同一包内 子孙类 其他内
public 可以访问 可以访问 可以访问 可以访问
protected 可以访问 可以访问 可以访问 -
default 可以访问 可以访问 - -
private 可以访问 - - -

不使用任何关键字:对同一包内可见,接口变量隐式的声明为 public static final,接口里的方法默认情况访问权限为public。

非访问修饰符

  • static:独立于对象的静态变量,类变量,切静态变量只有一份拷贝
  • final:修饰的类不能继承,修饰的方法不能被继承类重新定义,变量不可修改
  • abstract:创建抽象类和抽象方法
  • synchronized/volatile: 用于线程
  • transient : 修饰短暂属性
@hsipeng hsipeng added the java label Jul 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant