Java identifiers and basic data types

Source: Internet
Author: User

Identifiers are names that give classes, interfaces, methods, and variables, and represent references to memory space.

Identifiers consist of numbers, letters, _, $, but cannot begin with a number. Because Java is encoded in Unicode, it contains the alphabet (including Chinese) for most countries.

Naming conventions:

Project name, class name: First letter capital.

Package name: All lowercase.

Method name, variable name: In the case of a hump, when the identifier contains various meanings, the first letter of the English word is lowercase, the remaining words are capitalized, such as: Studentname, Teacherno.

Constant name: all caps.


There are eight basic types of data:

Integer class: Byte 1 byte

Short 2 bytes

int 4 bytes

Long 8 bytes

Logical class: Boolean 1 bytes

Floating-point type: Float 4 bytes

Double 8 bytes

Character type: Char 2 bytes

When a basic data type is created and given to a variable, the data is created in a constant pool of memory, which is not modified, and the variable references the data of a constant pool when the variable is assigned again. Therefore, when basic data is passed as a parameter, modifying the data of the formal parameter does not affect the argument.

However, string objects are special, string objects reference string data in a constant pool. When a string object is created, it first creates string data in a constant pool (the string data is a reference to char in a constant pool), and then creates a string object and references string data, so if you create multiple string objects of the same string, Their hashcode are all the same. If you reassign a variable of type string, you actually refer to a new string object, and the data for the original object does not change. There is also no way to change the current object data in the String class.

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.