search
HomeJavaJavaBaseWhat are the eight basic data types of java?

What are the eight basic data types of java?

Jul 15, 2020 pm 05:55 PM
javaBasic data types

The eight basic data types of Java are: byte (bit), short (short integer), int (integer), long (long integer), float (single precision), double (double precision) , char (character), boolean (Boolean value).

What are the eight basic data types of java?

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

##1byte(bit)80 -2^7 - 2^7-1byte b = 10;2short(short integer)16##320-2^ 31 - 2^31-1int i = 10;long(long integer)64float(single precision)##0 - 2^16-1char c = 'c';8boolean(Boolean value) 8false

Serial number

##Data type

Number of digits

Default value

Value range

Examples

##0 -2^ 15 - 2^15-1 ##short s = 10; ##3
int(integer) 4
##0 -2 ^63 - 2^63-1 long l = 10l; 5
32 ##0.0 - 2^31 - 2^31-1 ##float f = 10.0f; 6 double(double)
64 0.0 -2^63 - 2^63-1 double d = 10.0d;
##7 char (character) 16 empty
##true, false boolean b = true;

##In order to verify the contents of the form, 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);

    }
}
The output result on the console is as shown below:


Why is the data range of char output 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 tutorial: "

java tutorial

"

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

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools