Understanding and understanding of Java objects

Source: Internet
Author: User
Tags garbage collection

today is my first time since Learning programming blog, write down the weekday learning, originally these days are learning the web framework but I think it is necessary to comb the previous study. After all, learning Java before is very sketchy just for the purpose of exams. So, thinking in Java is the main book to consolidate Java from the beginning. The search for gaps and better understanding.   

everything is an object   .

 In C + + we know that manipulating objects with pointers, but almost everything in Java is an object, which simplifies the syntax. But it's important to note that in Java we manipulate objects by manipulating identifiers. That is, the identifier is actually a reference to the object. Be sure to have a reference to manipulate the object, but there are references that can have no objects. That is, we can have a reference but not necessarily associate it with an object. For example

1 String s;

  This will cause the error to be sent to S because the reference is empty. So when you write a program, you typically create a reference to initialize it for security.

and when we create a reference, we usually associate an object with the new operator. And new not only creates objects, but also gives information on how to produce this object. So all the objects in Java are created by ourselves. Java provides a number of types we can also create types ourselves. However, some of these types of programming often require special treatment, a series of types that are basic types. The special treatment is because new is storing objects in the heap. And this is not very effective for some simple small variables. So for this type of Java, like C + +, you create a variable that is not a reference, and this variable is stored and placed directly on the stack. So the size of the storage space for each basic type is constant. Each base type has a wrapper class that can create an object in the heap that corresponds to the base type, and then I'll detail the reason for wrapping the base type later.

  One of the notable considerations in Java is that we do not need to destroy objects, and all cleanup is done by Java itself.

1 { 2 string s = new string ("1"); The 3 }// scope endpoint reference s disappears at the scope endpoint, and the object that s points to still occupies memory space. Actually the object created with new is always preserved, as long as you need it, because the garbage collection mechanism of Java itself so we don't have to worry about freeing up memory.

class 

Since everything in Java is an object, we use classes to determine the appearance and behavior of a class of objects. In Java, what we do is define classes, produce objects of those classes, and send messages to those objects. You can set two elements in a class by defining a class: Fields and methods. When a member of a class is a base type and does not initialize Java, it gives him a default value. However, this method of initialization does not apply to methods.

The first blog did not understand the typesetting, do not want to write too much, right when the notes.

Understanding and understanding of Java objects

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.