zoukankan      html  css  js  c++  java
  • JAVA 8学习笔记-第一章

    CHAPTER 1  Java Building Blocks

    1. comment

    // : single-line comment

    /*

    *

    */ : multi-line comment

    /**

    *

    */ : javadoc comment

    2. class

    Classes have two primary elements: methods and fields, classes are basic building blocks.

    The name of the file must match the name of the class, and have a .java extension.

    compile javafile in commandline: javac xxx.java

    run javaclass: java xxx

    main method: public static void main(String[] args){}

    Without main( ) method, the class can compile but can't run.

     

    3. import

    Imports only classes in the designated package, it doesn't import classes in child packages of designated.

    java.lang package is automatically imported.

    Explicit import takes precedure over the wildcard present.

    Use fully qualified class name to fix naming conflict

    import java.util.Date;

    import java.sql.*;

    Explicit class name:

     java.util.Date  date; //new-built object of type java.util.Date named date

     java.sql.Date sqldate; //

     

    4.  object creating

    1) constructor

    - match the name of the class without a return type.

    - to initialize fields

    2) instance initializer

    Codes blocks {}, which appear outside a method, are called instance initializers.

    3) order of initialization

    Fields and instance initializer blocks are run in the order in which they appear in the file.

    Then the constructor runs.

     

    4. Data type

    1) primitive types

    eight bulit-in:  byte, short, int, long, float, double, char, boolean.

    By default, java assumes that you define an int with a literal.

    long max = 3123456789;  // doesn't compile

    long max = 3123456789L;

    A floating-point literals are assumed to be double, so a float requires a letter f following the number.

    float f = 2.2;  // doesn't compile

    float f = 2.2f;

    Undercore can be added into a number except at the beginning of a literal, the end of a literal, right before the decimal point , or right after the decimal point.

    2) reference types

    A reference type refers to an object (instance of a class).

    Test s = new Test();

    3) key differences

    - A reference type can be asigned null, while primitive type can't.

    - A reference type have methods, while primitive type don't.

     

    6. Variables

    Declare a variable: state the type and give a name.

    Initialize a variable: give a value.

    Multiple variables of defferent types can't be declared in the same statement.

    String s, int num;  //doesn't compile

    1) identifiers

    - Can be combinations of letter, number, _ and $.

    - Can't begin with numbers.

    - Can't use java-reserved words.

    - Java is case-sensitive.

    Method and variable names begin with an lowercase letter followed by ComelCase.

    Class names begin with an uppercase letter followed by ComelCase.

    Package names use only lowercase.

    Constant names use only uppercase.

    2)initialization

    Local variables is a variable defined within a method. Local variables must be initialized before use.

    Instance variables are also called fields.

    Class variables hava a keyword static before it, and shared by multiple objects.

    As soon as you declare a class variable or instance variable, it's given a default value.

    Default value:

    boolean: false

    byte, short, int, long: 0

    float, double: 0.0

    char: 'u0000'

    reference type:  null

    3) variable scope

    Local variables can NEVER have a scope larger than the method they are defined in.

    Local variables---in scope from declaration to the end of the block{};

    Instance variables--in scope from declaration until object garbage collected

    Class variables (static) -- in scope from declaration until program ends.

     

    7. elements orders in class

    1) package

    2) import

    3) class

    mutiple classes can be defined in the same file, but only one of them is allowed to be public.  The public class matches the name of the file.

    A file is also allowed to have neither classes be public.

     

    8. garbage collection

    1) System.gc(): suggests garbage collection to run, but java is free to ignore the request.

    2) finalize(): is only run when the object is eligible for garbage collection. it could run zero or one time.

     

    9. benefits of java

    Object - Oriented: code defined in classes and instantiated into objects.

    Encapsulation: Java supports access identifiers to protect data from unintended access and modification.

    Platform Independent: compiled to bytecode and can be run on different systems.

    Robust: Java manage memory on its own and does garbage collection automatically, proventing memory leaks.

    Simple: get rid of operator overloading

    Secure: Java code runs inside the JVM.

  • 相关阅读:
    Altera的FPGA_常见问题汇总65
    图像处理中振铃现象 分类: 图像处理 2014-12-16 23:40 565人阅读 评论(0) 收藏
    空域高斯滤波与频域高斯滤波 分类: 图像处理 2014-12-13 14:52 560人阅读 评论(0) 收藏
    灰度世界算法(Gray World Algorithm) 分类: 图像处理 Matlab 2014-12-07 18:40 874人阅读 评论(0) 收藏
    Retinex系列之McCann99 Retinex 分类: 图像处理 Matlab 2014-12-03 11:27 585人阅读 评论(0) 收藏
    Retinex系列之Frankle-McCann Retinex 分类: Matlab 图像处理 2014-12-01 21:52 538人阅读 评论(2) 收藏
    Tenegrad评价函数 分类: 图像处理 Opencv 2014-11-12 20:46 488人阅读 评论(0) 收藏
    Base64编码与解码 分类: 中文信息处理 2014-11-03 21:58 505人阅读 评论(0) 收藏
    VS2010下安装Opencv 分类: Opencv 2014-11-02 13:51 778人阅读 评论(0) 收藏
    循环队列 分类: c/c++ 2014-10-10 23:28 605人阅读 评论(0) 收藏
  • 原文地址:https://www.cnblogs.com/shendehong/p/11703043.html
Copyright © 2011-2022 走看看