• Java


    2016-12-17  21:10:28

    吉祥物:Duke(公爵)    Logo:咖啡(爪哇岛盛产咖啡)  An overview of the software development process.

            

    《编程语言吉祥物之Duke》:http://www.cnblogs.com/turingbooks/p/3585919.html

    《Java Tutorials Learning Paths》:http://docs.oracle.com/javase/tutorial/tutorialLearningPaths.html

    《The Java™ Tutorials》:http://docs.oracle.com/javase/tutorial/

    《Java SE Specifications》:http://docs.oracle.com/javase/specs/index.html

    《Java™ Platform SE API Specification》:http://docs.oracle.com/javase/8/docs/api/index.html

    2016-12-24  12:17:20

    Variables

    The Java programming language defines the following kinds of variables:

    • Instance Variables (Non-Static Fields) Technically speaking, objects store their individual states in "non-static fields", that is, fields declared without the static keyword. Non-static fields are also known as instance variables because their values are unique to each instance of a class (to each object, in other words); the currentSpeed of one bicycle is independent from the currentSpeed of another.
    • Class Variables (Static Fields) A class variable is any field declared with the static modifier; this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated. A field defining the number of gears for a particular kind of bicycle could be marked as static since conceptually the same number of gears will apply to all instances. The code static int numGears = 6; would create such a static field. Additionally, the keyword final could be added to indicate that the number of gears will never change.
    • Local Variables Similar to how an object stores its state in fields, a method will often store its temporary state in local variables. The syntax for declaring a local variable is similar to declaring a field (for example, int count = 0;). There is no special keyword designating a variable as local; that determination comes entirely from the location in which the variable is declared — which is between the opening and closing braces of a method. As such, local variables are only visible to the methods in which they are declared; they are not accessible from the rest of the class.
    • Parameters You've already seen examples of parameters, both in the Bicycle class and in the main method of the "Hello World!" application. Recall that the signature for the main method is public static void main(String[] args). Here, the args variable is the parameter to this method. The important thing to remember is that parameters are always classified as "variables" not "fields". This applies to other parameter-accepting constructs as well (such as constructors and exception handlers) that you'll learn about later in the tutorial.

         You may also occasionally see the term "member" used as well. A type's fields, methods, and nested types are collectively called its members.

    Why Use Nested Classes?

    Compelling reasons for using nested classes include the following:

    • It is a way of logically grouping classes that are only used in one place: If a class is useful to only one other class, then it is logical to embed it in that class and keep the two together. Nesting such "helper classes" makes their package more streamlined.

    • It increases encapsulation: Consider two top-level classes, A and B, where B needs access to members of A that would otherwise be declared private. By hiding class B within class A, A's members can be declared private and B can access them. In addition, B itself can be hidden from the outside world.

    • It can lead to more readable and maintainable code: Nesting small classes within top-level classes places the code closer to where it is used.

    public class OuterClass {
        static class StaticNestedClass {
    
        }
    
        class InnerClass {
    
        }
    
        public static void main(String[] args) {
    
            OuterClass.StaticNestedClass nestedObject = new OuterClass.StaticNestedClass();
    
            OuterClass.InnerClass innerObject = new OuterClass().new InnerClass();
        }
    
    }

    Lambda Expressions

    One issue with anonymous classes is that if the implementation of your anonymous class is very simple, such as an interface that contains only one method, then the syntax of anonymous classes may seem unwieldy and unclear. In these cases, you're usually trying to pass functionality as an argument to another method, such as what action should be taken when someone clicks a button. Lambda expressions enable you to do this, to treat functionality as method argument, or code as data.

    The previous section, Anonymous Classes, shows you how to implement a base class without giving it a name. Although this is often more concise than a named class, for classes with only one method, even an anonymous class seems a bit excessive and cumbersome. Lambda expressions let you express instances of single-method classes more compactly.

    http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html

    http://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html

    When to Use Nested Classes, Local Classes, Anonymous Classes, and Lambda Expressions

    As mentioned in the section Nested Classes, nested classes enable you to logically group classes that are only used in one place, increase the use of encapsulation, and create more readable and maintainable code. Local classes, anonymous classes, and lambda expressions also impart these advantages; however, they are intended to be used for more specific situations:

    • Local class: Use it if you need to create more than one instance of a class, access its constructor, or introduce a new, named type (because, for example, you need to invoke additional methods later).

    • Anonymous class: Use it if you need to declare fields or additional methods.

    • Lambda expression:

      • Use it if you are encapsulating a single unit of behavior that you want to pass to other code. For example, you would use a lambda expression if you want a certain action performed on each element of a collection, when a process is completed, or when a process encounters an error.

      • Use it if you need a simple instance of a functional interface and none of the preceding criteria apply (for example, you do not need a constructor, a named type, fields, or additional methods).

    • Nested class: Use it if your requirements are similar to those of a local class, you want to make the type more widely available, and you don't require access to local variables or method parameters.

      • Use a non-static nested class (or inner class) if you require access to an enclosing instance's non-public fields and methods. Use a static nested class if you don't require this access.

    2016-12-22  08:20:00

    JDBC

    There are three different kinds of statements:

    • Statement: Used to implement simple SQL statements with no parameters.
    • PreparedStatement: (Extends Statement.) Used for precompiling SQL statements that might contain input parameters. See Using Prepared Statements for more information.
    • CallableStatement: (Extends PreparedStatement.) Used to execute stored procedures that may contain both input and output parameters. See Stored Procedures for more information.

    2016-12-22  07:42:08

    《Java分布式应用如何入门以及有哪些资料?》:https://www.zhihu.com/question/22764869

    2017-02-24  09:17:12

    //String.substring(int beginIndex, int endIndex)
    //IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.

  • 相关阅读:
    hexo博客搭建
    HDFS基本命令
    hadoop简单排序
    HBase实验
    linux版python升级依赖项问题
    hadoop大数据生态安装
    linux-anoconda更换镜像
    [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:排序、筛选和分页
    [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:实现基本的CRUD功能
    [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:建立一个EF数据模型
  • 原文地址:https://www.cnblogs.com/beidoufeng/p/6193282.html
Copyright © 2020-2023  润新知