Java Programming thought 4th the 2nd Chapter everything is the object

Source: Internet
Author: User

Java is based on C + +, but Java is a more purely object-oriented programming language, unlike C + +, Java only supports object-oriented programming, so Java programming style is also pure OOP style, that is, everything is a class, everything is done in the class object.

In Java, the use of references to manipulate objects, in the fourth edition of Java programming thought, the term used is "reference (Reference)", previously read the third version of Java programming thought, in the third edition, the use of the term "handle (handle)", in fact, I think the third edition of the term " Handle "more vivid and vivid, like you use a door handle to open the door to close the door, no tube door is what gate, in short you use the door handle can control operation this door." Of course, using the term "reference" is easier to understand for people with C + + origins, because in C + +, the underlying general uses pointers to implement references, which indirectly manipulate objects through pointers. More in tune, in C + +, the object that is dynamically allocated with new is anonymous, and there is no way to manipulate the object, except for the pointer returned by the new expression at the beginning, in Java, where the object is new and stored in dynamic memory, to use the object, It's going to be manipulated by the object's handle (reference), which virtually links Java to C + +, because both are essentially pointers-like things.

In Java, a reference can exist separately, as in C + +, the pointer is also a standalone existence. We can associate a reference to an object, or we can point the pointer to an object, so the reference (pointer) is independent of the object. As with pointers, it is not possible to use a reference without an associated object. In Java, references to non-associative objects can lead to compilation errors, which in C + + typically results in out-of-bounds memory, which in turn receives the segmentfault signal from the operating system, which is the program Coredump by default if the signal is not captured for processing. As shown in the following:

C++:

Java:

The features of a Java language are also implicitly described here: string strings can be initialized with quoted literals (the word value is the term I took from C + +), as shown in the following example:

String str = "Hello";

Once a reference has been created, in addition to being initialized directly with the above attribute, the reference must normally be managed to an object, and the creation of the object in Java can only be done through new. For the above example, you can write:

New String ("Hello");

Java Programming thought 4th the 2nd Chapter everything is the object

Related Article

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.