Java Data types

Source: Internet
Author: User

1.1Program Overview

What is software? In fact, software is the process used to process data. The software can be divided into two parts, one part is "data" and the other part is "The logic of data processing".

1 program = data + logic

What is data? Electricity subcontractors example, the user is the data, the commodity is also the data. So what is data processing logic? The process of buying a product is the logic of data processing.

program development is inseparable from data, in fact, the white program is used to process data. In Java we want to learn the type of data and the amount of data.

Usually the data is changed, and the processing logic of the data is not changed. For example, the quantity of a product varies, and the number of users varies, but the process of purchase usually does not change.

1.2Data Type

There are types of data in life, such as a person's name is a string type, and the age of a person is a positive integer type. Data in Java is also typed (any 0 of the data must have a type), the following is the type of data in Java:

the base data type is the types built into the Java language are integer types, decimal types, character types, and Boolean types. These four basic types are the simplest and most basic types.

A reference data type is a powerful data type that is created based on a basic data type. A Super Class library is available in Javase, which contains nearly universal reference data types. But now we have to learn the basic type!

1.3Constants

The amount of data in Java is divided into constants and variables, we first learn constants!

constants are constant data volumes, such as the constant, where any amount of data has its type, What type is the constant? Recall that there are four classes in the base type, namely integers, decimals (floating-point numbers), characters, and Booleans. So What type is it? Yes, it's an integer constant!!

1.3.1 Integer type

1 Binary Representations: Beginning with 0b (0B)    , such as 0b1011, 0b10012 octal representation: starting   with 0 3 decimal notation: Normal numbers   such as25, 4 hexadecimal notation: Starting with 0x (0X)   number 0-9 and a-f composition  

1.3.2 Decimal type

1 such as 1.0,-3.15, 3.168, etc.

1.3.3 Boolean type

1 true,false

1.3.4 Character types

1 such as ' A ', ' a ', ' 0 ', ' Home '2 characters must be wrapped, and only one character can be included in it.

1.3.5 String type

1 strings String type is a reference type, we first understand how to use as a constant type 2 such as "I Love Java", "0123", "", "null"3 string must use "" "package, which can contain 0~n characters.

1System.out.println (' D0 ');//false A "can only wrap one character, error2System.out.println (");//false does not write or not, error3System.out.println (' d ');// Right4         5System.out.println ("");//Right double quotes inside wrapped content 0-countless6System.out.println ("0");//Right one7System.out.println ("double quotes here can be written countless, the number of words unrestricted");// Right

Review HelloWorld case, where System.out.println ("Hello world!") A string is placed in the parentheses. So can we replace the strings in parentheses with other strings? The answer is YES! You can change the strings in parentheses to other types of constants, for example:

We actually feel it by writing code: Const.java

1 /*2 * Demonstration of constants3 */4  Public classConst {5      Public Static voidMain (string[] args) {6         //integer Type7 //10 binary8SYSTEM.OUT.PRINTLN (100);9System.out.println (12345);TenSYSTEM.OUT.PRINTLN (10 ); One         //2 binary A System.out.println (0b1010); -         //8 binary -SYSTEM.OUT.PRINTLN (012 ); the         //16 binary -System.out.println (0xA); -         //Decimal Type -SYSTEM.OUT.PRINTLN (3.15); +         //Character Type -System.out.println (' a '); +System.out.println (' A '); ASystem.out.println (' 0 '); atSystem.out.println (' home ')); -         //Boolean type -System.out.println (true); -System.out.println (false); -         //String Type -System.out.println ("I love Java"); inSystem.out.println ("0123"); -     } to}

1.3.1 Integer type

Java Data types

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.