zoukankan      html  css  js  c++  java
  • Java SE 第八十四,八十五,八十六讲 Observable类与Observer接口详解,深入理解观察者模式 Java内部类深度剖析及常见使用陷阱 Java SE IO详解

    1.内部类:(Inner class):Java中的内部类共分为4中.

    2.内部类:Group related classes and thus reduce namespace clutter

    defined at a scope smaller than a package

    An inner class can be defined inside another class,inside a method,and even as part of an expression.

    There are four types of inner classes

    a)static Inner classes(also called nested classes)

    b)member Inner classes

    c)local Inner classes

    d)anonymous Inner classes

    3.静态内部类(嵌套类)static Inner class

    a)The simplest forn of inner class

    b)Can’t have the same name as the enclosing class

    c)Compiled into a completely separtate .class file from the outer class

    编译生成单独的.class文件.

    文件名为:外部类名$内部类名.class

    d)Can access only static members and methods of the enclosing class, including private static members

    只能够访问外部类静态的成员,方法.

    e)Create an instance of a static inner class out of enclosing class:

    new outerclass.innnerclass();

    4.成员内部类:(member innerclass)

    Defined in an enclosing class without using the static modifier.定义在一个类的内部,且没有static关键字修饰.

    Like instance variables.就像实例变量一样.

    Can access all members of the enclosing class

    想在内部类中访问外部类的变量,可以使用outerclass.this.变量名.

    outerclass.this表示对外部类的引用.

    Create an instance within the enclosing class

    this.new Innerclass();

    Create an instance out of the enclosing class:

    (new Outerclass()).new Innerclass;

    Access members of the enclosing class with inner classes:

    Outerclass.this.member;//内部类引用外部类的成员变量`

    总结:成员内部类(member innerclass):可以访问外部类的静态与非静态的方法和变量,生成成员内部类的方法为:

    OuterClass.InnerClass inner = new OuterClass().new InnerClass();

    5.若想在局部内部类中访问外部类的成员变量,语法为:OuterClass.this.a;

    6.局部内部类(Local Innerclass):

    Defined within the scope of a method,even smaller blocks within methods.

    The least used form of inner class.

    Like local variables,can’t be declared public,protected,private and static

    Can only access final local variables.

    summary:定义在方法当中,只能当问方法中的final类型的变量.

    7.匿名内部类(Anonymous Inner Class)

    Local inner classes which don’t have class names

    No key word class

    No key word extends and implements

    No constructors

    Implicitly extend a superclass or implement an interface

    summary:匿名内部类会隐式地继承一个父类或者实现一个接口.

    8.Java IO系统:

    对于程序语言设计者来说,设计一个令人满意的I/O(输入输出)系统,是件极其困难的任务.-------------Think in Java

    9.File类:表示了磁盘上的文件或是目录.

    File提供了与平台无关的方法来对磁盘上的文件或目录进行操作.

    File类直接处理文件和文件系统

    File类没有指定信息怎样从文件读取或向文件存储.

    File类描述了文件本身的属性

    File对象用来获取或处理与磁盘文件相关的信息,例如权限,时间,日期和目录路径.

    File类还可以浏览子目录层次结构.

    10.路径分隔符:Java中默认的"\"表示转义字符,表示路径时,使用"\\"表示路径分隔符,也可以使用"/";建议使用"/"以提高可移植性.

  • 相关阅读:
    回家了
    AMP > Chapter 3 Concurrent Objects > Notes<1>
    Readings in Database Systems
    读书笔记:《Transaction Processing》Chapter 13 Buffer Management

    委托和事件的区别
    .net网页不完整的解决方案
    聚集索引,非聚集索引
    固定宽度下拉列表中option内容显示不全问题解决方法
    让你的Windows系统自动释放系统资源
  • 原文地址:https://www.cnblogs.com/donaldjohn/p/1988984.html
Copyright © 2011-2022 走看看