Java Learning Notes (basic data types and variable naming rules) __java

Source: Internet
Author: User

Java basic data Types

variable
1. Variable is the variable quantity.
2. Constants are immutable quantities.
3. Literal: Java variables and constants stored in the specific data into the literal amount.
variable
Naming rules:
(1) The first letter is an English letter, a $ or an underscore, consisting of letters, numbers, and underscores.
(2) The name of the variable follows the principle of seeing the uprising.
(3) The Java variable name is not recommended in Chinese.
(4) The first letter of the variable name is not recommended for uppercase letters.
(5) The name of a variable named multiple words by means of the hump nomenclature.
(6) Variable name do not use the Java keyword.
Defined:
Each variable must belong to a data type.
Type variable name 1, variable 2, ..., variable n;
Example:
BYTE score;
Short age;
int Sumscore;
Long fileSize;
float X,y;
Double result;
Boolean OK;
string S;
Initialization of a variable
Variable name = value;

Example: OK = 1;
x=y=1;//Continuous Assignment
int ans=0;//Declaration and initialization

In Java, a pair of {} is a scope that does not allow the occurrence of a variable of the same name in the same scope.
(As with the case of different scopes is not covered in this section, see later articles.) )

Import java.io.*;  
Import java.math.*;  
public class test02 {public  

    static void Main (string[] args) {  
        //TODO auto-generated method Stub  
         String a = " 1 ";  
         String a = "2";  
         System.out.println (a);  
    }  

  

The above code again defines a in the same scope after the string A is defined, and an error is made.
Of course, if you change the above code to

Import java.io.*;  
Import java.math.*;  
public class Test02 {  
        String a = "1";  
    public static void Main (string[] args) {  
        //TODO auto-generated method Stub  

         String a = "2";  
         System.out.println (a);  
    }  

  

The program outputs 2;
Reprinted marked Source: http://blog.csdn.net/qq_33583069/article/details/50625502.

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.