JAVAEE Foundation (personal)

JAVAEE Foundation (personal)

Statement: This article is only a personal note and does not have any reference. If you are interested in its title, please refer to other professional articles.

1.JAVA overview

1.1 fundamentals of computer

Software / hardware
Software can be divided into system software and application software

System software: DOS, windows, Linux (CentOS 7.8, red hat, deepin: domestic), Mac
Mobile terminal: android,ios, Hongmeng (Huawei)
Application software: the client software must be updated to use the functions of the server's higher version!
QQ client
office software
VNC view (client)
VCN service (server)

human-computer interaction
It is mainly divided into graphical interface and character interface. For example, Linux and Windows have their graphical interface and console dos interface.

Windows character interface: win+R - > CMD - > Enter to open (recommended)
ps: if you are a home version user and there is no security policy option, it is recommended to select the second one: Start Menu - > Enter cmd - > right click to open it by the administrator.
Linux character interface: init 3 (graphical interface command init 5) is a convenient and safe entry method. More specific methods and principles are not described.

1.2 Dos control command

ps: in order to facilitate the instruction memory of Windows and Linux, select to summarize them together

  • Change letter
    Windows: d:
    Linux: there is no specific, which can be completed by subsequent cd to the specified directory file
  • Enter the specified directory
    Windows: cd \ directory name path (both relative and absolute paths are allowed)
    Linux: cd / directory file name (ditto)
  • Return to the previous level
    Windows: cd . .
    Linux: cd . . (ibid.)
  • Fallback root
    Windows: cd
    Linux: cd /
  • Create a directory
    Windows: md directory name
    Linux: mkdir directory name
  • Create a file
    Multiline editing
    Windows: copy con file name Suffix (type end crtl+z)
    Linux: cat > file name Suffix (end crtl+d)
    vim/vi/grdet file name
    Single line editing
    Windows: echo content > file name
    Linux: echo "content" > file name
  • Delete directory
    Windows: rd directory name (all directories are empty)
    rd /s directory name (the directory has contents and there are warnings for deletion)
    rd /s /q directory name (forced deletion, no warning)
    Linux: rm directory name (directory has no content)
    rm -rf (forced deletion, no warning)
  • Delete file
    Windows: del file name
    Linux: rm file name (everything in Linux is a file)
  • Clear screen
    Windows: cls
    Linux: crtl+L or clear
  • View ip address information
    Windows: ipconfig
    Linux: ifconfig
  • Access ip
    Windows: ping ip address
    Linux: ping ip address

1.3 Java language platform

  • JAVASE
  • JAVAVME
  • JAVAEE

1.4 Java features

  • object-oriented
    The object-oriented method is mainly to objectify things, including their attributes and behaviors.
  • Cross platform
    JAVA programs run on Windows,Linux,Mac and other platforms through JVM virtual machines
  • Open Source
    You can view the underlying source code of any JDK and so on

1.5 Java language environment construction

  • jre: Java runtime environment
  • jdk: Java Development Kit
  • jvm: Java virtual machine

The jdk contains the jre and the jvm

1.6 Path environment variable configuration

Reason: javac and java source files need to be compiled and run in any directory
Method: this computer - > right click Properties - > advanced system settings - > environment variables - > system variables - > new variable name: JAVA_HOME variable value: the directory path where the jdk is located

1.7 writing JAVA program

1) New file XXX java
2) Write code
3) Compile javac XXX java
4) Run java xxx

2. Fundamentals of Java language

2.1 keywords

public static void main

2.2 identifier

2.2.1 constants

2.2.2 variables

  • format
    Data type variable name = value;
  • Naming rules
    Words, underscores and $symbols must be used at the beginning, including the front and numbers, and the naming method of the small hump shall be followed as far as possible.
    -Initialization
    Before use, it must be initialized.
  • data type
    java data types are divided into two categories: basic data types and reference data types
    Basic data types: integer type (byte type, short integer type, integer default type, long integer type), floating point type (float, double), character type (char), boolean type (Boolean)
    Reference data types: arrays, classes, and interfaces.

2.3 assignment operator

2.4 logical operators

2.4.1 logic and
2.4.2 logic or
2.4.3 logical non

2.5-bit operator

2.5.1 |
2.5.2 &
2.5.3 !

