Java Basics

1. Object & Variables

1.1 Object

Everything in Java is Object

1.2 Variables

  • 是一个被name命名的storage location,里面存储着一定的value。

  • 可以具有不同的types

2. Control Structures

To modify the flow of code in a program

2.1 condition

  • if

2.2 loop

  • for
  • while
  • foreach
for(char c : charArray) {
  ...
}

3. Data Structures

To store data in an organized and efficient manner

3.1 Array

  • fixed size
char[] charArray = new char[5];

3.2 ArrayList

  • flexible size
List<Character> arrayList = new ArrayList<Character>();

3.3 Maps

  • Key : Value
Map<String, List<String>> map = new HashMap<String, List<String>>();

4. Primitives & Wrapper

4.1 Primitives & its Object counterpart(Wrapper)

  • int & Integer
  • boolean & Boolean
  • double & Double
  • float & Float
  • char & Character

4.2 Primitives Size & Default value

  • 8种原始数据类型


    Primitive Data Type
  • Wrapper的default value为null

4.3 什么时候使用Primitive,什么时候使用wrapper?

Primitive更efficient,当需要参与的计算非常的直接,不需要处理类型的转换,不需要考虑极大,极小值等等时,优先考虑Primitive。 反之,考虑使用Wrapper。

5. Methods

code reuse

5.1 Access Control

a.k.a Access Modifiers

  • Visible to the package, the default. No modifiers are needed.
  • Visible to the class only (private).
  • Visible to the world (public).

because of class inheritance, all public methods and variables of a class are inherited by its subclasses. 所有public的东西会被子类继承

  • Visible to the package and all subclasses (protected).

同一个包,或者子类(无论同不同包)。因此可以理解为,隔离了非子类且不同包

5.2 Return Types

好处: 在函数定义的时候指明返回值类型,可以使对函数的使用更加明确。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Astronomygonova - A wrapper for libnova -- Celestial Mech...
    JumboWu阅读 8,867评论 0 41
  • 生命有限,生活应该是丰富多彩的,一个女人,最高的境界就是把生活过成诗。创业与生活完美的融合!一起感受如诗如画般的生...
    瑜伽赵老师阅读 422评论 -1 5
  • 用yum安装软件默认是不保存软件包的,如果要保存的话只需修改配置文件/etc/yum.conf,将keepcach...
    syp_xp阅读 502评论 0 0
  • 在前行中,我好像丢了好多东西啊。为了所谓的成熟,竟然开始随波逐流了,呵呵,就像以前听过的一句话:成熟不是越来越现实...
    一字_阅读 159评论 0 0
  • 聪明伶俐的白兔先生群-41吴蕙羽 任务一 我就是谁?我就是我,一个普通人。左脑右脑的选项,左脑符合9个,右脑符合3...
    吴蕙羽阅读 138评论 0 0