Thinking in Java II

Source: Internet
Author: User

    • manipulating objects by reference
    • Creates a reference that needs to be associated with an object, via new, such as: string s = new string ("AAA"); Otherwise S is empty

About storage Locations

    • CPU Registers: The fastest, on demand, unable to control
    • Stacks: In RAM, used to hold references to objects, stack pointers Move down, allocate memory, stack pointers move up, free memory
    • Heap: In RAM, storage of all objects, allocation of memory flexibility, than the above waste of time, new, the object exists in the heap
    • Constant storage: Constants are stored directly inside the code
    • Non-RAM storage: Stream objects and persisted objects, when used to get into RAM

Basic type

Relatively small, simple variables, without new creation, create variables directly, storing "values" between them, not references to objects, and storing them in stacks for more efficient

Basic type size (bit) wrapper type Related: I'll talk about it later.

Boolean ~

Char 16

BYTE 8

Short 16

int 32

Long 64

Float 32

Double 64

void

    • All numeric types have positive and negative numbers, no unsigned type
    • The Boolean type can only take a value of true or flase

Scope:

In Java C + + C, scopes are determined by curly braces

{

}

If you define a variable outside of {}, the object or variable is automatically destroyed and cannot be used, but you cannot create an object of the same name in a subdomain of the same scope. C++/C can.

To create a new data type: Class

Create Class

Class classname

{

}

You can then create objects from the class

Class name = new name ();

The class consists of two types of content, fields, and methods.

    • Field

The field is the data in the class, can be the basic type data, or it can be an object, if it is an object, it must be initialized with new method, otherwise it will be error, if it is the basic data type, can have no initialization, the system will initialize by default, but the basic type outside the class must also initialize, otherwise it is considered an error Its value is random.

Reference field: Name.name

    • Method

The method is the function, the basic component: name, parameter, return value, method body.

ReturnType methodName (/* Argument list */)

{

/*method body*/

}

Method names and parameter lists (called method signatures together) are used to uniquely identify a method

The method can only be created as part of a class, and can be called only through an object, calling the method format:

Objectname.methodname (Arg1, arg2, ARG3);

int x = A.F (); The return value for f must be of type int, which is called sending a message to an object.

Parameter list:

As with other stories that pass an object, the argument passes a reference to the object as well.

Thinking in Java II

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.