"The read in Java" Reading notes (i) Basic articles __java

Source: Internet
Author: User

One, the object is stored in that place
(1) Register (register) is located in the CPU, resources are limited by the program compiled according to the needs of the distribution
(2) Stacks (stack) are in RAM (Random Access menory), allocating memory through the stack pointer, and freeing memory on the pointer. Move the memory down.
The Java compiler must know the exact size and lifecycle of the data stored on the stack, including the storage of basic data types and object reference types
(3) The heap (heap) is located in RAM, storing Java objects, and the compiler does not need to know the size and lifecycle. Flexible, but allocating memory slower than stack
(4) Static storage is stored in RAM stored in the program running the data, but Java objects can not be stored in static storage space
(5) constant storage located in ROM (Read only menory) will never change,
(6) Non-RAM storage data exists outside the program, can not accept any program control, can exist when the program is not running, such as persistent objects and streams

Static Explanation:
(1) If you want to allocate memory for some specific data, regardless of how many objects you want to create, or you do not need to create any objects at all.
(2) This method can be invoked if some methods do not associate any objects of the class containing it, that is, no object is created.
Using static to define data and methods can be shared with all objects. can be accessed directly through a class. Called class data or class methods.

Second, initialization
Inside the class, the order in which the variables are initialized determines the order in which they are initialized. Even if the variable definitions are scattered between the method definitions, they can still
Any method, including the constructor, is initialized before being invoked.
Class a{
Public A (int ncount) {
System.out.println ("" +ncount);
}
}

Class b{
A a0 = new A (0);
Public B () {
System.out.println ("HelloWorld");
A2 = new A (3);
}
A a1 = new A (1);
public void F () {
System.out.println ("F ()");
}
A a2 = new A (2);
}

public class helloworld{
public static void Main (String []args) {
b b=new B ();
B.f ();
}
}


Print results:
0
1
2
HelloWorld
2
F ()

Third, the initialization of static data
A static data member is initialized only when the object of its corresponding class is created, and is not initialized after initialization, and is preceded by a non-static member
Before initialization.
Class bow1{
Public Bow1 (int market) {
System.out.println ("Bow1" ("+market+"));
}
public void f (int market) {
System.out.println ("F" ("+market+"));
}
}

Class table{
 static Bow1 b1 = new Bow1 (1);
 public Table () {
  system.out.println (" Table () ");
  b2.f (1);
 }
 public void F2 (int market) {
  system.out.println ("F2 (" +market+) ");
 }
  static Bow1 B2 = new Bow1 (2);
}

Class cupbord{
Bow1 B3 = new Bow1 (3);
static Bow1 b4 = new Bow1 (4);
Public Cupbord () {
System.out.println ("Cupbord");
B4.F (2);
}
void F3 (int market) {
System.out.println ("F3" ("+market+"));
}
static Bow1 B5 = new Bow1 (5);
}
public class Init {
public static void Main (String []args) {
SYSTEM.OUT.PRINTLN ("Creating new Cupbord in Main");
New Cupbord ();
SYSTEM.OUT.PRINTLN ("Creating new Cupbord in Main");
New Cupbord ();
T2.F2 (1);
T3.F3 (1);
}
static Table t2 = new Table ();
static Cupbord t3 = new Cupbord ();
}

Print results:
Bow1 (1)
Bow1 (2)
Table ()
F (1)

Bow1 (4)
Bow1 (5)
Bow1 (3)
Cupbord
F (2)

Creating new Cupbord in Main
Bow1 (3)
Cupbord
F (2)
Creating new Cupbord in Main
Bow1 (3)
Cupbord
F (2)
F2 (1)
F3 (1)

Summary: If there is a dog class
(1) When you first create a dog object or first access a static method of a class, the Java interpreter finds the classpath and navigates to the Dog.class file
(2) Loading the Dog.class file, the static method of the dog class and the static domain are accessed, and only initialized once during load
(3) Allocate enough storage space for dog above the heap
(4) The storage space is cleared 0, the base data type is initialized to the default value, and the reference type is set to NULL
(5) Perform initialization actions for all occurrences of the domain
(6) Execute constructor


The binding concept of the method Rtti RunTime type indentify run-time types recognition
Method calls and method associations are called bindings. When a method has final or static before it (the method that is modified by final is not overloaded and rewritten), the method is bound earlier. Because it can be determined at compile time.
The general approach is late binding, that is, at run time to determine which method is invoked, such as:
Class shap{
Public draw () {};
}

Class Circle extends shap{
Public draw () {};
}

Call
Shap circle = new Circle ();
Circle.draw ()//Here only at runtime can be determined to call the method in the Circle class draw ();
So how do you invoke (or bind) the Circle class at run time? This needs to know the class object class.
The class object is loaded when needed, and the Load method has an object that manufactures the class or is loaded through a class loader.
It contains information about the class.

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.