Core Java for impatient notes

Source: Internet
Author: User
Tags shallow copy

Learn by analogy with C + +!

1. In Java the variable does not hold the object, the variable holds the object reference, you can think of the variable as a pointer in C + +, automatically manage memory

Manual initialization required (otherwise null pointer!) )

2.final is equivalent to const in C + +

Nested classes in Java:

1. Statically Nested classes:

Class can get the right to use variables and methods in a static nested class

2. Inner class

An inner class's method can access an instance variable of its outer class. In this case, they are instance variables of the outer class!

The difference between a static nested class and an inner class is that each inner class object has its own reference to an outer class object.

When calling an external class method, the actual call is OUTER.F ()

When interpreting an external class reference for an inner class, it is called a outer

An interface is a special class that can be used to abstract the behavior of Java! The default definition of an interface is static and final variables, which can be implemented by default!

The class that inherits the interface must implement the method of the interface! And declare the method of the interface as public!

The parent class method is preferred when the default method of the interface and the method of the parent class collide

Common interfaces in Java

Comparable interface

Comparator interface

Runnable interface that produces a function with no return value

A lambda expression is a piece of code that can pass this part as a defined method or object.

This in the lambda expression method represents the This parameter of the method that creates the lambda expression

It is often necessary to access variables from a closed method or class in a lambda:

When a lambda-defined behavior is called in a thread, the referenced variable may no longer exist ... What to do?

The lambda expression has three parts: 1. code block 2. Parameter 3. The value of a free variable (neither a parameter variable nor an internally defined variable)

The lambda expression must store these values in the data structure!

This means that these values have been captured by a lambda expression (to ensure that the captured values are well-defined, you can only refer to variables whose values do not change in lambda, final variables)

You can define a local class and then return the constructor, which is equivalent to implementing a simple factory design pattern:

Subclasses can use the keyword super to invoke the parent class's method or constructor.

The final method cannot be overwritten, and the final class cannot be inherited!
.

All classes in Java are subclasses of object and provide methods such as tostring,hash,clone,equals.

Class Loads the Java type of information, including classes, arrays, interfaces, basic types

The Reflection library allows the program to access the members, variables, and methods of the class during the run!

In the downward transition, the safe approach is to use instanceof detection and then convert with the forced type conversion Method!

Abstract methods and classes: An abstraction of the specific behavior of an object and an abstraction of a class of objects!

When you define the Equals method in a subclass, you first call the parent class's Equals method, because the object must not be equal when the parent class's check is not passed!

The own clone () is a shallow copy of the referenced reference, if a deep copy of its own definition is required.

When dealing with static members, they are chosen to be new in their construction order, because enumeration constants are built before static members, so you cannot reference any static members in the constructor.

Core Java for impatient notes

Related Article

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.