A summary collation of the data types and operators in Java.

Source: Internet
Author: User

First of all to learn Java must first understand the history of Java, as well as the characteristics of Java, Common DOS commands, JDK installation, how to develop Java programs and so on the concept of the line of things, which I do not say.

In this chapter, I want to summarize the data types and operators in Java in 2 major aspects.

Say the name of the identifier before the data type:

General naming rules: see the name. If there are multiple words, the first word is lowercase, and the other words are capitalized (hump-named).
1. The first letter can only be letters, underscores and $
2. The remaining letters can be letters, underscores, $ and numbers
3. Cannot use reserved keywords
4. Strictly case-sensitive (as in general, C voice)

The data types in Java are divided into 2 major areas: basic data types and reference data types.

The basic data types are divided into: shaping, floating point, character type, Boolean type.

There are 4 types of shaping: Byte (1 bytes) short (2 bytes) int (4 bytes) long (8 bytes);

Floating-point 2 kinds: double (8 bytes) float (4 bytes);

1 Types of characters: char (Unicode code);

1 Types of Boolean: Boolean (1-bit);

There are 3 types of reference data: Class, interface, and array. (see this for a moment).

Then there is the basic concepts and declarations of variables and constants:

Variable: A variable is a representation of a memory space that can be used to store data and can be re-assigned during a run.

Declaration: A variable must first be declared, then assigned, and then used. Syntax: Data type variable name [= value];eg:

int age;
age=10;
Declaration to assignment one step completion
int age=10;
You can also declare multiple variables of the same type at once
int a,b,c;


Constants: A program cannot be re-assigned to it while it is running, and a variable with a final decoration in Java is a constant.

Naming conventions for constants: Use uppercase letters, if there are multiple words, in the middle use _ Connect.

Final double pi=3.14; final int max_value=10;
Scanner (similar to scanf in C language)

Except for classes that are under the Java.lang package, the class under the other package needs to be guided when it is used without a guide package.

The Java.util.Scanner class allows you to get the content entered by the user.
Steps to use:
1. Import the package by importing a key, and the import statement is placed above the declaration of the class (the first line statement);
Import Java.util.Scanner;
2. Create a Scanner object
Class Name Object name = new class name (parameter);
Scanner Scanner = new Scanner (system.in);
3. Get user input using the scanner method
The name of the object. Method Name ();
Scanner.nextint ()---> Gets the value of the type int entered by the user
Scanner.nextfloat ()---> Gets the value of the float type entered by the user
Scanner.nextdouble ()---> Gets the value of the double type entered by the user
Scanner.next ()---> Gets the value of the string type entered by the user
Scanner.nextlong ()---> Gets the value of a long type entered by the user
.....

Operators: Arithmetic operators, assignment operators, logical operators, relational operators, and bitwise operators.

Arithmetic operator: +-*/% (for redundancy) + +-;

Assignment operator: = compound assignment operator: +=,-+,*=,/=.%=;

Logical operators: Logic with &, logic or |, logic xor ^, short circuit with &&, short circuit or | |, non! (Logic and &, logic or | and short circuit with &&, short circuit or | | Difference, the former condition all judgment only give the result the latter as long as one condition is not satisfied on the result)

Bitwise operator: ~: Inverse (if bit is 0, the result is 1, if bit is 1, the result is 0,)

^: XOR (two bits of the operand, same result is 0, different result is 1)

&: With the nth bit of the first operand in the second operand if all is 1, then the result of Nth is also 1, otherwise 0)

|: or (two bits as long as one is 1, then the result is 1, otherwise 0,)

<< left Shift: Move left 1 bits equal to 2 >> right Shift: Shift right 1 is equal to divide by 2

The end is type conversions:
Automatic conversion: Small range can be converted to a large range of byte--->short--->int--->long--->float--->double
Cast: It is possible to lose precision or even the distortion (data type) expression or value of the data;





A summary collation of the data types and operators in Java.

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.