tags: Computer common base and conversion between bases Commonly used computer codes java
1. Learning of basic concepts
1. Comments
2. Keywords
3. Identifier
Second, the constant
Three, variables
Knowledge of variables
Data type
Fourth, the operator
Arithmetic operator
Comparison operator
Assignment operator
Logical operator
Ternary operator
Shift operator
Overview: This is the content format for explaining the code we wrote. He didn't write it for computers. He wrote it for our programmers.
Features:
1. The format and content of the comment will not be compiled when compiling
2. The content will not be run when running
classification:
Single-line comment: [//] write what we want to explain after the symbol
Features:
1. No line breaks
2, can be applied
Multi-line comment: [/* */] write our explanation in the middle of the asterisk
Document comment: [/** */] Write our comment between the second asterisk and the last asterisk
Features:
1, can wrap
2. Not applicable
Combined with fixed annotations to generate corresponding help documents
Code example:
package com.ujiuye.demo;
/*Write an introductory case/*The example reaches the output on the console
* "Jinlian has an idea, so Da Lang is out of luck"*/
public class Demo01 {
/** Implement the console in the main method
* Output/**Content effect*/
public static void main(String[] args) {
//Output a sentence on the console: "Jinlian has an idea,//So Da Lang is out of luck"
System.out.println("Jinlian had an idea, so Da Lang was unlucky");
}
}
Overview: In Java, there are some words that have been defined and given special meanings.
There are 50 such words in java.
[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-5QKymJGG-1593604994270) (E:\Employment Class\java97 Class (Beijing)\day02\Notes\Keywords. png)]
Features:
1. All letters of the word are lowercase
2. Keywords cannot be used as identifiers
Reserved keywords: [Interview Questions]
const goto is a reserved keyword for Java. Even these two words are not used in the Java language, and the words have no special meaning. I don't know if I will use it in the future.
Overview: The identifier is the name. In Java, it is used to name a series of content such as classes, variables, constants, enumerations, interfaces, etc. This content is called an identifier.
Composition content:
1. All English letters including upper and lower case [52 English letters]
2, 0-9 Arabic numerals
3. English symbols _ and $
4. Characters in languages of other countries [not commonly used]
Precautions for use:
1. Numbers cannot start
2. Cannot be a keyword
3. Do not have spaces in the identifier
General rules: to be known by name
Class name and interface name, enumeration name: the first letter of the identifier should be capitalized, and all other letters should be lowercase
1. The identifier is a word, only the first letter needs to be capitalized and the other letters are lowercase
2. The identifier is a combination of multiple words, the first letter of each word needs to be capitalized, and all other letters are small
Write
Such a rule is called: big camel case format
For example: HelloWorld Person
Variable name, method name: the first word of the identifier is all lowercase, the first letter of the following word is capitalized, and the other letters are small
Write
1. The identifier is a word: all lowercase
2. The identifier is a combination of multiple words: the first word is all lowercase, and the first letter of the following word should be uppercase
Other lowercase letters
Such format: small camel case format
For example: age [age] getSum
Constant: All words and letters must be capitalized, if it is more than one word, use _ to separate words and words
For example: AGE_MAX PI E
Package name:
Package: In fact, it is the folder used to manage the written code uniformly, which is passed as the address by the compiler
Features: can have levels
Naming rules:
1. All package names are generally composed of one word and all lowercase
2. The package name can be layered, and each package is separated by.
3. The first two layers of all hierarchical packages are the reverse of the company's domain name. [Guaranteed that the package name is unique]
Overview: The value that does not change in any way during the running of the java code is called a constant.
Constants cannot exist alone in java, they must be combined with other operations [generally combined with output statements and assignment operations or logical operations and other operations]
classification:
1. Divided into the form of expression:
Literal constant: You can know the specific value when you see the quantity, including all numbers and all strings
For example: 1 "I am not Pan Jinlian"
Symbolic constant: When you see a specific symbol, you know that it represents a specific value. For example: Erli 30 ancient rare 70 pi [PI: 3.14159265358] natural number [E: 2.718]
2. Divided according to the data type
Basic data type constants:
Integer constant: all integers
Decimal constant: all decimals
Character constant: the amount of a single character surrounded by English symbol single quotes such as: ‘a’ ‘Chinese’
There must be one and only one character in the single quotation mark
Boolean constant: Indicates the amount of right or wrong There are only two values: true false
Reference data type constants:
String constant: a sequence of characters wrapped in double quotes with English symbols such as: "Wuhan, come on"
Empty constant: only one value null can not be output, the meaning of an empty constant means nothing
You can't actively use it to do things, you can only passively assign it to other elements [variables]
Code example
package com.ujiuye.demo;
public class Demo02 {
public static void main(String[] args) {
//Constant writing
//100 constants are written separately in java code to report errors. Constants cannot be used alone
//Use in combination with output statements
//Literal constant
System.out.println(100);
//Symbolic constant PI
System.out.println(Math.PI);//3.1415926
//Basic data type constant
System.out.println(500);
System.out.println(13.14);
System.out.println('a');
System.out.println(true);
System.out.println(false);
//Reference data type constant
System.out.println("Come on Wuhan, Wuhan will win");
//System.out.println(null);
}
}
Overview: The amount that the value of the java code changes during the running process is called a variable.
Understanding: Variables are the containers used to store constants in java. They can be stored at different time periods during operation.
The same constant value, so its value will change. Note: Only one constant value can be stored in a variable at a time.
1. Variable declaration: only to define the variable, but no constant value for the variable
Format: data type variable name;
Features: Variables can only be used after they have stored values.
2. Variable declaration and assignment: define the variable and put the constant value in the variable at the same time
Format: data type variable name = constant value;
Code example
package com.ujiuye.demo;
public class Demo03 {
public static void main(String[] args) {
//Declare variables
int age ;
//The process of assignment
age = 18;
System.out.println(age);
//Declaration and assignment
int salary = 20000;
System.out.println(salary);
}
}
The embodiment of variables in memory [jvm memory]:
Jvm memory division [data area division during jvm runtime]:
1. Register: store the instruction address of the execution program [basically the system manages us and we don’t have to worry about it]
2. Local method stack: resources that serve to execute local methods [managed by the system]
3. Stack memory: the area where the relevant information of the java method is loaded and the method is executed
4. Heap memory: load related information of the class object
5. Method area: load related information, static information, constant pool and other information
Overview: The basis for determining the size of the memory space for storing variables when defining variables. Data types are used to modify variables.
Category:
Basic data types
Four categories:
Integer type:
byte: The space occupied in the memory is 1 byte
Stored data range: -128 to 127
short: It occupies 2 bytes in memory
Range of data stored: -215 to 215-1
int: The space occupied in memory is 4 bytes
Range of data stored: -231 to 231-1
long: The space occupied in memory is 8 bytes
Range of data stored: -263 to 263-1
Floating point type:
float [single precision]: the space occupied by the memory is 4 bytes [more than the integer type
8 bytes are big]
double[double precision]: occupies 8 bytes in memory [IEEE754]
Note: The standard adopted by the floating-point type is that the IEEE754 standard is larger than the standard for the integer type.
Character type:
char: occupies space in memory is 2 bytes [standard and integer type standard
is the same, char and short occupy the same space]
Boolean type:
boolean: Occupy space in memory is unknown, only true and false can be stored
Reference data type:
Class, array, interface
Code example
package com.ujiuye.demo;
public class Demo04 {
public static void main(String[] args) {
//Use basic data types to define corresponding variables
//Integer type
byte a = 123;
//a = 128; can't put it in 128 is beyond the range of byte storage
System.out.println(a);//123
short s = 1024;
System.out.println(s);//1024
int i = 100000;
System.out.println(i);//100000
long l = 123L;
System.out.println(l);//123
long l2 = 123456789340L;//When assigning a long type variable, it is recommended that you add L to the number
System.out.println(l2);//123456789340
//floating point
float f = 3.14F;
System.out.println(f);//3.14
double d = 32.109;
System.out.println(d);//32.109
//Character type
char c = 'a';
System.out.println(c);//a
//Boolean type
boolean boo = true;
boolean boo1 = false;
System.out.println(boo);//true
System.out.println(boo1);//false
//String variable
String ss ="Come on Wuhan";
System.out.println(ss);//Come on, Wuhan
}
}
Sorting of basic data types: byte<short=char<int<long<float<double
The default data type of integer constants in operation is: int [details attention]
The default data type of the decimal constant in operation is: double [Note for details]
Reference data type
String: String belongs to the class,
Overview: Computer storage resources are stored using numbers. And most of our resources are composed of characters. If you want to store characters, try to program the characters one by one to store them.
Encoding: Convert characters to corresponding numbers, this process is called encoding
Decoding: The process of converting numbers into corresponding characters is called decoding
ASCII table: a collated table of all characters and corresponding numbers in English
The number corresponding to A that needs to be remembered in the ASCII table 65 The number corresponding to a is 97 Character 0 corresponds to the number 48
Related mathematical operations can be performed directly when character constants and character variables are used.
Coding table
Universal Code: Unicode code table
utf-8: It is a kind of Unicode code table, and he is also a kind of code that programmers prefer to use.
English occupies 1 byte in this code table, Chinese occupies 3 bytes in this code table.
gbk: Domestic systems prefer to use this coding table.
English occupies 1 byte in this code table, Chinese occupies 2 bytes in this code table
Code example:
package com.ujiuye.demo;
public class Demo05 {
public static void main(String[] args) {
//Characters become numbers
int a = 'a';
System.out.println(a);//97
//Numbers become characters
char c = 48;
char cc = 100;
System.out.println(c);
System.out.println(cc);//d
}
}
The range of commonly used data types [from small to large]
byte -> short -> char -> int -> long -> float -> double
Conversion classification:
From small to large: Put the constant value of the small data type into the large data type variable
From big to small: Put the constant value of the big data type into the small data type variable
Small type to large type: long l = 1234;
Large type to small type: short b = 128; the wrong aspect does not go in
Format: small data type variable name = (small data type) large data type constant value
Also called the forced conversion of data.
Note: There is a risk of data loss due to forced conversion. Under normal circumstances, do not easily force conversion.
Code example
package com.ujiuye.demo;
public class Demo06 {
public static void main(String[] args) {
//Small to large
long l = 1234;
System.out.println(l);//1234 The value has not changed, and the occupied space in the memory has become larger
//Big to small[Data type coercion]
short s =(short)1234L;
System.out.println(s);// The value of 1234 has not changed but the space in the memory has become smaller.
short ss = (short)3.14;
System.out.println(ss);//3 The value will change, and at the same time the internal space occupation will become smaller
}
}
Precautions: 1. Strictly case sensitive 2. English model semicolon 1. Note: 1.1 What is a comment? The text used to explain the program. 1.2 Comments in Java SVN/Git - Source Code Manager 2. Keywords ...
I. Objects and classes Final final class, abstract abstract class, final and abstract are mutually exclusive. Final defines a constant. This constant must be initialized (initialization details:How to...
Java Web basic knowledge The following is an introduction to the basic knowledge of the Java web. Some language usages included with the Java web Here are some basic tag usage and implementation featu...
A. How to create a thread 1.1 inherits the Thread class Rewrite the run() method. 1.2 implement Runnable interface 2 threads of 5 states New When creating a thread object with the new operator, such a...
More detailed Java interview pleaseclick here Java basic knowledge points Java keywords and features Familiar with the spelling and function of common Java keywords All Java keywords are lowercase Got...
type of data Basic data type Integer Byte: 1 byte Short: 2 bytes Int: 4 bytes (default type) Long: 8 bytes Floating point Float: 4 bytes Double: 8 bytes (default type) Character Char: 2 bytes Boolean ...
(Reprinted) Modified on the teacher's blog. 1. What are the aspects of object-oriented features? 1.1 Abstraction: Focus only on the properties and behavior of objects, and not on the details of these ...
1, the composition of Java Java language cross-platform principle: to achieve cross-platform virtual machine JVM that depends on Java JRE: Java runtime environment, including the core class libraries ...
What is the basic knowledge of java? XiaofengBackend technology selection 2018-05-16 Poke aboveBlue wordFollow us! Recently, many people invited me to answer the basic questions of various j2ee d...