Java Foundation 2 (2015-8-3) variables and data types

Source: Internet
Author: User

1, write the program is repeated in the memory access operation, the data into memory, when needed to take out the address to do processing.

2, variable is the most basic program of storage unit, is the memory allocated to the memory interval, for storing the corresponding data, through the variable name can access the relevant data inside.

3. Allocate memory space according to data type.

4. Variables must be initialized before they can be used;

5, int a=b=c=5; the wording of the company is wrong; int a=3,b=6,c=9; right;

6, cannot affirm the same name variable, the address is the unique identification;

7, the keyword can not be used as a variable name;

8. Variable names are case-sensitive.

9, Java Strong type language, for each kind of data has defined specific data types, in memory allocated a different size of memory space (platform-independent)

10, Jvmjava virtual machine to the memory management: when Java executes A class, the execution of the process to allocate memory frequently. Stack memory (some basic types declared in a method when a method is called), heap memory (new Object -- reference type), method area (some information about loading a class, static variables, constants), and so on.

11, accuracy problem -- beyond the range of data type; incompatible type - The assigned value is inconsistent with the data type defined by the variable.

public class DataDemo1
{
public static void Main (String [] args) {

BYTE age=20;
byte age=128; exceeds maximum range
Age=true; type not compatible
System.out.println (age);
Short number1=200;
int number2=100;
Long number3=2000;//automatically converted from int to long type
Long number3=2000l; the same effect
Long number3=2000l; the same effect
System.out.println (NUMBER1);
System.out.println (NUMBER2);
System.out.println (NUMBER3);
Float data1=10.5;10.5 is the double type by default.
float data1=10.5f;
Double data2=10.345;
Double data3=.344;
Double data4=0.3456e3;//scientific counting method 0.3456*10^3;
System.out.println (DATA1);
System.out.println (DATA2);
System.out.println (DATA3);
System.out.println (DATA4);
Boolean flag=true;

flag=1;//Data Type inconsistency
SYSTEM.OUT.PRINTLN (flag);
}
}

Java Foundation 2 (2015-8-3) variables and 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.