"Learning Notes" Java Core Technology learning notes finishing

Source: Internet
Author: User

"Java Core technology"

Spent half a day and read carefully the Java core technology in the class part, feel the recent programming time a lot of vaguely, "This is not right, try." What's wrong? "The confusion of this sort has been defined earlier.

    • Main function must be in the main class
    • A class is a machine, and to use the method, you need to build an instance of this class. If a constructor is defined in a class, the type of the constructor is the public class name, and the class name is the original class name
    • A class can have more than one constructor, and the constructor does not return a value.
    • Variables are marked as private, which means that only methods of that class can use these variables, and the methods of other classes may call this method if they cannot be marked public by methods of other classes.
    • Accessor method: GetName Change method: SetName is generally: private data fields, common accessor methods and change method,

B, if this method only needs to access the static domain of the class.

    • Static domain: A variable belonging to a class, private static int NextID, when the class is instantiated, there will be multiple objects, but only one static domain.
    • A class can contain only one public class with the same name and file name. Employtest.java contains the main method, Employ.java defines the class employ, then compile time Javac Employ*.java, in Java employtest, It automatically generates a class of Employ.java and then
    • Each class can have a main, which is used to test the class and do the unit tests.
    • This can call an implicit parameter. If there is no write constructor, there will be a default constructor, set the value to 0, set the object to null (note: The name of the string class will also become null, because string is a class)
Object and Class Basics

Object variables: Java object variables are equivalent to C + + object pointers

Construction: 1. Must have the same name as the class

2. Each class has at least one constructor, and the default is the parameterless constructor

3. can have 0 or more parameters

4. No return value

5. Can be private,protected or public, default is public

6. Always be used with the New keyword

Explicit parameters: Class method arguments in parentheses

Implicit parameter: The class object that appears before the method name when called, and the use of the This keyword in the method definition to represent the implicit argument

Class-based access: A method of a class can access the private domain of any instance of the class

Final instance fields: When you define an instance field as final, you must initialize such a domain when you create the instance, and for variable object variables, which are defined as final only means that the variable cannot reference another object, but the current object's internal data field can still be modified.

Static domain: The field is decorated with the static keyword, which indicates that each instance of the class has a copy of the domain, and that the static domain belongs to the class, not to any separate instances, each time it is modified, the field in each instance becomes the most recent value

Constants: Static + Final

static method: The class method is modified with static to indicate that the method cannot operate on an instance of the class, that the static method has no implicit argument (this), that the static method can only access the static domain in the class, that the instance domain cannot be accessed, and that the static method is called directly by the class name, such as Math.random ();

Method parameters

Java uses values to invoke

There are two types of method parameters:

1. Basic data types

2. Object references

For a basic data type parameter, the method cannot modify the argument (because the value is called)

For parameters referenced by an object, the shape participation argument points to the same object position, so the method can change the value inside the object, but cannot point the argument to a new object

Object construction

Overloading: The signature of a method includes the method name and its argument list, excluding the return value and access rights, and overloading is a set of methods with the same method name and a different parameter list, which is called by the compiler to pick a matching method based on the parameter list.

Default Domain initialization: If the field is not explicitly assigned in the constructor, the Value field is assigned as 0 by default, the Boolean field is assigned false, and the object variable is assigned NULL

Default constructor: If the constructor is not explicitly defined in the class definition, then by default the runtime system provides an empty constructor with no parameters

Explicit domain initialization: In a class definition, assigns the initial value directly to the domain when it is defined

Call another constructor: Use this (...) in the first sentence in a struct; You can call another overloaded constructor

Initialize Block: A code block is directly included in the class definition to assign an initial value to the domain

Object Construction Execution Order: contains static block, domain initialization statement, initialization block, multiple constructs

1. All data fields are initialized to 0, false, or null

2. Execute all static blocks sequentially in the order in which they appear in the class declaration

3. Execute all domain initialization statements and initialization blocks sequentially in the order in which they appear in the class declaration

4. If the first row of the constructor invokes the second constructor, the body of the second constructor is executed first

5. Executing the body of this construct

Object destruction: Java does not support object destruction, and the garbage collector recycles resources that are no longer needed

"Learning Notes" Java Core Technology learning notes finishing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.