Home> Java> JavaBase> body text

What are java value types

angryTom
Release: 2019-11-13 15:53:08
Original
2931 people have browsed it

What are java value types

What are java value types?

java value types are basic data types, basic data types Often called four categories and eight types

Four categories: 1, integer type 2, floating point type 3, character type 4, logical type

Eight types:

1, 4 types of integer types: byte (2 to the 3rd power), short, int, long (2 to the 6th power)

2, 2 types of floating point types: float, double

3, 1 type of character type char

4, 1 type of logical type boolean

Value type:

means copying the current variable and passing it to Method, when you change the value of this variable in this method, the original variable value will not change

A data with a value type (value type) is stored in a variable on the stack. That is, allocating memory space in the stack and directly storing the contained value, the value represents the data itself.

Value type data has faster access speed.

Supplement:

Reference type:

means that the data you operate is the same, that is to say, one is passed in that year When the parameter is given to another method, and you change the value of this variable in another method, the value of the variable passed in when calling this method will also change

A data with a reference type (reference type) It does not reside on the stack, but is stored on the heap. That is, allocating memory space in the heap does not directly store the contained value, but points to the value to be stored, and its value represents the pointed address. When accessing data of a reference type, you need to check the contents of the variable on the stack, which refers to an actual data in the heap. Reference type data has larger storage size and lower access speed than value type data.

There is a garbage collection mechanism in Java. The variables in the stack memory are naturally destroyed as the method ends. When using reference types, when the method ends, the object may be used by another reference type. The application will not be destroyed. Only when an object does not have any reference variables, the garbage collection mechanism will recycle it.

php Chinese website, a large number of freeJava introductory tutorials, welcome to learn online !

The above is the detailed content of What are java value types. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!