A rule
1 Naming conventions
A: Class name capitalized, as far as possible to take the camel-named: Malin HelloWorld
B: Name Identifier specification: number, letter, underscore, $ composition, but cannot start with a number, cannot be a keyword or a reserved word. Example: 3max 3d goto
C: Variable name: First letter must be lowercase constant: must be all large PI MAX
D: Method Name: First letter must be lowercase
2 Strict case sensitivity
3 End with semicolon '; '
Two data types
A: Basic data type (eight types in four categories)
1. Simple Type
2. Package type (data type conversion simple Type)
Byte Short Integer Long Float Double Character Boolean
1. The base type can only be passed by value, and the encapsulated class corresponding to each base type is passed by reference.
2. In terms of performance, the basic type in Java is created on the stack, and all object types are created on the heap (the object's reference is created on the stack)
B: Reference type
1. Array 2. Class (Object) 3. Interface
Description
Machine language (binary language): composed of 1, 0. Example: 00000101
Minimum unit: bit bit 8bit = 1byte (Byte, character) ' a ' ~ ' Z ' a ' ~ ' z ' 0 ' ~ ' 9 ' special symbol a Chinese character = 2 bytes = 16 bit ' good '
1024byte = 1KB 1024KB = 1MB 1024MB = 1GB 1024GB = 1TB
Package: Essence Folder Directory
java.lang.* 1.java Default Import
java.util.*; 1. Tool class
java.sql.*; 1. Database
java.net.*; 1. Network programming
java.io.*; 1. Input and output stream
Guide Package shortcut key Ctrl+shift+o
package com.companyname.test;import java.util.Scanner;public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); }}
Three variables, constants
1 Syntax :
Data type variable name [= value];
char sex; //声明变量 sex = ‘男‘;//初始化、赋值 int age = 10; float score = 93.2F; int x,y,z=20;
Final data type variable name [= value]; final int x=1;
1. First declare 2. Initialize 3. Use
conversions between 2 types:
2.1--and large: automatic type conversion
short y = 1;System.out.println(y);double x = y;
SYSTEM.OUT.PRINTLN (x);-> small: Coercion type conversion
13;//13(int)-->小,到 System.out.println(score); int rs = (int)score; // 0.3截取丢失 System.out.println(rs);
Four string types
String in Java.lang.String
1. Must master: = =, equals () string comparison differences :
PublicClass Test1 {PublicStaticvoidMain (string[] args) {//String: Special Java class int num = 100; String name = "Jackson"; String address = "North Street West Gate ..."; String phone = "18182679850"; System. out.println (name+address); //string splicing System. out.println (3.14f+name); out.println ( "520" + "Zhang San"); String temp = "Jackson"; String str1 = new String ( "Jackson"); out.println (STR1);}}
2. Proficiency in Simple type string types
string.valueof (parameter) any type + ""
String Simple Type (package type: parsexxx ())
public class Test2 { public static void main(String[] args) { float num = 3.1f; String str = String.valueOf(num); System.out.println(str);//3.1(String) num = Float.parseFloat(str) ; }}
3. Mastering: Common functions in the string class
Frequent manipulation of strings: Do not recommend using the String class, but instead use StringBuilder & StringBuffer
Five operators
1 Arithmetic operators
Binocular: */% (take surplus, modulus) +-
Monocular: ++–
a prefix (num++;)
int num = 4; ++num; int rs = ++num*2; System.out.println(rs);//?
b suffix
int num = 4; int x = 3; num++;//5 int rs = num++ +x; //rs = 8 num=6 System.out.println(rs++);//? System.out.println(rs);
2 relational operators : True/false
< >= <= = = (constant equals)! =
Logical operators: True/false
! (reverse) && (short-circuit and) | | (Short circuit or)
int x=3,y=4,z=10;boolean rs = x>y&&++z>10;// true / falseSystem.out.println(z);
operator =
3 Assignment Operators
Assignment operator: =
Compound assignment operator: + = = *=/=%=
int x = 5;// x = x + 10; x+=10; System.out.println(x);
43 mesh Operator :
Exp1? EXP2:EXP3;
Exp1:true EXP2;
Exp1:false Exp3;
5-bit operators :
~ Non-| or & with ^ xor
Bitwise ~ Operator: 10100101=01011010
Bitwise & Operator: 1101&1010=1000
bitwise | operator: 1101 | 1010= 1111
Bitwise XOR Operator: 1101 ^ 1010 = 0111
6-bit shift operator
<< 3<<3=24 >>
On the premise that the number is not overflow, for positive and negative numbers, the left one is the equivalent of multiplying by 2 by 1, and the left shift n is the equivalent of multiplying by 2 of the n-th square
7 escape characters :
\ nthe line break
\ r Enter
\ t Horizontal Tabulation
\v Vertical Tabulation
\” “
\’ ‘
\ \
Java Basic syntax