Java is a more "pure" object-oriented language built on C ++. Everything in Java is an object.
C or C ++ indirectly manipulate objects through pointers, while Java uses reference to manipulate objects. In Java, except for the primitive (original) type, all types of objects must be created by the program. For efficiency, objects of the primitive type can be created without the use of new, and a non-reference "automatic" variable is created. The value of this variable is stored in the stack, therefore, it is more efficient. Primitive types include Boolean (T/F), char (16bit, Unicode), byte (8bit), short (16bit), INT (32bit), long (64bit ), float (32bit), double (64bit), and void; there are two special biginteger and bigdecimal. Creating an array in Java is actually creating an array of reference. These references are automatically initialized to a null value. Therefore, you must assign values using objects before using reference.
Data in Java can be stored in six places: 1. registers (registers): the fastest speed, allocated by the compiler; 2. STACK: In the "regular memory zone", the processor can directly access the stack pointer, And the stack pointer moves down to create a new space. Java generally places the object reference in the stack, but the object is not here; 3. heap: A Multi-Purpose memory pool. All Java objects are stored here. Different from stack, the advantage of heap is that the compiler does not need to know how much space to allocate or how long the data will be in the heap, because the heap is flexible, use new directly. 4. static storage: it is stored in Ram and can be accessed during the entire program running. You can use static statement; 5. constant storage: the constant value is usually directly stored in the program, which makes it safer. 6. non-ram storage: it is completely Program-independent and mainly includes "stream object" and "Persistent Object (stored on disk )".
Scope: eg: {string S = new string ("A string") ;}, the reference S disappears after the scope ends, but the string s indicates still occupies the memory. The Java Garbage Collector automatically recycles objects created by new without reference.
Build a Java program: namespace generally uses domain names to avoid duplication. net. yanhuohy; use import to import classes in other packages, only Java. lang is imported by default. static data and methods can be directly accessed without being connected to any instance of the class.
You can use/**... */to extract the Annotation with javadoc or embed HTML commands. For details, see javadoc syntax.
Programming style: the first letter in upper case represents the name of a class, and the first letter in lower case represents other methods, data members, variables, etc. For All, if a name contains multiple words, do not use a slide line to connect them directly. However, the first letter of the subsequent words is capitalized.