Syntax format
1.1 Constants 1.1.1 Constants Overview
– The amount of value that cannot be changed during program execution
1.1.2 Constant classification
– string constants are enclosed in double quotes ("HelloWorld")
– Integer constant all integers (12,-23)
– Decimal constant All decimals (12.34)
– Character constants are enclosed in single quotes (' A ', ' a ', ' 0 ')
– Boolean constants are more specific, only true and false
– Null constant Null (part of the array explained)
1.1.3 Case Code Four:
/* Constant: The amount of the value that cannot be changed during program execution class: A: String constant "HelloWorld" B: integer constant 12,-23 C: decimal constant 12.34 D: Character constant ' a ', ' 0 ' E: Boolean constant true,false F: null constant Null (explained later) */public class Changliang { public static void Main (string[] args) {//String constant System.out.println ("HelloWorld"); Integer constant System.out.println (12); System.out.println (-23); Decimal constant System.out.println (12.34); Character constant System.out.println (' a '); System.out.println (' 0 '); Boolean constant System.out.println (true); System.out.println (FALSE); }}
1.1 Variable 1.1.1 Variable Overview
– In the course of a program execution, the amount of its value can change in a range
– essentially, a variable is actually a small area in memory
1.1.2 Variable Definition Format
– data type variable name = initialization value;
– Note: Format is fixed, remember format, Status Quo
1.1.3 variable plot
1.2 data type 1.2.1 Computer storage unit
variable is a small container in memory that is used to store data. So how does computer memory store data? Whether it is a memory or a hard disk, the smallest unit of information in a computer's storage device is called a bit, which we also call "bit", usually in lowercase letter B. The smallest storage unit of the computer is called "byte", usually denoted by a capital letter B, which consists of 8 consecutive bits.
In addition to the bytes there are some common storage units, we may be familiar with, we look at:
–1b (bytes) = 8bit
–1kb = 1024B
–1MB = 1024KB
–1GB = 1024MB
–1TB = 1024GB
1.2.2 Overview and classification of data types
A: Why is there a data type
The Java language is a strongly typed language that defines specific data types for each data and allocates different sizes of memory space in memory
classification of data types in B:java
Base data type
Reference data type
Object-oriented section explanation
1.3 identifier 1.3.1 Identifier Overview
A effect
– Give the package, class, method, variable, etc. name
B constituent rules
– by character, underscore _, Dollar sign $ composition
? The characters here are in the Unicode character set, so they include English case letters, Chinese characters, numeric characters, and so on.
– Considerations
– Cannot start with a number
– cannot be a keyword in Java
C: Naming principle: See the name of the meaning
a package
preferably the domain name upside down, require all the letters lowercase
Class B or interface
If it is a word with the first letter capitalized
If it is more than one word each word is capitalized (Hump identification)
C method or variable
If it is a word all lowercase
If it is more than one word, capitalize from the second word
D constant
If it is a word, all letters are capitalized
If you have more than one word, all the words are capitalized, and each word is distinguished by an underscore
1.3.2 Case Code five
/* Identifier: Is the name of the package, class, method, variable. Composition rule: A:unicode character numeric characters, English case, kanji (Chinese characters not recommended) B: Underscore _ C: Dollar sign $ note A: Cannot start with a number B: no Can be a keyword in Java common naming rules: A: Basic requirements See the name of the understanding B: Common Naming A: the package (in fact, is the folder for the management of the class) all lowercase, many Pack. Examples of separation: Com,com.itheima B: Class One Word capitalize example: Student,car Capitalize the first letter of each word in multiple words example: HelloWorld C: Methods and variables An example of a word first letter lowercase: Age,show () Multiple words start with the first letter of each word from the second word example: Maxage,getage () */public class Biaozhifu {public static void Main (string[] args) {//define variable//data type variable name = initialize value; int a = 10; correct int b2 = 20; Error//int 2b = 30; Cannot be a keyword in Java//error//int public = 40; }}
1.1 Defining variables 1.1.1 The definition and use of basic data type variables
Define the format of the variable:
Variable name of data type = initialization value;
Basic data type:
Byte,short,int,long,float,double,char,boolean
Attention:
integers are type int by default, and when you define a long type of data, you add l after the data.
Floating-point numbers are double by default, and when you define data of type float, you add f after the data.
1.1.2 Case Code VI
public class VariableDemo { public static void main(String[] args) { //定义byte类型的变量 byte b = 10; System.out.println(10); System.out.println(b); //定义short类型的变量 short s = 100; System.out.println(s); //定义int类型的变量 int i = 10000; System.out.println(i); //定义long类型的变量 long l = 1000000000000000L; System.out.println(l); //定义float类型的变量 float f = 12.34F; System.out.println(f); //定义double类型的变量 double d = 12.34; System.out.println(d); //定义char类型的变量 char c = ‘a‘; System.out.println(c); //定义boolean类型的变量 boolean bb = false; System.out.println(bb); }}
Considerations for 1.1.1 Variable Definitions
? The variable is not assigned to a value and cannot be used directly
– The second use format of the derivation variable
? A variable is valid only within the range to which it belongs.
– Where the variable is in curly braces, the variable belongs to the curly brace
? Multiple variables can be defined on a single line, but not recommended
1.1.2 Case Code VII
/* 变量定义注意事项: 1:变量未赋值,不能直接使用 2:变量只在它所属的范围内有效 变量属于它所在的那对大括号 3:一行上可以定义多个变量,但是不建议*/public class VariableDemo2 { public static void main(String[] args) { //定义变量 int a = 10; System.out.println(a); int b; b = 20; //变量在使用前赋值都是可以的 System.out.println(b); { int c = 100; System.out.println(c); } //System.out.println(c); /* int aa,bb,cc; aa = 10; bb = 20; cc = 30; */ /* int aa = 10; int bb = 20; int cc = 30; */ int aa=10,bb=20,cc=30; }}
1.1 Data-type conversions 1.1.1 Implicit data type conversions
A data type with a small range of values and a data type with a large range of values will first be promoted to a large, and then a small data type
1.1.2 Case Code Eight
/* +:是一个运算符,做加法运算的。 我们在做运算的时候,一般要求参与运算的数据类型必须一致。 类型转换: 隐式转换 强制转换 隐式转换 byte,short,char -- int -- long -- float -- double*/public class TypeCastDemo { public static void main(String[] args) { //直接输出了运算的结果 System.out.println(3 + 4); //定义两个int类型的变量 int a = 3; int b = 4; int c = a + b; System.out.println(c); //定义一个byte类型,定义一个int类型 byte bb = 2; int cc = 5; System.out.println(bb + cc); //我能不能不直接输出,用一个变量接受呢? //用变量接受,这个变量应该有类型 //可能损失精度 //byte dd = bb + cc; int dd = bb + cc; System.out.println(dd); }}
1.1.1 Forcing type data conversion
Format of the cast
Java Syntax format