Java Learning the next day

Source: Internet
Author: User

Key words

Keywords: words that are given a specific meaning by the Java language.

Keywords feature: The letters that make up the keywords are all lowercase.

Caveats: 1.goto and const exist as reserved words and are not currently used. 2. Advanced Notepad encountered keywords will change color, very intuitive display.

Identifier

Identifier: A sequence of characters to use when giving seven names such as classes, interfaces, methods, variables, and so on.

Composition rules: English uppercase and lowercase letters, numeric characters, $ and _

Note: You cannot start with a number, cannot be a keyword in Java, is strictly case-sensitive, cannot have spaces

Identifiers (common naming conventions): See Names and know

Package: is actually a folder, used to distinguish the same class name (all the names are lowercase)

Single-stage package: ZhuZhu

Multi-level package: Cn.itcast

Class or interface:

One word: The first letter of a word must be capitalized

Example: Student,dog

Multiple words: The first letter of each word must be capitalized

Example: Studentscore

method or Variable:

One word: The first letter of the word lowercase

Example: Main (), age

Multiple words: Starting with the second word, capitalize the first letter of each word

Example: Studentage,showallnames ()

Constant:

One word: all caps

Example: PI

Multiple words: Each letter is capitalized, separated by _

Example: Student_max_age

Comments

Note: Used to explain the text of the program, improve the reading of the program, to help us debug the program (can be commented to check whether the other program is correct)

Comment Classification format in Java:

Single-line Comment://Note text can be nested

Multiline Comment:/* Comment text */cannot be nested, start with/*/End With/*

Document comments:/** Note Text * * by Javadoc tool parsing generates a manual, object-oriented part of the explanation

Constants and variables

Constants Overview : The value cannot be changed during program execution

Java constants Category: literal constants and custom constants

literal constants:

             a: String constants:   "Hello"   "world", enclosed in double quotes

             B: integer constant: all integers

             C: Decimal constants: All decimals

             D: Character constants:   ' A '   ' B '

enclosed in single quotes

             e: Boolean Constants

                    Example: True,false

             f: Empty constants    null   later narration

integer constant of the binary
1byte bytes =8bit
1k=8byte
1m=1024k
1g=1024m
1t=1024g
Binary: 0b start octal: 0 start decimal: Default hexadecimal: 0x starts with

conversion
(1) Other decimal
factor: the value on each bit

right: the data on each digit, from the right, and numbering starting from 0, the corresponding number is the right to the data.
result: the sum of the coefficient * cardinality ^ weights of the powers .
(2) decimal to other binary
In addition to the base, Until the quotient is 0, the remainder is reversed.
(3) Fast conversion method for binary conversion
a: Conversion between decimal and binary
8421 yards. (One of the BCD codes)
b: Binary to octal, hexadecimal conversion, split-group legal, octal three-bit, hexadecimal four-bit

Symbolic data representation: original code, anti-code, complement

When the computer is operating, it is calculated by using the binary complement of the data corresponding

Example: Using the original code, anti-code, complement to represent +7 and 7 respectively

First, convert to binary: 00000111

Original code: Symbol bit + value bit, where the highest 0 is a positive number, 1 means negative

+7:0 000111

-7:1 000111

Anti-code: The inverse code of positive number is the same as the original code, negative number of the inverse code is to its original code bitwise negation, except the sign bit

+7:0 000111

-7:1 111000

Complement: The complement of positive is the same as the original code, the complement of negative number is on the basis of anti-code plus 1

+7:0 000111

-7:1 111001

Variable Overview: The amount of its value changing within a certain range during program execution

Composition rule:

A: It must be qualified (data type)

B: Allocate A memory space, we give this space a name that is the variable name

C: Initialize Value

Define variable format: Data type variable name = initialization value;

Data type

The Java language is a strongly typed language that defines specific data types for each type of data, and allocates a different size of memory space in memory

Classification:

A: Basic Data type: 4 classes of 8
B: Reference data type: Class, interface, array.

Basic data types
A: integer consumption of bytes

BYTE 1
Short 2
int 4
Long 8
B: Floating point
Float 4
Double 8
C: Character
Char 2
D: Boolean
Boolean 1
Attention:
integers are type int by default, and floating-point numbers are double by default.

Long integers to be added L or L.
Single-precision floating-point numbers are added F or f.


Considerations for Using Variables:
A: Scope
B: Initialize Value
C: Multiple variables can be defined on the same line, but not recommended

Data type conversions:

(1) Boolean type does not participate in conversions


(2) Default conversion
A: From small to large
B:Byte,short,char--INT--long--float--double
C:Byte,short,char do not convert to each other, directly into the int type participates in the operation.

byte a=1;
int b=2;
BYTE C=a+b; Error
int d=a+b; That's right

(3) Forced conversion
A: from big to small
B: There may be a loss of precision, it is generally not recommended

byte a=1;
int b=2;
byte c= (Byte) (A+B); That's right
C: Format:
Target data type variable name = (target data type) (converted data);


(4) Study Questions and interview questions:
A: Are there any differences in the following two ways?
float f1 = 12.345f; It was originally a float type.
float F2 = (float) 12.345; Originally a double type, forced to convert to float type
B: Is there a problem with the program below, and if so, where?
BYTE B1 = 3;
byte b2 = 4;
BYTE B3 = b1 + b2; problems, type promotion B1 and B2 participation calculations are converted directly to int type,
byte B4 = 3 + 4; No problem, constants first calculate the results, and then see if in the byte range class, if there is no error
C: What is the result of the following operation?
byte B = (byte) 130;

130 exceeds the range of byte ( -128~127)
Because computer computing is done with binary complement, we first put 130 into binary: 10000010
The original code of the positive number of the reverse code is the same: the 10000010,int type of 130 is originally 32 bits, when intercepted as a byte type, 8 bits, the highest bit is 1
After that, the complement: 10000010 into the inverse code: 10000001, and then converted to the original code is: 11111110, the decimal value is 126

D: Character participation operation
is to find the value inside the ASCII
' A ' 97
' A ' 65
' 0 ' 48

System.out.println (' a '); Result A
System.out.println (' a ' + 1); Results 98
System.out.println ("Hello" + ' a ' + 1);//result helloa1, string data and other data do +, the result is a string type , where the + is the connector
System.out.println (' A ' +1+ "hello");//Result 98hello, first calculate + method, then concatenate string

Array of operator statement functions

Java Learning the next day

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.