Java Learning Note 01

Source: Internet
Author: User


Java Basic article


Basis in the foundation



First, build the development environment: Set the PATH variable * * (x:\...\bin;) * and Classpath variable * * (.;) * *,. Represents the current directory.


Second, the code of the first sentence: public static void Main (String args[]) {}. The main () method, which is the program entry.


Third, about the comment:

Single-line Comment

/*...*/Multi-line comments

/**...*/Document Comments



Variable


The basic data types of Java are 4 classes and 8 kinds:

Integer type: Byte,short,int,long

Floating point type: float,double

Boolean Type: Boolean

Character type: Char


Second, the range of byte is (-128 to 127), int is probably positive or negative 2e10,long close to the positive and negative 1e20,double range of the largest, float is generally enough. The Boolean can only be true or false.


The scope of the variable is only in the curly brace that declares the variable, that is, the light is dead.


Variables can be divided into local variables and member variables .

Local Variables : variables defined inside a method are called local variables, which can only be used inside the method, and no one knows the method. Modifiers for local variables can only be final, and others are illegal.

member variable : A variable defined inside a class is a member variable.

The system does not automatically assign initial values to local variables, but for member variables, the system automatically assigns initial values. The value of the base type is 0, and the value of the composite type is null.

The life cycle of a local variable is the same as the execution period of the method. When a method executes to a statement that defines a local variable, the local variable is created, and the local variable is destroyed when it executes to the last statement in the scope where it is located. A member variable of a class that, if it is an instance member variable, has the same lifetime as the object. The lifetime of a static member variable is the entire program's run-time.

In different methods, local variables of the same name can be used, and they do not interfere with each other. Local variables can have the same name as member variables, and when used, local variables have higher precedence.


Memory

(Understanding memory will understand everything!) ):

The memory is divided into 4 parts: code segment,data segment,stack,heap.

* Code segment: Store codes.

* Data segment: Static variables and string constants that hold the static keyword declaration.

* Stack: Declare the variable to hold the address of the object in the heap, after the execution of the method is not known when it was recycled oh.

* Heap:new out of the objects are put here.

Java Learning Note 01

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.