First, the Java Language Foundation (2) _ Types and operations--literals and constants

Source: Internet
Author: User

2018-04-11

Variables and constants

One, constant

  1. Concept

      fixed constant values in the program

2. Classification

   1) Literal constants

A direct quantity that represents a direct given value (which can be integers, decimals, ture, false, and so on)

For example: integer value constant, 3.14, 2.25, Boolean constant Ture,false, etc.

   2) Final modified variables

Second, the variable

1. Concept

Represents a storage space used to hold constants of a certain type, with no fixed value, can be reused, or can be used to store unknown data of some kind

2. Features

        • Occupy a piece of an area in memory
        • The zone has its own name (variable name) and type (data type)
        • can be reused
        • Data in this region can be constantly changed in the same type  

3 . Defining Variables

1) syntax

Data type variable name

such as: int age;

2) assigning values to variables (initializing)  

Variable name = constant value of the declared variable type

Age = 17;

You can also initialize variables when declaring variables: int age = 18;

  Note: variables must be initialized (assigned) before they can be used, and initialization is the true memory allocation.

Iii. Classification of variables-scope-usage rules

  1. Classification of variables

    Variables fall into two categories depending on the location of the definition

     1) member variables/fields: variables directly defined in the class {} (outside the method)

2) Environment variables: variables other than member variables, variables defined in the method

  Note: variable access is the nearest principle

  2. Scope of variables: areas that can work

1) member variable/field: function in the defined class

2) Environment variables: From the definition of the place to the close immediately after the end of the

Iv. Java expressions

  

First, the Java Language Foundation (2) _ Types and operations--literals and constants

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.