Java Chapter II: Data Types and operators

Source: Internet
Author: User
Tags naming convention

Today just class, Yang teacher said the conversion between the system: 16 binary: 1,2,3,4,5,6,7,8,9,a,b,c,d,e,f. Already mastered, just a stroke!

decimal integers, such as: 99,-500, 0
octal integers, which require starting with 0, such as: 0 15
Hexadecimal number, requires 0x or 0X, such as: 0x 15

Java is a strongly typed language with a naming convention for identifiers:

Can only be a letter, _, number, $ composition, and the first digit cannot be a number! Can not use keywords, strict case-sensitive, hump naming method, do see the name of the idea!

Data types in Java:

Basic data types: 4 Class 8, Integer type: Byte (1 bytes), short (2 bytes), int (4 bytes), Long (8 bytes), Float type: float (single precision, 4 bytes), double (doubles, 8 bytes), Character: char (2 bytes), Boolean: Boolean (1-bit/1bit, can only be ture or false). 1 bytes/1byte=8bit/8 bits.

Reference data type: Class, Interface (interface), array.

Unicode encoding set is International, 2 bytes, can represent a Chinese character (two bytes); 1 The default is the int type. 3.14 The default is the Doublie type . float pi = 3.14F This is the right way to write!

The final modified variable is constant, cannot be re-assigned, and the variable is best capitalized pi.

Scanner input = new Scanner (system.in);//Get the input stream of the keyboard, need the guide package before use: Import Java.util.Scanner;

Class Name Object name = new class name (parameter);//How to create an object

The assignment operator and the three-mesh operator have the lowest precedence, () [] have the highest precedence.

Data transformations in Java
1. Automatic conversion: Two data types are compatible with each other, the target type is greater than the source type (the range of small to large automatic conversion).
BYTE--->short-->int--->long--->float--->double
If multiple data types are mixed, the result should be the type with the largest range
2. Cast: The loss of precision can occur, even data distortion.
Syntax: (data type) an expression or variable;
Eg:double f=3.14;
int i = (int) F;

  

Java Chapter II: Data Types and operators

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.