Home > Java > Javagetting Started > What are the basic data types of java

What are the basic data types of java

醉折花枝作酒筹
Release: 2023-01-13 00:40:09
Original
93202 people have browsed it

There are 8 basic data types in Java, namely: byte (bit), short (short integer), int (integer), long (long integer), float (single precision), double (double precision) ), char (character) and boolean (Boolean value).

What are the basic data types of java

The operating environment of this tutorial: windows7 system, java10 version, DELL G3 computer.

About Java’s 8 basic data types, their names, digits, default values, value ranges and examples are shown in the following table:

What are the basic data types of java

In order to verify the contents of the table, run the verification code in eclipse as follows:

 package com.ce.test;

class Test {
    static byte b;
    static short s;
    static int i;
    static long l;
    static float f;
    static double d;
    static char c;
    static boolean bo;

    public static void main(String[] args) {

      System.out.println("byte的大小:"+Byte.SIZE
              +";默认值:"+b
              +";数据范围:"+Byte.MIN_VALUE+" - "+Byte.MAX_VALUE);

      System.out.println("short的大小:"+Short.SIZE
              +";默认值:"+s
              +";数据范围:"+Short.MIN_VALUE+" - "+Short.MAX_VALUE);

      System.out.println("int的大小:"+Integer.SIZE
              +";默认值:"+i
              +";数据范围:"+Integer.MIN_VALUE+" - "+Integer.MAX_VALUE);

      System.out.println("long的大小:"+Long.SIZE
              +";默认值:"+l
              +";数据范围:"+Long.MIN_VALUE+" - "+Long.MAX_VALUE);

      System.out.println("float的大小:"+Float.SIZE
              +";默认值:"+f
              +";数据范围:"+Float.MIN_VALUE+" - "+Float.MAX_VALUE);

      System.out.println("double的大小:"+Double.SIZE
              +";默认值:"+d
              +";数据范围:"+Double.MIN_VALUE+" - "+Double.MAX_VALUE);

      System.out.println("char的大小:"+Character.SIZE
              +";默认值:"+c
              +";数据范围:"+Character.MIN_VALUE+" - "+Character.MAX_VALUE);

      System.out.println("boolean的大小:"+Byte.SIZE
              +";默认值:"+bo
              +";数据范围:"+Byte.MIN_VALUE+" - "+Byte.MAX_VALUE);

    }
}
Copy after login

The output result on the console is as shown below:

Why is the data range of the output char here not 0 - 65535?

The char type in Java is represented by two bytes, that is, sixteen bits. Because it is an unsigned number, it is 2 to the 16th power, and the value range is: 0 - 2^16-1;

Recommended related video tutorials: Java video tutorial

The above is the detailed content of What are the basic data types of java. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template