preface

My Java theory knowledge has not been very good, decided to start from 0 to sum up, think of and before uncertain (refer to the data to determine) knowledge sort out, refuze!! Insist!!

Java overview

Three Major Java systems

1, Java ase standard edition 2, JavaEE enterprise edition (mainstream) 3, JavaME micro edition

Download and Install JDK

You are advised to install JDK8 or later

Environment Variable Configuration

1, the JAVA_HOME

The root directory of the JDK installation, for example:

D:\JDK8_211
Copy the code

2, the path

; %JAVA_HOME%\bin; %JAVA_HOME%\jre\binCopy the code

3, the CLASSPATH

.; %JAVA_HOME%\lib; %JAVA_HOME%\lib\dt.jar; %JAVA_HOME%\lib\tools.jarCopy the code

Verify that the installation and compilation run DOS

Verify the installation

java -version
Copy the code

Compile operation

1. Javac: compile to class file

javac Hello.java
Copy the code

Java: Run Java

java Hello
Copy the code

HelloWorld.java

public class HelloWorld{
	public static void main(String args[]){
		System.out.println("Hello World!"); }}Copy the code

Java Syntax Rules (specifications)

The source file name must be the same as the class name, and the suffix must be. Java 5. A source file can only contain one public class. There can be more than one other class (inner class, anonymous class) 6. All programs start execution from the main method (main()) entry 7

  1. The name must start with a letter, dollar sign, or underscore (_). It cannot start with a number
  2. Keywords cannot be used as identifiers

8, comments,

  1. Presenter: / /
  2. Multiple lines: / * * /

Java keyword

The common are here, you can recall the meaning and use of these keywords while watching, review and consolidate, check the gaps

Access control

private // Private mode
protected // Protection mode
public // Common mode
Copy the code

Class, method, and variable modifiers

class// Declare a classabstract// Indicates that a class or member method has abstract propertiesextends/ / inheritancefinal// The final attribute cannot be changedinterface// Declare an interfaceimplements// Implement an interfacenew// Create a new instance objectstatic// indicates static propertiessynchronized// indicates that a piece of code needs to be executed synchronouslyvolatile// indicates that two or more variables must change simultaneouslyCopy the code

Program control statement

break // Break out of the loop
continue // Continue the next loop
return // Return data from member methods
do.while(a)// Execute at least once before deciding whether to continue the loop
if()..else // If, conditional judgment
for / / loop
instanceof // Check whether an object is an instance object of the specified type
switch // Branch statement
case // After switch, one of the branches is represented
default // Use default if none of the switches meet the criteria
Copy the code

Error handling

try // Try a block of code that might throw an exception
catch // Catch the exception and process it
throw // Throw an exception
throws // Declare all exceptions that need to be thrown in the current member method
Copy the code

Package related

import // Specify the package or class to access
package / / package
Copy the code

Basic types of

boolean / / the Boolean
byte / / type byte
short / / short integer
int / / integer
long / / long integer
char / / character
float // Single-precision floating point
double // Double precision floating point
null // Null, note: cannot be assigned to primitive types (int,long...)
true / / true
false / / false
Copy the code

Variable reference

super // Represents a reference to or constructor of the parent type of the current object
this // Represents a reference to the current object
void // Indicates that the current member method does not return a value
Copy the code

Reserved keywords

goto
const
Copy the code

Constants and variables

constant

Use final names to modify constants.

final String DEMO = "Hello";
Copy the code

Final modifiers are allowed to be initialized only once and are usually used with static

variable

Example: int a = 2;

The data type

Basic data type

Reference data type

Array class interface

Data type conversion

Automatic type conversion

2. Byte and short cannot be converted to char. The char value ranges from 0 to 65535. Byte and short both contain negative numbers. 3. A string is converted to a string type when connected to any data type. 4

Cast

Byte b = (byte)12 (byte b = (byte)12

The operator

count

+, -, *, /, %, ++, —

The assignment

=, +=, *=, /=, %/

To compare

<,>, >=, <=,! = = =

logic

, &&, | |!

The ternary

Conditions? Value of true: value of false

priority

Try to use parentheses for better readability

instanceof

Checks whether the current object is of a specific type

Control process

The order

branch

if else

switch case
Copy the code

cycle

while

Do while executes at least once

for

Enhanced for loop

for(int hero : heros)
{
   // Code sentences
}
Copy the code

The keyword

break

The innermost cycle stops completely

continue

Stop this cycle and start the next one

return

Just end a method

An array of

define

The object stored on the heap, can save multiple variables of the same type array initialization, memory space is fixed, the length cannot change

Static initialization

int demoArray[3] = {1.2.3};
Copy the code

Dynamic initialization

int demoArray[10];
Copy the code

The statement

int[] a
Copy the code

create

int[] a = new int[5];
int[] a = {1.2.3.4.5};
Copy the code

traverse

// The array index starts at 0
for (int i = 0; i < myList.length; i++) {
	System.out.println(myList[i] + "");
}
/ / for each cycle
for (double element: myList) {
	System.out.println(element);
}
Copy the code

The Arrays class method

The sorting

sort

To compare

equals

Common operation

Sort (bubble, select) find Max, min and half search

To be honest, it’s a little hard… Come on!! Insist on!!!!!