2.6 ternary operators

  • Basic format
    (conditional judgment)? Condition 1: condition 2;

3.JAVA control statement

3.1 sequence structure

From top to bottom

3.2 selection of structure

3.2.1 if statement

Case 1: find the maximum of the three data

import java.util.Scanner;
public class Demo9 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.println("Enter the first number");
		int a = input.nextInt();
		System.out.println("Enter the second number");
		int b = input.nextInt();
		System.out.println("Enter the third number");
		int c = input.nextInt();
		//Method 1, ternary
		int max1= (a>b)?a:b;
		int max = (max1>c)?max1:c;
		System.out.println("The maximum value is:"+max);
		//Method 2: if
		int max2,max3;
		if(a>b) {
			max2 = a;
		}else max2 = b;
		if(max2>c) {
			max3 = max2;
		}else max3 = c;
		System.out.println("The maximum value is:"+max3);
	}

Case 2: judging students' grades

import java.util.Scanner;
public class Demo12 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int a = input.nextInt();
		if(a<100 && a>=90) {
			System.out.println("A");
		}else if(a<90 && a>=80)
		{
			System.out.println("B");
		}else if(a<80 && a>=70)
		{
			System.out.println("C");
		}else if(a<70 && a>=60) 
		{
			System.out.println("D");
		}else if(a<60 && a>=0)
		{
			System.out.println("E");
		}else System.out.println("Input error!");
	}
}
3.2.2 switch statement

Case 1: judge week

import java.util.Scanner;
public class Demo10 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int a = input.nextInt();
		switch(a) {
		case 1:System.out.println("Monday");
		break;
		case 2:System.out.println("Tuesday");
		break;
		case 3:System.out.println("Wednesday");
		break;
		case 4:System.out.println("Thursday");
		break;
		case 5:System.out.println("Friday");
		break;
		case 6:System.out.println("Saturday");
		break;
		case 7:System.out.println("Sunday");
		break;
		default:System.out.println("Please re-enter!");
		}
	}
}

3.3 circulation structure

3.3.1 for statement

Case 1: print out the number of all daffodils

public class Demo13 {
	//Narcissistic number 
	public static void main(String[] args) {
		int a,b,c;
		for(a=1;a<=9;a++)
		{
			for(b=0;b<=9;b++)
			{
				for(c=0;c<=9;c++)
				{
					int num = a*100+b*10+c*1;
					if(num == a*a*a+b*b*b+c*c*c)
					{
							System.out.print(num+" ");
					}
				}
			}
		}
	}
}

Case 2: buy a hundred chickens for a hundred dollars

public class Demo14 {
	//Buy white chicken for free
	public static void main(String[] args) {
		int a=0,b=0,c=0;//a is the cock, b is the hen, c is the chick
		for(a=0;a<=35;a++)
		{
			for(b=0;b<=100;b++)
			{
				for(c=0;c<=400;c++)
				{
					if(a+b+c==100 && c%3==0 && a*3+b*2+c/3==100)
					{
						System.out.println("cock:"+a+"hen:"+b+"chick:"+c);
					}
				}
			}
		}
	}
}
3.3.2 while statement

Case 1: use the while/for loop to find the sum between 1-100 and the even sum between 1-100

import java.util.Scanner;
public class Demo11 {
	//Use the while/for loop to find the sum between 1-100 and the even sum between 1-100
	public static void main(String[] args) {
		//while method
		int a=1,sum=0;
		while(a<=100) {
			sum+=a;
			a++;
		}
		System.out.println("while Method 1-100 And:"+sum);
		//for method
		int b,sum2=0;
		for(b=1;b<=100;b++) {
			sum2 += b;
		}
		System.out.println("for Method 1-100 And:"+sum2);
		//while even numbers and methods
		int c=0,sum3=0;
		while(c<=100) {
			sum3+=c;
			c = c+2 ;
		}
		System.out.println("while Method 1-100 Even sum of:"+sum3);
		//for even numbers and methods
		int d,sum4=0;
		for(d=0;d<=100;d=d+2) {
			sum4 += d;
		}
		System.out.println("for Method 1-100 Even sum:"+sum4);
	}
}

3.3.3 do while statement

Case 1:

Keywords: Java

Added by suave4u on Fri, 21 Jan 2022 00:18:30 +0200