Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How many data types are there in Java

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how many data types there are in Java. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

/ * * java is divided into 4 categories, 8 basic data types and 4 categories: 1. Integer (byte,short,int,long) 2. Floating point (float,double) 3. Character type (char) 4. Boolean (boolean) * / public class BaseDataType {public static void main (String [] args) {/ / Integer byte, short, int, long byte a1; / / byte occupies 1 byte = 8 bits-2 ^ 7-2 ^ 7-1 (- 128-127) short a2-10 / / short occupies 2 bytes = 16 bits-2 ^ 15 ~ 2 ^ 15-1 int a3Bytes 100; / / int occupies 4 bytes = 32 bits-2 ^ 31-1 long a4 bytes 1000; / / long occupies 8 bytes = 64 bits-2 ^ 63 ~ 2 ^ 63-1 System.out.println (A1); System.out.println (a2) System.out.println (a3); System.out.println (a4); / * Note: 1. If the integer assignment exceeds the storage range, the error reporting accuracy of compilation is lost * / / floating-point float, double double b1 error 10.1; / / double occupies 8 bytes = 64-bit float b2 upload 12.2f; / / float occupies 4 bytes = 32-bit float b3 = (float) 13.3 System.out.println (b1); System.out.println (b2); System.out.println (b3); / * Note: 1. Floating-point data is double by default. If you want to assign a value to float, you must go through forced type conversion. There are two ways to cast floating-point numbers: one is to add f directly to the end, and the other is to add (float) * / / the character type char is a single character enclosed in single quotation marks, char c1characters. / / char occupies 2 bytes = 16-bit char c2 'good'; char c3 'good'; System.out.println (c1); System.out.println (c2); System.out.println (c3); / * Note: 1. Numbers and letters account for 1 byte in calculated storage While Chinese characters occupy 2 bytes, java defines char to occupy 2 bytes to store letters and Chinese characters uniformly. The difference between char and String is that strings are multiple characters * / Boolean boolean boolean d1=true enclosed in double quotation marks. / / Boolean occupies 1 byte = 8 bits boolean d2 false; System.out.println (D1); System.out.println (D2); / * Note: 1. True of Boolean type cannot be equal to 1 and false is not equal to 0. This should be distinguished from c language * /}} / * Review: 1. Basic data type variables are divided according to the data type to which they belong: 8 basic data types (byte,short,int,long,float,double,boolean Char) reference data type variables: except for 8 basic data types, all variables are reference variables. String does not belong to the basic data type belongs to the reference data type * / this is the end of the article on "how many data types are there in Java" Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report