java just started learning record

Some of the features of java

  1. Simplicity

  2. Object-Oriented

  3. distributed

  4. Robustness

  5. safety

  6. Architecture-neutral

  7. portability

  8. Interpreted

  9. high performance

  10. Multithreading

  11. Dynamic

    For boolean notes:

    Boolean type has two values, true and false. Used to determine the logical condition. Not conversion between integer and Boolean type, which means that for a c and c ++, 0 equals false, 1 is equal to true. But for java it if you do, it will error if you give false conversion converted from 0, true to 1, you can use conditional statements,

    boole1?10;
    

    Object-Oriented

    For process-oriented program turned out that their work must first determine how to manipulate the data, and then decide how to organize such data, but also facilitate the operation of the data. This is why that program = algorithm + data structure, the algorithm in the first place. Children for object-oriented (OOP) who has swapped the order of the data in one, then consider this data manipulation algorithms.

    Objects

    For Java objects, if not mew out of it, the effect is similar to a pointer, a reference heap memory. Be sure to recognize: a Java object does not contain an actual object, but merely refers to an object. In java the value of any object variables are references to objects stored in another place. new operator returns a reference value is

    Date birthday = new Date();
    Date birthday1 = birthday;
    

    1550561487293

    The above statement has two parts, the expression new Date () construct a Date object type, and its value is a reference to the newly created object, this reference is stored in the birthday. This is the core java volume to say, my understanding is that new Date () creates an object of type Date, and store it in a heap, and then put the object in the heap want to address is stored in the date. Date birthday1 = birthday, birthday also point to the same memory, when executed

    birthday=null;
    

    When that time and did not really create a Date object deletion type, but the reference date address programmed null, does not refer to any type, and Date types are still in the heap in addition to waiting for the Java garbage collector.

    java local variables are not initialized to null. It must be initialized to null or set them by new.

    c ++ Notes : Many people mistakenly believe that java object reference variables and c ++ similar type. However, no null references, and references can not be assigned in in c ++. Java objects can be seen as a pointer to an object of c ++. Column such as:

    Date birthfay;//java
    

    In fact, equivalent to

    Date* birthday;//c++
    

    Once you understand this, all problems are solved. Of course, a a Date * pointer can be initialized by calling new. In this regard, c ++ and Java syntax is almost the same.

    Date* birthday = new Date();//c++
    

    If the value of a variable it is assigned to another variable, two variables point to the same date, or you can say the same two variables referenced object address, point to the same heap memory. That is, a pointer to the same object. Null java in c ++ references corresponding to the NULL pointer.

    All java objects are stored in the heap, when an object contains another object variable that still contains a pointer pointing to another heap objects.

    Method parameters

    To summarize the use of Java in parameters

    1. A method can not modify a basic data type of the parameter (i.e., numeric, and boolean)
    2. A method of an object can change state parameter
    3. A method can not make a reference to a new object parameter object
Share on the use of static, complete increment operator's staff id

In java static variables modified only one class creates all objects are shared, use of static code block is variable increment operator, because every time when new operation code block execution of the program, so be static mark variables in each time you create a new object will be incremented.

package hsj.alalgorithm;

import javax.xml.transform.sax.SAXTransformerFactory;
import java.util.*;

/**
 * Hello world!
 *
 */
public class App<E>
{
    public int id;
    public static int nextid=1;
    {
        id = nextid;
        nextid++;

    }
    public int getId(){
        return id;
    }
    public static void main( String[] args )
    {
        App app = new App();
        App app1 = new App();
        System.out.println(app.getId());
        System.out.println(app1.getId());
    }
}

Some notes on inheritance

Static and dynamic binding

Call the java process to figure out the method, the program is very important to our understanding, the following assumptions to call xf (args), the implicit parameter x declared as an object class C. Next we discuss the details of the procedure call:

1) type and a method declared by an object reference to the compiler, assumed that a call xf (param), and a hidden parameter declared object X, in which case the compiler will reference to method F (), if there is a method overloaded, if there is heavy load method, the compiler will then be determined by parameters which method to call. To determine the method that is called when you call parameter overload resolution , due to the presence of automatic type conversion, this determination process may be more complicated. If the compiler does not find matching method, or the type after conversion, there are multiple matching method, which is the compiler will report an error. This process is called dynamic binding .

* Note: The parameter names and method of approach is called a method signature, if the same methods in the superclass and subclasses have signed, then the child class square method in the superclass will be covered, but the return type not part of the signature, the type of random back to ensure consistency.

If the method is private, static methods, final method or constructor, then the compiler know exactly call it a method, this method will be called static binding

Each call must search method, a large time overhead. Therefore, a virtual machine created in advance for each class method table , which lists the actual method signature and call all methods. Such method call when you need only look-up on it.

Java simple way to read a file of records about

Convection first need to understand the concept of need:

In the Java API objects which can be read from a direct-sequence is referred to the input stream, and to which can be written to a byte stream objects called output. (In Java for the input and output for the memory, with respect to the memory or input memory called a read input, write from memory or written to a file called output.) The origin and destination byte sequence may be file, and usually is a file. But it may also be connected to a network, even a memory block. InputStream and OutputStream abstract class is a base class I / O class family. Here the process can be considered as the input and output operations on a pool of

Input :

For input, our goal is to make the contents of a file or elsewhere input into memory or program. This process can be divided into three parts.

  1. First is our target file, the target file can be seen as a dress that we need to read the contents of the pond. The pool may be may be bytes character stream thus generated can be divided into a byte stream and a stream of characters. We need to do is open the file

     FileInputStream file = new FileInputStream("D:\\qq\\a.txt");//或者
    /************************************************************************/
     File file = new File("D:\\qq\\a.txt");
     FileInputStream file = new FileInputStream(file);
    

    This process is like giving a loaded pond this target sequence mounted on a faucet. The next thing to do is to install the faucet water pipes, so that these direct flow (equivalent to water) can flow to memory.

  2. How to install water pipes,

    InputStreamReader input = new InputStreamReader(file, "GBK");
    //GBK是字节编码的方式,有时候会出现乱码,需要给出指定的编码方式。GBK是简体中文的编码。
    

reflection

Reflection library provides a very rich and well-designed set of tools, the purpose of the program to be able to write java code dynamic operation. Using reflection, especially in the design or add a new class operation, development tools, the ability to dynamically add new class of queries can be quickly applied, the ability to be able to analyze the program class called reflection.

Reflection mechanism may be used:

  1. In the run-time analysis capability class

  2. View objects at runtime, such as writing a toString () method for all classes use

  3. Array is achieved by an operation code (this not really understand)

  4. Using Method object that like in c ++ function pointers.

    During the program runs, the runtime system java objects are always maintained for all type flag is known as a run-time. This information is tracked for each object belongs to a class. Virtual machines using the appropriate runtime type selection method.

    We can access this information through the java class, the class holds these information are called Class. getClass Object class () method returns a Class instance.

    Inner classes

    Brief inner classes, inner classes are divided into members of inner classes, local inner classes, anonymous inner classes, static inner classes . Internal class is defined in another class in the class, the following three main reasons:

    1, the internal class can access the data of the class is the scope, including proprietary data.

    2, inner classes can be hidden to other classes of the same package.

    3, want to define a callback function, but do not want to write a lot of code is more convenient to use anonymous inner classes

    Members of the inner class :

    Members of the inner class is the equivalent of a member variable outside the class, we were a little too similar to the operation of the member variables in the operating members. Next we perform a detailed analysis of the inner class.

lambda expressions

Learn how to use a lambda expression to write cleaner code.

Why introduce lambda expression **: ** a lambda expression is a code block can be transmitted, may be performed one or more times later.

Next is the lambda format

(String frist,String second)->frist-length()-second.length

() ->, which is the basic of lambda expressions, -> contact followed by expression, the expression can not be written if the line may be enclosed in {}. lambda expression can be given a value according to the inferred document return value can also be displayed. But if the lambda expression only child to return a value on some branches, while in some other branch does not return a value, which is illegal

java generics

Generic programming means to write code that can be reused by many different types of objects.

Java appear before generics, generic programming is inheritance to achieve,

Guess you like

Origin blog.csdn.net/qq_39401252/article/details/93718388