Java Day 02

Source: Internet
Author: User
Tags arithmetic arithmetic operators

Key words
All lowercase, with the first letter of the class name capitalized

Identifier
1, the number can not start
2, can not use keywords
Case sensitive
26 uppercase and lowercase letters, 0-9, _, $ composition
Is main the key word?

Comments
Single-line comment//
Multiline Comment/* */
Document Comments/** */extracted by Javadoc
You can locate the problem by commenting the debugger
At compile time, comments are not compiled, which is the same size as the class file generated by the comment.

Application of annotations
1. Annotations
2. Commissioning
3, the key to the interview
Code is only part of the idea.
/*
Requirement: Practice a Hello World program.

Ideas:
1. Define a class
2, define a main function, in order to let the class can run independently
3, see in the console, need to output the statement

Steps:
1, using the class keyword to complete the definition of classes, a strong reading class name
2. The main function fixed format JVM can recognize
3. Using OUTPUT statements
*/

Constant
Integer, Decimal, Boolean, character, string, null

In-process
Binary
Octal 0 Start
Decimal
Hex 0x Start
1 byte = 8 bit

Binary conversion

Binary with negative numbers
An integer of 4 bytes
Positive + negative = 0 Any negative number, the binary highest bit is 1

Variable
Strongly typed languages
Basic data type numeric (integer (Byte, short, int, long), decimal (float, double)) character type (char) Boolean (Boolean)

Variable definition
Long declaration followed by L
Float declaration after adding F
Scope of the variable

Automatic type Promotion & forced type conversion
byte + int = int
byte B = 3;
b = (byte) (b + 4);//easy to lose precision

Character type operations
int + char = int//ascii
Unicode

Type operation details
byte B = 4; 4 is int, cast
b = 3+7; That's right

BYTE b1=3;
BYTE b2=4;
b = b1+b2; Error byte + byte = int
B1, B2 is a variable that cannot be judged in the byte range and is assigned a value

int x;
int x1=10;
int x2=integer.max_value;
x = x1+x2;

Arithmetic operators
Arithmetic operator: +-*/% (remainder, modulo operation) + (connector)
int x = 6370
x = x/1000 * 1000//6000
-------
6
--------
6000
-5%2//-1
5%-1//1
string + int = string

Arithmetic operator II & assignment operator
++ --
int a =3,b;
B=a++;//a=4,b=3
B=++a;//a=4,b=4

= += -= *= /= %=
Short S = 3;
s + = 4; Automatic type conversion
s = s + 4; short + int = int

Java Day 02

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.