main Method shortcut :psvm
Output shortcut :sout

Hello World! ceremony
public class demo01 { public static void main(String[] args) { System.out.
println("Hello World!"); System.out.println(" Hello , world !"); } }

Java of main method

Here we learned the naming convention , as well as Java in main Method writing
public class demo01 { public static void main(String[] args) { /* // Case sensitive
String a ="zhouql"; String A ="zhouql"; // standard String 1a ="zhouql"; String Av
="zhouql"; String $ ="zhouql"; String $1 ="zhouql"; String _ ="zhouql"; String
_1 ="zhouql"; String 1_ ="zhouql"; String -asd ="zhouql"; // Keywords cannot be used as variable or method names
String clas ="zhouql"; String class ="zhouql"; */ } }
Basic data type
package base; public class demo02 { public static void main(String[] args) {
// Eight basic data types // integer int num1 = 10; // Most commonly used // Range in 100 many // byte num2 = 200; //short short
num3= 20; //long long num4 = 40L; //Long Type add an after the number L Say yes long type //float Floating point number : decimal
float num5 = 12.3F; //float Type plus F, Otherwise, an error will be reported double num6 = 3.14159; // character char name1 =
'a'; // char name2 = 'as'; // Character is a // character string //String Not a keyword , Is a class String num7 = "asd"
; // Boolean value boolean flag = true; // really boolean fla = false; // false } }
Cast and escape
public class demo03 { public static void main(String[] args) { int i=10; int i1
=010;//ba jin zhi int i2=0x10;//shi liu jin zhi System.out.println(i); System.
out.println(i1); System.out.println(i2); System.out.println(
"==================================================="); float f=0.1f; double d=
1.0/10; System.out.println(f==d); System.out.println(f); System.out.println(d);
System.out.println("==================================================="); float
a=231313123123123189f; float b=a+1; System.out.println(a==b); System.out.
println("===================================================="); char c1='a';
System.out.println(" Force conversion "); System.out.println((int)c1); System.out.println((int
)'A'); System.out.println("===================================================="
); System.out.println(" Escape character "); System.out.println("Hello\tWorld!"); System.out.
println("Hello\nWorld!"); } }

New features
public class demo06 { public static void main(String[] args) { //JDK New features , Easy to see int
money= 10_0000_0000; System.out.println(money); int years = 20; System.out.
println(money*years); System.out.println("-----------------------------"); long
sum= money*((long)years); System.out.println(sum); } }
Recognition of naming
public class demo07 { //static It's a modifier , Do not distinguish between before and after //final It can only be read and cannot be modified , What cannot be changed is defined as a constant static
final double PI = 3.1415926; public static void main(String[] args) { System.out
.println(PI); } } // Naming conventions /* * 1, See the meaning of name * 2, Class member variable hump principle * 3, Local variable initial lowercase and hump principle *
4, Constant uppercase and underscore * 5, Class name initial capital and hump * 6, Method name initial lowercase and hump * */
Class variable , local variable , Instance variable
package base; public class demo08 { // Class variable static static double salary = 20000;
// Instance variable : Subordinate object // Instance variable , Not initialized , Default value , Except for basic types , Everything else null, Boolean default is false String name; int age;
//main method public static void main(String[] args) { // local variable ; Must declare and initialize values int i = 10;
System.out.println(i); // Variable type Variable name Variable value demo08 demo08 = new demo08(); System.out.
println( demo08.age); System.out.println( demo08.name); // Class variable static System.out.
println(salary); } // Other methods public void add(){ System.out.println(); } }
Operator part

add , subtract , multiply and divide
public class Demo01 { public static void main(String[] args) { // Binary operator int a =
10; int b = 20; int c = 30; int d = 10; System.out.println(a+b); System.out.
println(a-b); System.out.println(a*b); System.out.println(a/(double)b); } }
public class Demo02 { public static void main(String[] args) { long a =
12345678L; int b = 123; short c = 10; byte d = 2; System.out.println(a+b+c+d);
//long System.out.println(b+c+d);//int System.out.println(c+d);//int } }
Modular operation ( Key experience )
public class Demo03 { public static void main(String[] args) { // relationship int a = 10;
int b = 20; int c = 21; // Surplus shu, Modular operation System.out.println(c/b); System.out.println(
a>b); System.out.println(a<b); System.out.println(a==b); System.out.println(a!=b
); } }
Self increasing and self decreasing
public class Demo04 { public static void main(String[] args) { // Unary operator ++ Self increasing
-- Self subtraction int a = 3; int b =a++;// After executing this line of code , Give it first b value , yes 3, Then in self increasing a Value of , here a yes 4 System.out.println
(a); int c = ++a;// Before this line of code is executed , Self increasing first a Value of , here a yes 5, Then assign a value // in brief a++ Assign first and then increment ++a Increment before assignment System.
out.println(a); System.out.println(b); System.out.println(c); // exponentiation double pow =
Math.pow(3,4); System.out.println(pow); } }
Logical operation
public class Demo05 { public static void main(String[] args) { // And (and) or (or)
wrong (no) boolean a = true; boolean b = false; System.out.println(a && b); System.
out.println(a || b); System.out.println(!(a && b)); // Short circuit operation System.out.println(
"==================="); int c = 5; boolean d = (c<4) && (c++<4); System.out.
println(d); System.out.println(c); } }
Bit operation ( Just know it now )
public class Demo06 { public static void main(String[] args) { /* * A = 0011
1100 * B = 0000 1101 * * A&B = 0000 1100 Both 1 Just for 1, Otherwise 0 * A|B = 0011 1101
All 0, Just for 0, There is one 1, Directly for 1 * A^B = 0011 0001 Same as 0, The difference is 1 * ~B = 1111 0010 Reverse * * * >> Shift right
*2 << Shift left /2 * Extremely efficient * 0000 0000 0 * 0000 0001 1 * 0000 0010 2 * 0000 0011 3 *
0000 0100 4 * * 0001 0000 16 * …… * */ } }
Small expansion
public class Demo07 { public static void main(String[] args) { int a = 10; int
b= 20; a+=b; a-=b; System.out.println(a); System.out.println(a+b); // String connection
String System.out.println(""+a+b); System.out.println(a+b+""); } }
Get data input , Simple interaction , similar C language scanf

Be careful ,IO Remember to release the stream after use
import java.util.Scanner; import static java.lang.System.in; public class
Demo01 { public static void main(String[] args) { // Create a scanner object . Used to accept keyboard data Scanner
scanner= new Scanner(System.in); System.out.println(" use next Mode reception "); if(scanner.
hasNext()){ String str = scanner.next(); System.out.println(" The input content is "+str); }
import java.util.Scanner; public class Demo02 { public static void main(String[]
args) { Scanner scanner = new Scanner(System.in); System.out.println(
" input ,nextline"); if(scanner.hasNextLine()){ String s = scanner.nextLine(); System
.out.println(":"+s); } scanner.close(); } } import java.util.Scanner; public
class Demo03 { public static void main(String[] args) { Scanner scanner = new
Scanner(System.in); System.out.println(" input "); String str = scanner.nextLine();
System.out.println(" Enter yes :"+str); scanner.close(); } } mport java.util.Scanner;
public class demo04 { public static void main(String[] args) { Scanner scanner =
new Scanner(System.in); int i = 0; float f = 0.0f; System.out.println(" input "); if(
scanner.hasNextInt()){ i = scanner.nextInt(); System.out.println(":"+i); }else{
System.out.println(" The input is not an integer "); } scanner.close(); } } import java.util.Scanner;
public class Demo05 { public static void main(String[] args) { int score = 0 ;
Scanner scanner = new Scanner(System.in); System.out.println(" Please enter your grade , children's shoes "); int s
= scanner.nextInt(); if(s>=60 && s<=100){ System.out.println(" congratulations , I didn't hang up "); }else if
(s>=0 && s<60){ System.out.println(" forehead , You know "); }else{ System.out.println(" Not an integer "); }
scanner.close(); } } public class Demo06 { public static void main(String[]
args) { char grade = 's'; switch (grade){ case 'a': System.out.println(" excellent ");
break; case 'b': System.out.println(" good "); break; case 'c': System.out.println(
" pass "); break; case 'd': System.out.println(" make persistent efforts "); break; default: System.out.
println(" Unknown level "); } } } public class Demo07 { //JDK7 Start supporting characters , The essence of characters is still numbers // Decompile
java---class( Bytecode file )----- Decompile (IDEA) public static void main(String[] args) {
String name = " Xiao Zhang "; switch (name){ case " Liu Sen ": System.out.println(" Liu Sen "); break;
case " Xiao Zhang ": System.out.println(" Xiao Zhang "); break; default: System.out.println(" What are you doing ");
} } }
loop
public class Demo01 { public static void main(String[] args) { int i = 0; while
(i<100){ System.out.println(i); i++; } } } public class Demo02 { public static
void main(String[] args) { int i = 0; int sum = 0; while (i<=100){ sum+=i; i++;
} System.out.println(sum); } } public class Demo03 { public static void main(
String[] args) { int i = 0; int sum = 0; do { sum+=i; i++; }while (i<=100);
// Pay attention to the semicolon System.out.println(sum); } } public class Demo04 { public static void
main(String[] args) { int a = 0; while (a<0){ System.out.println(a); a++; }
System.out.println("======================"); do{ System.out.println(a); a++; }
while (a<0); } } public class Demo05 { public static void main(String[] args) {
int sum = 0; for (int i = 1;i<=100;i++){ sum+=i; System.out.println(i); } System
.out.println(sum); } } // Dead cycle //for(;;) public class Demo06 { public static void
main(String[] args) { int a = 0; int b = 0; for (int i = 0; i < 100; i++) { if(i
%2==0){ a+=i; }else{ b+=i; } } System.out.println(" Even and yes :"+a); System.out.println
("ji Number sum is :"+b); } public class Demo07 { public static void main(String[] args) {
int i = 0; while (i<=1000){ i++; if(i%5==0){ System.out.print(i+"\t"); } if(i%(
15)==0){ System.out.println(); } } } } // Line wrap after output println // No line wrapping after output print
99 multiplication table
public class Demo08 { public static void main(String[] args) { for (int i = 1;i
<=9;i++){ for (int j = 1;j<=i;j++){ System.out.print(i+"*"+j+"="+(i*j)+'\t'); }
System.out.println(); } } } package loop ; //JDK5, Focus on circular arrays and collections public class Demo09 {
public static void main(String[] args) { int[] numbers = {10,20,30,40,50,60};
// Elements of convenience array for (int x:numbers){ System.out.println(x); } } }
//continue; Skip a loop ( younger sister ) //break; Forced push cycle ( Fierce ) public class Demo10 { public static void
main(String[] args) { int i = 0; while (i<100){ i++; if(i>50&&i<60){ continue; }
System.out.println(i); } } } // Print 101~150 Prime number of // Prime greater than 1 In the natural number of , except 1 A natural number that has no other factors than itself
public class Demo11 { public static void main(String[] args) { int i = 0; outer:
for (int a = 101;a<150;a++){ for(int b = 2;b<a/2;b++){ if(a%b ==0){ continue
outer; } } System.out.print(a+" "); } } } public class Demo12 { public static
void main(String[] args) { for (int i = 0; i <=5; i++) { for (int j = 5; j >=i ;
j--) { System.out.print(" "); } for (int j = 0; j <=i ; j++) { System.out.print
("*"); } for (int j = 0; j < i; j++) { System.out.print("*"); } System.out.
println(); } } }
method

Personal understanding Java The method can be compared with C Consistent understanding of core functions
stay main External writing method , Cry uncomfortable , It can be called function temporarily , ensure main Neatness of functions , The second is in main Call in method , Then you'll find out , It's not just for main in ……
public class Demo01 { //main method public static void main(String[] args) { int add
= add(1,5); System.out.println(add); print(); System.out.println(max(3,3)); }
// Wig public static int add (int a,int b){ return a+b; } //void public static
void print(){ System.out.println("Hello World!"); } // Maximum public static int max(
int a,int b){ int c = a>b?a:b; return c; //1. Return value //2. Planting method } }

Method reconstruction , Is one way , Suppose I compare the size of the method , Xiao Ming needs to compare the size of the two numbers , Xiao Hong needs to compare three people , It's just like rewriting a name , Different parameters , The implementation process is different, so the function reconstruction is realized
public class Demo02 { public static void main(String[] args) { System.out.
println(max(2.6,4.8,3.6)); } public static int max(int a,int b){ int c = a>b?a:b
; return c; } public static double max(double a,double b){ double c = a>b?a:b;
return c; } public static double max(double a,double b,double c){ if(a>b){
return a; }else if(b>c){ return b; }else{ return c; } } }
Variable length parameter
public class Demo03 { public static void main(String[] args) { Demo03 demo03 =
new Demo03(); demo03.test(1,234,45,4,6); } public void test(int... i){ System.
out.println(i[0]); System.out.println(i[1]); System.out.println(i[2]); System.
out.println(i[3]); System.out.println(i[4]); } } public class Demo04 { public
static void main(String[] args) { printMax(34,56,34,78,89); printMax(new double[
]{1,2,34}); } public static void printMax(double... numbers){ if(numbers.length
== 0){ System.out.println(" No input "); return; } double result = numbers[0]; for(int
i= 1; i<numbers.length;i++){ if(numbers[i]>result){ result = numbers[i]; } }
System.out.println("the max value is "+result); } }
recursion , In short, it is to pass the tortoise , ha-ha
Is to call yourself , Return to yourself
// Recursive header // Recursive body public class Demo05 { public static void main(String[] args) {
Demo05 demo05 = new Demo05(); demo05.test(); } public void test(){ test(); } }
example , calculation n Terrace factorial
public class Demo06 { public static void main(String[] args) { int c = f(4);
System.out.println(c); } public static int f(int n){ if(n == 1){ return 1; }else
{ return n*f(n-1); } } }

It is worth noting that ,Java Language land stack mechanism , Recursive operation , Need a lot of computer resources , Often face slightly greater demand ,Java The preset space is not enough , So use it with caution , But understand recursion , Feel the beauty of recursion !!! Come and tear the code

Technology
©2019-2020 Toolsou All rights reserved,
C++ of string of compare usage Python Study notes ( one )evo Tool usage problems ——Degenerate covariance rank, Umeyama alignment is not possibleRISC-V_GD32VF103-TIMER0 timer interrupt java Array subscript variable _Java Basic grammar : array be based on stm32 Control four-wheel trolley motor drive ( one ) be based on redis Design of liking function Software engineering career planning mysql Query random data by conditions _MySQL Random query of several qualified records centos7 install RabbitMq