The second day of basic Java learning

Source: Internet
Author: User

================ Daily must-read ====================

Write code:

1, clear demand. What needs do I need to fulfill?

2, analysis of ideas. How do I need to fulfill my needs?

3, determine the steps. What statements, methods, objects do I need to use for each part of my train of thought?

4, the code implementation. Use code to express my ideas.

PS: Watch every day, go forward every day ...

================ Daily must-read ====================

Package code.day01;

public class Demo {
public static void Main (string[] args) {
System.out.println ("http://www.cnblogs.com/xymxhs/");
}
}

Java Syntax Basics:

1, the keyword: a language has given special meaning words.

Reserved words: In fact, there is no special meaning, but prepare the words to be used later.

2, identifier: In fact, is a custom noun in the program.

Functions and Requirements:

0 for naming classes, methods, and variables, and for packages
0 consists of letters, numbers, "_" and "$" symbols
0 can only start with a letter, "_", "$" symbol, cannot start with a number
0 Case Sensitive
0 No length limit, no spaces
0 cannot use Java keywords and reserved words
0 Support Chinese (deprecated)

3, constants: The amount of the program can not be changed during operation.

0 normal constant (constant): true, False, 12, 43.35, "Hello!!!" ”
0 identifier constant (constant variable): Final keyword definition (later course learning)

4, variable: In fact, is a memory storage space, used to store constant data.

Function: Convenient for operation. Because some data is uncertain. So determine the noun and storage space for the data.
Features: Variable space can be reused.
When do I define a variable? As long as the data is uncertain, the variable is defined.

What are the necessary elements for the opening of variable spaces?
1) What data is stored in this space? The data type.
2) What is the name of this space? The variable name.
3) What is the first data for this space? The initialization value of the variable.

Scope and lifetime of variables:
Scope of the variable:
The scope starts at the position defined by the variable and ends with the curly brace where the variable is located;
Life cycle:
The variable is alive in memory starting at the defined position;
When a variable reaches its scope, it disappears in memory;

Data type:

Basic data type: There are 8 data types in Java that store numeric values, characters, and Booleans.

Integer types: integers are used to store integer values, that is, numeric values that do not have fractional parts. Can be a positive number, or it can be a negative number. There are 3 representations of integer data in Java programs, decimal, octal, and hexadecimal, respectively.
Integer data can be divided into 4 different types depending on the size of the content it occupies.

      

Floating-point types:

      

Character type: The character type is used to store a single character, occupying 16 bits (two bytes) of memory space. When you define a character variable, you want to indicate it in single quotation marks. Use the Char keyword to define a character variable.

      

Boolean type: Boolean type is also called logical type, the boolean type variable is defined by the keyword Boolean, only true and false two values, respectively, represent "true" and "false" in Boolean logic. Boolean types are often used in process control as a condition of judgement.

Type conversions (basic types): Conversions of data types, divided into automatic conversions and casts. Automatic conversion is a program in the execution of the "quietly" conversion, do not require the user to declare in advance, generally from a low number of bits of the type to a high number of bits conversion; Coercion type conversions must be declared in code and the order of conversion is not restricted.

Automatic type conversion:

Automatic conversions are converted in order from low to high. The priority relationships between different types of data are as follows:
Low---------------------------------------------> High
byte,short,char-> int, long, float---double

Operations, different types of data are converted to the same type first, then the operation, the conversion rules are as follows:

      

To force type conversions:

The format of the cast is to add "()" before the data that needs to be transformed, and then add the data type that needs to be converted in parentheses. Some data after transformation operation, the accuracy will be lost, and some will be more accurate, the following example can illustrate this problem.

    

Running Result: x=45

y=56.0

Analysis: Because coercion of type conversions results in a change in precision.

Java operators:

Operator: is a combination of a single character and multiple characters used to perform the calculation.

Expression: A sequence of variables, constants, operators, method calls that perform the specified calculation and return a certain value. Unary operators: + +,--, + (take positive),-(negative)

Mathematical operator: A mathematical operation that results in a numeric value.

    

Relational operators: Relational operators, which result in a Boolean value.

    

Bitwise operator: The bitwise operator makes a bitwise logical operation on the binary form of an integer, resulting in an integer.

    

Conditional operator (Trinocular operation):

Example: Double c = a > B? 1:2;

If a=8,b=7, the result is c=1;

If a=8,b=9, the result is c=2.0;

Examples of operators:

    

Operation Result:
After self-add a=10
The value of a a=11
Former self-add b=11
==============
Ask X>y, right? False
Think X>y and X<y, right? False
Think X>=y or x==y, right? False
Think X<y or x=z, right? True
==============
The result of the a&x is: 10
The result of the a|x is: 11
The result of the y^z is: 31
==============
A 2-bit left shift result is: 44
The result of the right shift of Y 3 bits is: 2

The second day of basic Java learning

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.