Java Basics-Data types & variables

Source: Internet
Author: User

Overview and use of constants

What is a constant?
Its value cannot be changed during program execution

 classConstant { Public Static voidMain (string[] args) {System.out.println ("Hello world!");//string ConstantsSYSTEM.OUT.PRINTLN (123);//Integer ConstantsSystem.out.println (12.3);//Decimal ConstantsSystem.out.println (' 1 ');//a single character must be stored in the character constant 'System.out.println (true);//Boolean constantSystem.out.println (false);//Boolean constantSystem.out.println ("");//Empty Constants    }}
Variable

When are the variables?
The amount of the value that can change within a range during the execution of a program

The format of the variable definition
Data type variable name = variable value;

Why do you define variables
Used to keep constant of the same type, and can be reused

Overview and classification of data types

Why do you have data types?
Java Yu Yuan is a strongly typed language that defines specific data types for each data type and allocates a different size of memory space in memory

Classification of data types in Java
1. Integer type:

    *byte    占1个字节       -128 到127     *short   占2个字节       -2^15 到2^15-1    *int     占4个字节       -2^31 到2^31-1    *long    占8个字节       -2^63 到2^63-1    

2. Float Type:

    *float    占4个字节       -3.403E38到3.403E38    *double   占8个字节       -1.798W408到1.798W408

3. Character Type:

    *char     占2个字节        0到 65535    

4. Boolean type:

    *boolean 理论上占八分之一个字节,因为一个开关就可以决定是true和false了,但是java中的boolean 并没有明确的指定其大小

Java Basics-Data types & variables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.