Java Programming Idea-the fourth edition of the Learning Summary, this is the second chapter: Everything is an object.
Package Com.w3cjava.second; @SuppressWarnings ("All") public class Second {/** * Java Programming Ideas (Fourth Edition) * Chapter 2nd everything is an object * @param args */public static void main (string[] args) {/** * 2.1 with reference Action Object * Remote control (Reference) Operation TV (object), change the volume, change the channel * * Even without a TV, remote control can exist independently, * As a result, references can exist independently and not necessarily associated with an object, but if you want to manipulate the reference, a run-time error is reported. * If you want to manipulate this reference, you need to initialize the reference while creating the reference. */String s1;//uninitialized/** * Create a String type reference S1 uninitialized, a run-time error occurs * SYSTEM.OUT.PRINTLN (S1); */String s2= "ABCD"; String s3 = new String (); String S4 = new String ("ABCD"); /** * Creates a string-type reference s2 initialization, string type can be initialized with quoted text */System.out.println (S2); System.out.println (S3); System.out.println (S4); /** * 2.2 All objects must be created by you * 2.2.1 Storage location * 1, Register: Located inside the processor, storage speed is the fastest, but the number is limited, on demand, not directly Access control. * 2, Stack: In RAM, the storage speed is second only to register, through the stack pointer can get direct support from the processor, the pointer moves downward, allocates new memory, conversely, frees memory. * When creating a program, Java must know the life cycle of all items stored in the stack so that the stack pointer moves up and down. * Some Java data is stored on the stack---especially object references, but Java objects are not stored in them. * 3, Heap: A common memory pool, located in RAM, for storing all Java objects. Storing data does not need to know the life cycle like a stack. * When an object is needed, new writes a simple line of code, which is automatically stored in the heap when the line of code is executed. * 4, Constant storage: Located inside the program code. * 5, non-RAM storage: Outside the program * Stream object---object into a byte stream * persisted object---object is stored To disk * * 2.2.2 Special case: Basic type * Instead of creating a variable with new, you create an "automatic" variable that is not a reference, which stores "values" directly on the stack, so higher Effect. Determine the size of the storage space that each base type occupies, and the size is the same. Have a wrapper type. * Char c = ' x '; * Character character=c; * System.out.println (character); * High-precision numbers: * BigInteger: integers that support arbitrary precision. * BigDecimal: Fixed-point number that supports any precision. * * Automatic packing function will automatically convert the base type to the package type * Character m = ' k '; * can also reverse convert * char l = m; * Array in 2.2.3Java: * C + +: Arrays-memory blocks, which can have unpredictable consequences if the program accesses an array or array of memory outside its own block of memory before initializing it. Use data at risk. * Java: Use array security. The Java array is initialized and cannot be accessed outside of its scope. */}/** * 2.3 Never need to destroy objects * 2.3.1 Scope: Determines the visibility and life cycle of the variable names that define them. * The scope of the 2.3.2 object: New object, as long as necessary, will remain. (The following method is physically new a String object, the method runs out, and the s reference disappears, but the new string ("SSSs") does not disappear immediately) * If Java keeps objects in place, then what prevents them from filling up the memory space , and then block your program? * Java garbage Collector, which monitors all objects created by new and identifies those objects that are no longer referenced, freeing up memory space for those objects. Avoids a memory leak issue. */public void scope () {String s = new String ("SSSs"); Return } /** * 2.4 Create a new data type: Class * Describes the appearance and behavior of a class of objects. * 2.4.1 fields and methods * field: Any type of Object * method: The way to do something * 2.5. Method/Parameter/return value * Return: Already done, leave this method, if the return type is void, the return keyword will only be used to exit the method. * 2.6 Build a Java program * */Newclass Newclass = new Newclass (); } Class newclass{}
"Java Programming Ideas-fourth Edition" chapter II: Everything is an object