Java Fundamentals-variables, data types, and operators

Source: Internet
Author: User
Tags arithmetic operators

1. Variable: A basic unit that stores data.
2. Declaration and assignment of variables:
1) Declare and assign values; data type variable name = value for example: int prince=10;
2) Declaration, assignment is divided into two steps: Data type variable name; for example: Int=price;
Variable name = value For example: price=10


3. There are two types of data:
1) Basic data type eight kinds:
Byte (-2 of 7 square to 2 of 7 square-1)
Short (-2 of 15 parties to 2 of 15 parties-1)
Int (-2 of 31 Square to 2 of 31 square-1)
Long (-2 of 63 square to 2 of 63 square-1) 99l
float Float Type 99f
Doubles double prince=32.5
Boolean True (True) False (False) Boolean isbrand=true;
Char one character, two byte range is 0-65535 reference ASCII character encoding table
Char sex= ' male '; char num=65; (Output a)
2) Reference data type:
String Strings name= "Zhang San";
Class
Interface

4. Variable Naming conventions:
English words or pinyin
Initials: Start with letters, underscores, and $
When multiple words are made up of variable names: Named by the Hump-type nomenclature. Example: Studentname
The name of the variable should be the result of knowing the meaning of the name

5. Assignment Operator: = Assign the right value to the left

6. Arithmetic operators: +-*/(except)% (take surplus)

7. num++; num=num+1; Num+=1;
num--; Num=num-1; Num-=1;
System.out.println (--num);//calculate and re-output first
System.out.println (num--);//First output recalculation

8.double avg= (90+99)/3.0 automatic type conversion occurs

Automatic conversion type conditions:
1) Type-compatible: (int and double are numeric)
2) The target type is greater than the source type: (double greater than int)

9. Coercion type conversion: (data type) variable name (data type) value

For example: Double num=5.5; int result= (int) num;
int result= (int) 5.5;

Java Fundamentals-variables, data types, and operators

Related Article

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.