Java certification exam official language skills

Disclaimer: if reproduced - please add 457 556 886 micro letter informed at all can share knowledge of https://blog.csdn.net/wolf_love666/article/details/90664269

Jdk-8:

First certification:

  • Java foundation
  • Java data types
  • An operator and a decision-making structure
  • Creating and Using Arrays
  • Using cyclic constructor
  • Packaging and use
  • Using inheritance
  • Handling Exceptions
  • Use Java API class selected

Section I: Java foundation

  • Variable
    four types of variables: instance variables were (a member variable, non-static variable), static variables, local variables and parameters
  • Naming rules:
    变量名区分大小写。变量的名称可以是任何合法标识符,一个由Unicode字母和数字组成的无限长度序列,以字母、美元符号“$”或下划线字符“_”开头。然而,习惯上,变量名总是以字母开头,而不是“$”或“_”。此外,根据惯例,美元符号字符从未使用过。您可能会发现在某些情况下,自动生成的名称将包含美元符号,但是您的变量名称应该始终避免使用它。下划线字符也有类似的约定;虽然从技术上讲,以“_”作为变量名的开头是合法的,但是不鼓励这样做。不允许使用空格。后续字符可以是字母、数字、美元符号或下划线字符。约定(和常识)也适用于此规则。当为变量选择名称时,使用完整的单词而不是模糊的缩写。这样做将使您的代码更容易阅读和理解。在许多情况下,它还会使您的代码自文档化;例如,名为cadence、speed和gear的字段要比缩写形式(如s、c和g)直观得多。还要记住,您选择的名称不能是关键字或保留字。如果您选择的名称只包含一个单词,请将该单词全部用小写字母拼写。如果由一个以上的单词组成,则将后面每个单词的第一个字母大写。名称gearRatio和currentGear是这种约定的主要例子。如果您的变量存储一个常量值,比如静态final int NUM_GEARS = 6,那么约定会稍微改变,将每个字母大写,然后用下划线分隔后面的单词。按照惯例,下划线字符永远不会在其他地方使用。
  • main method
  • The basic configuration of class Class: attribute constructors, methods
  • Creating and Using packages, as well as lead pack and static imports
  • Java features:
  • simple
  • Object-Oriented
  • distributed
  • Multithreading
  • dynamic
  • Architecture Neutral
  • Portable
  • high performance
  • the strong
  • Safety
    Here Insert Picture Description
    Here Insert Picture Description
    Here Insert Picture Description
  • Oriented programming concepts
  • What an object is?
    Object is a software package by the relevant state and behavior composed. Software objects commonly used for modeling real objects found in everyday life
  • What class is?
    Class is a blueprint to create an object or prototype. Define a class, its real object state and behavior modeling. It intends to focus on the foundation, it demonstrates that even a simple class can clearly state and behavior modeling.
  • What inheritance?
    Object-oriented programming allows classes to inherit from a common state and behavior of other classes.
  • What interfaces are?
    Interface is a contract between the class and the outside world. When a class implements an interface that promises a release behavior of the interface. (Note that the performance function interface
  • What package is?
    Package is a namespace used to logically organize classes and interfaces. The code in the package can make large software projects easier to manage.

Section 2: Handling Java data types

  • Use variables and attributes
  • The basic difference between variable and object reference variables point here
  • You know how to read and write object fields
  • Multiple inheritance:
  • Declare member variables:
    of the type name;
  • Create Object
    Point originOne = new Point (23, 94);
  • Using object
    Rectangle rectOne = new Rectangle (originOne, 100, 200);
    all classes have at least one constructor. If the class does not explicitly declare any, Java compiler automatically provides a no-argument constructor, called the default constructor. The default no-argument constructor class constructor calls the parent class, if there is no other parent class, object constructor is called. If the parent class has no constructor (a subject), the compiler will reject the program.
  • Life cycle interpretation objects (create, "dereference by reassigning" and garbage collection).
    Here Insert Picture Description
    Here Insert Picture Description
    Here Insert Picture Description
    This will call origin is initialized to one of the rectangle constructor originOne. Further, the constructor width to 100, 200 to the height. Now with reference to a two point object - An object may have multiple references, as shown above: the code below:
public class Rectangle {
    public int width = 0;
    public int height = 0;
    public Point origin;

    // four constructors
    public Rectangle() {
        origin = new Point(0, 0);
    }
    public Rectangle(Point p) {
        origin = p;
    }
    public Rectangle(int w, int h) {
        origin = new Point(0, 0);
        width = w;
        height = h;
    }
    public Rectangle(Point p, int w, int h) {
        origin = p;
        width = w;
        height = h;
    }

    // a method for moving the rectangle
    public void move(int x, int y) {
        origin.x = x;
        origin.y = y;
    }

    // a method for computing the area of the rectangle
    public int getArea() {
        return width * height;
    }
}

Section 3: construction using operators and decision

Using Java operation; covering parentheses operator precedence.
When the same precedence operators appear in the same expression, a rule must be used to decide which values to find. Assignment operators are evaluated from right to left; in addition to the assignment operators, all binary operators are evaluated from left to right
Here Insert Picture Description
: arithmetic operations Here Insert Picture Description
: unary operator
Here Insert Picture Description
before the increment / decrement operators may be applied operand (prefix) or after (suffix). ++ result code; result + +; as a result both are incremented by 1. The only difference is that the prefix version (c ++ result) is calculated as the increment value, while the postfix version (result ++) is calculated as the original value. If only perform simple increment / decrement, it does not matter which version you choose. However, if you use this operator in the larger expression, your choice of operator may produce significant differences.

等式、关系运算符和条件运算符
Here Insert Picture Description
条件操作符
Here Insert Picture Description
类型比较操作符instanceof

class InstanceofDemo {
    public static void main(String[] args) {

        Parent obj1 = new Parent();
        Parent obj2 = new Child();

        System.out.println("obj1 instanceof Parent: "
            + (obj1 instanceof Parent));
        System.out.println("obj1 instanceof Child: "
            + (obj1 instanceof Child));
        System.out.println("obj1 instanceof MyInterface: "
            + (obj1 instanceof MyInterface));
        System.out.println("obj2 instanceof Parent: "
            + (obj2 instanceof Parent));
        System.out.println("obj2 instanceof Child: "
            + (obj2 instanceof Child));
        System.out.println("obj2 instanceof MyInterface: "
            + (obj2 instanceof MyInterface));
    }
}

class Parent {}
class Child extends Parent implements MyInterface {}
interface MyInterface {}
输出结果

obj1 instanceof Parent: true
obj1 instanceof Child: false
obj1 instanceof MyInterface: false
obj2 instanceof Parent: true
obj2 instanceof Child: true
obj2 instanceof MyInterface: true

switch支持byte,short,char,int基本数据类型,也支持枚举类型,String类,以及包装类,Character,Byte,Short,Integer
警告:String是java7+以后支持的。

第4节:数组(一维和多维,以及jdk8+的并行排序)

Here is a quote
数组下标从0开始,
声明数组:
int[] anArray;
创建数组:
anArray = new int[10];
实例化数组:
anArray[0] = 100;
anArray[1] = 200;
anArray[2] = 300;
或者使用这种方式:
int[] anArray = {
100, 200, 300,
400, 500, 600,
700, 800, 900, 1000
};
多维数组声明:
String[][] names = {
{"Mr. ", "Mrs. ", "Ms. "},
{“Smith”, “Jones”}
};
警告:java.util.Arrays提供了几个便利的方法:排序,比较,填充,以及jdk8以后支持的并行排序。

第五节:循环

while和do-while
do-while和while之间的区别是do-while计算循环底部的表达式,而不是顶部的表达式。因此,do块中的语句总是至少执行一次,

class WhileDemo {
    public static void main(String[] args){
        int count = 1;
        while (count < 11) {
            System.out.println("Count is: " + count);
            count++;
        }
    }
}
class DoWhileDemo {
    public static void main(String[] args){
        int count = 1;
        do {
            System.out.println("Count is: " + count);
            count++;
        } while (count < 11);
    }
}

for循环
for (initialization; termination;
increment) {
statement(s)
}
initialization:初始化表达式初始化循环;它在循环开始时执行一次。
termination:当终止表达式的计算结果为false时,循环终止。
increment:每次循环迭代后调用增量表达式;此表达式可以完全接受值的递增或递减
或者使用增强for循环:

class EnhancedForDemo {
    public static void main(String[] args){
         int[] numbers = 
             {1,2,3,4,5,6,7,8,9,10};
         for (int item : numbers) {
             System.out.println("Count is: " + item);
         }
    }
}

break和continue和return
break的两种策略:
未带标记:只终止for循环

class BreakDemo {
    public static void main(String[] args) {

        int[] arrayOfInts = 
            { 32, 87, 3, 589,
              12, 1076, 2000,
              8, 622, 127 };
        int searchfor = 12;

        int i;
        boolean foundIt = false;

        for (i = 0; i < arrayOfInts.length; i++) {
            if (arrayOfInts[i] == searchfor) {
                foundIt = true;
                break;
            }
        }

        if (foundIt) {
            System.out.println("Found " + searchfor + " at index " + i);
        } else {
            System.out.println(searchfor + " not in the array");
        }
    }
}

带标记:(终止标记的代码块)

class BreakWithLabelDemo {
    public static void main(String[] args) {

        int[][] arrayOfInts = { 
            { 32, 87, 3, 589 },
            { 12, 1076, 2000, 8 },
            { 622, 127, 77, 955 }
        };
        int searchfor = 12;

        int i;
        int j = 0;
        boolean foundIt = false;

    search:
        for (i = 0; i < arrayOfInts.length; i++) {
            for (j = 0; j < arrayOfInts[i].length;
                 j++) {
                if (arrayOfInts[i][j] == searchfor) {
                    foundIt = true;
                    break search;
                }
            }
        }

        if (foundIt) {
            System.out.println("Found " + searchfor + " at " + i + ", " + j);
        } else {
            System.out.println(searchfor + " not in the array");
        }
    }
}

continue:跳过当前的执行,执行下一个
return:return语句退出当前方法,控制流返回方法调用的位置。return语句有两种形式:一种返回值,另一种不返回值。要返回值,只需将值(或计算值的表达式)放在return关键字之后

第6节:使用方法和封装

方法定义6个要求前提:

  • 修饰符,如public、private和其他稍后将介绍的修饰符。
  • 返回类型方法返回值的数据类型,如果方法不返回值,则为void。
  • 字段名的规则也适用于方法名,但约定略有不同。
  • 圆括号中的参数列表是以逗号分隔的输入参数列表,前面是它们的数据类型,后面是圆括号()。如果没有参数,则必须使用空括号。
  • 异常列表。
  • 方法主体位于方法代码的大括号之间,包括局部变量的声明。
    方法签名:
    定义:方法声明的两个组件包括方法签名—方法的名称和参数类型。
    calculateAnswer(double, int, double, double)

变量

  • 实例变量(非静态)
  • 类变量(静态)
  • 本地变量
  • 参数

嵌套类
嵌套类分为两类:静态类和非静态类。声明为静态的嵌套类称为静态嵌套类。非静态嵌套类称为内部类。
class OuterClass {

static class StaticNestedClass {

}
class InnerClass {

}
}
嵌套类是其封闭类的成员。非静态嵌套类(内部类)可以访问封闭类的其他成员,即使它们声明为私有。静态嵌套类不能访问封闭类的其他成员。作为外层类的成员,嵌套类可以声明为private、public、protected或package private。(请记住,外部类只能声明为public或package private。)
静态嵌套类与它的外部类(和其他类)的实例成员进行交互,就像任何其他顶级类一样。实际上,静态嵌套类在行为上是一个顶级类,它被嵌套在另一个顶级类中以方便打包。
静态嵌套类使用的语法:
OuterClass.StaticNestedClass nestedObject =
new OuterClass.StaticNestedClass();
内部类使用语法:
OuterClass.InnerClass innerObject = outerObject.new InnerClass();
警告:
强烈反对序列化内部类,包括本地类和匿名类。当Java编译器编译某些构造时,例如内部类,它创建合成构造;这些类、方法、字段和其他构造在源代码中没有对应的构造。合成结构使Java编译器能够实现新的Java语言特性,而无需更改JVM。然而,在不同的Java编译器实现中,合成结构可能会有所不同,这意味着.class文件也可能在不同的实现中有所不同。

第7节 : 继承(派生)

派生自另一个类的类称为子类(也称为派生类、扩展类或子类)。派生子类的类称为超类(也称为基类或父类)。
除了没有超类的对象之外,每个类都有且只有一个直接超类(单继承)。在没有任何其他显式超类的情况下,每个类都是对象的隐式子类。
类可以从类派生的类派生出类,也可以从类派生出的类派生出类,以此类推,最终从最顶层的类Object派生出类。这样的类据说是继承链中所有类的后代,继承链一直延伸到Object。Here Insert Picture Description
使用继承转换为父类对象为了避免出错可以
使用instanceof操作符对特定对象的类型进行逻辑测试。这可以避免由于不正确的转换而导致的运行时错误
Here Insert Picture Description
在子类中,可以重载从超类继承的方法。这样的重载方法既不隐藏也不覆盖超类实例方法——它们是子类特有的新方法。
子类的构造方法:
如果构造函数没有显式调用超类构造函数,Java编译器将自动向超类的无参数构造函数插入一个调用。如果超类没有无参数构造函数,则会得到编译时错误。Object确实有这样的构造函数,所以如果Object是惟一的超类,那么就没有问题。

第八节:处理异常

  • 三种异常:
  • 检查异常
  • 错误
  • 运行异常

第9节:选择合适的API(只提lamda表达式)

Over Lambda expressions by Example
1: creation method to find members of the method a characteristic that matches
2: create a more generalized search method Method
3: Specify the search condition code in the local class Method
4: code specifies search criteria in an anonymous class method
5: specify condition code search method and Lambda
6: using a standard manner and Lambda function interface of
7: throughout the application method
8 using Lambda expressions: wider use of generic methods
9: using GUI application syntax accepted Lambda expressions polymerization operation as a parameter, local variables Lambda expressions closed range, the target type, the target type and method parameters serialize

Guess you like

Origin blog.csdn.net/wolf_love666/article/details/90664269