Java with notes (ii)

Source: Internet
Author: User
Tags comparable shallow copy

Process oriented: function as the center;
Object Oriented Programming

(macro) to the object-centric research issues, more in line with human thinking;
OOA: Object-oriented analysis;
OOD: Object-oriented design;
OOP: Object oriented development;
From top to bottom, gradually refinement;
Reuse: Large object properties can also be an object
Why is the concept of OO introduced?

What the framework does is to understand the coupling: let the coupling degree decrease

Scalability: Rapid response to demand change;

Class is a template for an object
Object is an instance of a class


Encapsulation: 1. Unity 2. Concealment
Inheritance of
Polymorphism: The implementation of polymorphism is based on inheritance. Redefine the behavior of a superclass (@Override method overrides, overrides) (same as method signature)

Employee emp=new Manager (); a reference to a parent class that points to a space like
Emp.work (); compile-time-declaration; run-time-allocates space. The run-time only to see what his behavior was.
A stack of logically stacked stacks with a physical stack.
Iterations are generally read-only, which is equivalent to a cursor on a database that scans multiple rows
foreach cannot make structural changes to the collection itself, such as: Cannot List.remove ("World");

Polymorphism: The unification of particularity to generality

Constructors are primarily used to initialize properties when objects are created, and other irrelevant don't put them inside

Ensure that each class has a parameterless constructor so that the call of the child class

A non-static variable belongs to a class-specific.
Static variables belong to the global.

Class loading time Precedes object instance
1:classload Open the portal for the static method
2:creat instance open a portal for real-column properties and methods
So:

Static methods cannot invoke the instance's member variables and methods
Instance's member variables and methods can reference static properties
Private can take public, public cannot take private.

Static methods are often used as tool methods.


Static block, which executes any action created by the object, but only once
Construction BLOCK: The new one executes once before the constructor;

The result of two numeric values cannot exceed the numeric range of that type in the computer, otherwise the arithmetic operations in the computer are considered to be out of bounds.
Solution: BigInteger provides subtraction function;

Lang package inside the class, do not import;
Overloading of methods is the embodiment of (static) polymorphism (at compile time)-(the industry views differ);
The override of a method is the embodiment of (dynamic) polymorphism (runtime)--a reference to a parent class that refers to an entity;


Operator overloading places such as: +-----1: plus 2: collocated symbols;
: Only parameter of method participates in overload judgment


References, anonymous objects


Abstract class: An abstract class can have an implementation method, not to have an abstract method, but the abstract method must be in the abstract class
Non-abstract subclasses inheriting abstract classes must implement their abstract methods
Abstract class cannot be an instance, only new its non-abstract subclasses
Abstract classes often embody polymorphism in design

Reference types: Arrays, classes, interfaces
Interface: Only public |static| Final to modify,
No attributes, only constants,
The method inside is the abstract method by default;

An inherited relationship between a class and a class (single inheritance)
Pseudo-Multiple inheritance:
The relationship between the class and the interface is implemented (can be implemented more)
The relationship of an interface to an interface is an inheritance relationship (multiple inheritance is possible)
Interfaces are a better representation of a set of behavior declarations, because the interfaces are abstract methods, which are higher than the abstraction level of abstract classes.

Compared to the 1.0 version of the vector, 1.2 of ArrayList sacrificed thread safety, but the performance was good

LinkedList bottom for circular doubly linked list
HashSet bottom layer is implemented by HashMap
HashMap's capacity reached 75% and began to expand.

Linkedhashset rewrite HashMap's Addemtry () method to use a doubly linked list for logical ordering
TreeSet must be inserted in the same type, in order to compare the sorting algorithm if it is your own object, you have to implement the comparable rewrite CompareTo method the underlying implementation as a two-fork tree

ClassCastException Type Conversion exception

instanceof. Is.. The implementation of this is an operator that returns a Boolean value

Interface is also a type, special type

When using TreeSet to judge the repetition, if the comparable interface is implemented to judge the Comparato () method, the Hashcode () and the Equals () method are not entered.


HashMap disorderly (more than can see HA), the key value may be repeated but retain the back one (pit). Entry<k,v>

Generic generics
Enhanced for loop also called Foreach Loop

Concurrentmodificatoinexception Concurrency Modification exceptions
Remove () for a collection that has been iterated over before it can be deleted or with an iterator that comes with it
Listiterator bidirectional iterator

Object cloning overrides the Clone () method of Object--first to determine whether the current object can be cloned, you need to implement the Cloneable interface, which is called the tag interface, there is no way to play a marker role.
There is a shallow copy and a deep copy of the concept, deep copy requires a layer of cloning, such as the current clone object inside the property is a reference type requires a deep copy;

Java with notes (ii)

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.