Home > Java > javaTutorial > What are the data types of java

What are the data types of java

下次还敢
Release: 2024-04-21 02:15:39
Original
537 people have browsed it

The data type defines the type of value stored in the variable and determines the scope and operation of the variable. There are 8 primitive data types and two reference types in Java. Integer type: byte, short, int, long Floating point type: float, double Character type: char Boolean type: boolean Array: Collection class used to store elements of the same type: used to define and create objects

What are the data types of java

Java Data Types

What are data types?

Data types define the types of values ​​that variables can store. It determines the scope, precision, and operation of the variable.

Data types in Java

There are 8 main primitive data types and two reference types in Java:

Primitive data types

  • Integer type: byte, short, int, long
  • Floating point type: float, double
  • Character type: char
  • Boolean type: boolean

Reference type

  • Array: Used to store a collection of elements of the same type
  • Class: Used to define and create objects

Primitive data type

Integer type

Stores integers, with different lengths and ranges:

  • byte: 8 bits, range: -128 to 127
  • short: 16 bits, range: -32,768 to 32,767
  • int: 32 bits, range: -2,147,483,648 to 2,147,483,647
  • long : 64 bits, range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

##Floating point type

Storage floating point number (decimal):

    float: 32 bits, the precision is about 6-7 significant digits
  • double: 64 bits, the precision is about 15-16 significant digits

Character type

Stores a single character, the bottom layer uses Unicode character encoding:

    char: 16 bits, can store any Unicode character

Boolean type

Storing boolean value (true or false):

    boolean: true or false

Reference type

Array

Reference type, which can store a collection of elements of the same type:

    int[] numbers = {1, 2, 3} ;

Class

Reference type, used to define and create objects:

    class Person { String name; int age ; }

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

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template