Java Learning notes: Variables for Java

Source: Internet
Author: User

First, Introduction

In the Java language, all variables must be declared before they are used. The basic format for declaring variables is as follows:

Type identifier [= value][, identifier [= value] ...];

Format Description: Type is a Java data type. Identifier is the variable name. You can declare multiple variables of the same type by separating them with commas.

The following is a list of the declaration instances for some variables. Note that some of the initialization procedures are included.

int A, b, C;         // declares three integers of type int: A, B, C int // declares three integers and assigns an initial value byte z =;         // declaring and Initializing Z string s = "Runoob"  //  declares and initializes the string sdouble//  declares a dual-precision floating-point variable pi char x = ' x ';        // the value of the declared variable x is the character ' X '. 
Second, notes
 PackageCom.hgd.study;/*** variable *@authorHutiger **/ Public classVariables { Public Static voidMain (string[] args) {inta=30;//"A" is the variable "30" is the literal value "=" is the assignment "int" Data type shaping        intB=20; System.out.print (A+B);//and theSystem.out.print (A*B);//Product//---------------------------------        //defining rules for variables        /** 1. Variable name must not be $ _ or the beginning of the letter, you can make $ _ number or character * 2. Variable name suggested first letter lowercase * 3. Variable name cannot use keyword * 4. For multiple English word variables Using the Hump naming method * 5. Variable names not recommended for use in Chinese*/String UserName= "Admin";//String class = "" Error definition    }}

Java Learning notes: Variables for Java

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.