1. Java: born in 1995, pure object-oriented, cross-platform, mainly used for Internet and embedded;
Date.gettime () — the number of milliseconds since 1970;
3. Java running mechanism: Compile first, explain later
The platform-dependent. Java source files are first compiled by the compiler into platform-neutral. Class bytecode files, which are then interpreted into machine code files when run in the JVM, depending on the interpreter chosen for the platform. \
4. jvm(java virtual machine) : The JVM, short for Java Virtual Machine, is a specification for computing devices. The JVM is an imaginary computer that is implemented by emulating various computer functions on an actual computer. When the Java virtual machine executes bytecodes, it interprets the bytecodes as machine instructions on a specific platform. This is why Java has the ability to “compile once, run anywhere”.
The JVM is the container in which Java programs run, but it is also a process of the operating system, so it has its own running life cycle and its own code and data space.
The JVM is the lowest level of the JDK and is responsible for the interaction with the operating system. It is used to mask the operating system environment and provide a complete Java runtime environment, hence the virtual computer. The operating system is loaded into the JVM by using java.exe in the JDK. The following 4 steps are used to complete the JVM environment.
1. Create the JVM load environment and configuration
Libjvm.dll: libjvm.dll: libjvm.dll: libjvm.dll: libjvm.dll: libjvm.dll
JNI is short for Java Native Interface. It provides several apis to realize the communication between Java and other languages. It is the bridge between JNI and the Java world and Native world
4. Call the JNIEnv instance to load and process the class class.
5. Java Runtime Environment (JRE) : Java runtime environment compiler + JVM
JDK (Java Development Kit) : Java development tool JRE + core class library + tools
7. Java compile run command:
javac -d . Hello.java\
java p.Hello
javadoc -d . Hello.java
8. Java architecture:
Package: The package name is all lowercase
Class: There can be only one public class and the public class name must match the file name of the source file
Method: indicates the method name
Filed: Attribute variable hump naming method
9. Variable types:
Byte (1) short(2) int(4) Long (8) Float (4) Double (8) char(2) Boolean (1)
Reference type: String Array class interface enumerates annotations
10. Operators:
+, -, *, /, %
==, +=, -=, *=, /=, %=
Short circuit, &&, | |,!
The short circuit, &, |, ^ ~
<<, >>, >>>
a>b? a:b
11. Select statements:
if(…) {} else if(…) {} else {}
switch(…) {case 1 : ; break; . default : ; break; }
12. Loop statements:
for(.. ; . ; . 😉 {}
while(..) {}
do {} while(…) ;
13. Method: Modifier return value method name (argument list) throw exception {function body}
14. Method overloading: same method name, different parameter table
15. Method coverage:
The return value method name parameter list is identical
Modifier is the same as or wider than the parent class
You cannot throw more exceptions than the parent class
16. Object oriented: treat everything that exists objectively as an object
17. Encapsulation: Isolation and protection to form a distinct internal and external interval
18. Inheritance: The relationship between father and son is maintained only by inheritance
19. Polymorphism: The maintenance of additional relationships other than the main relationship is more inheritance and more implementation
Interface: Exposes abstract methods
Expose static constants
20. this(…) : calls the constructor of this class
super(…) : calls the constructor of the parent class
Both of these must be in the first line of the method
21. This.method () : Calls a method of this class
Super.method () : Calls the method of the parent class
22. Abstract
An abstract class does not necessarily have abstract methods, but a class with abstract methods must be an abstract class
An element is an object
List: the elements are ordered and can be repeated \
ArrayList :\
Vector :
LinkedList :
Set: Element is unordered and cannot be repeated
HashSet :
TreeSet :
Map: the key is unique and the value is arbitrary
HashMap :
HashTable :
Properties: load configuration information
TreeMap :
Traversal of sets:
Set and List traversal:
Set<String> set = new HashSet<String>();
Iterator
iterator = set.iterator(); while(iterator.hasNext()) { String str = iterator.next(); System.out.println(str); \
}
for(String str : set) {
System.out.println(str);
}
\
The Map through:
Value through:
Collection<Object> c = map.values();
for(Object o : c) { System.out.println(o); \
}
Key traversal:
Map
map = new HashMap
(); Set
set = map.keySet(); for(String key : set) { System.out.println(key + “———-” + map.get(key)); \
}
Map<String, Object> map = new HashMap<String, Object>();
Set<String> keySet = map.keySet();
Iterator<String> iterator = keySet.iterator();
while(iterator.hasNext()) {
String key = iterator.next();
System.out.println(key + “———” + map.get(key));
}
Key value traversal:
Map
map = new HashMap
(); Set
me : entrySet) { System.out.println(me.getKey() + “——-” + me.getValue()); \
}
Map<String, Object> map = new HashMap<String, Object>();
Set<Map.Entry<String, Object>> entrySet = map.entrySet();
Iterator<Map.Entry<String, Object>> iterator = entrySet.iterator();
while(iterator.hasNext()) {
Map.Entry<String, Object> me = iterator.next();
System.out.println(me.getKey() + “———” + me.getValue());
}
24. IO :
Byte stream: InputStream/OutputStream
FileInputStream/FileOutputStream node flow
A DataInputStream/DataOutputStream filtering flow
ObjectInputStream/ObjectOutputStream filtering flow
BufferedInputStream/BufferdOutputStream filtering flow
PrintStream — system.out.print () filters the stream
Character stream: Rider/writer
FileReader/stream FileWriter node
BufferedReader BufferedWriter/PrintWriter filtering flow
Bridge transformation flows: InputStreamReader/OutputStreamWriter only set the coding format of the stream
Object serialization: Objects are transferred in a stream implementing the Serializable interface
Development process:
Creating a node flow
Encapsulated filter stream
Input/output
Close the stream (usually close the outermost stream)
25.
Thread: a sequential process of concurrent execution within a process
Concurrency: for a CPU, macro parallel, micro serial, CPU time slice
Space: heap space sharing stack space independent
Thread creation: implements Runnable/extends Thread
Thread.start () thread.stop();
Initial state: Create Thread object
Running status: thread.start()
Running Status: CPU Selected
Terminated state: The thread is complete
Blocked: Waiting for join sleep
Lock pool status: Synchronized, but no lock flag obtained
Wait queue status: WAIT
Thread synchronization
Deadlock: Multiple synchronizations join each other
Reflection: Manipulate a class by retrieving information about it from a class object
Class loading: The first time the JVM uses a class, it finds the class’s.class bytecode file based on its classpath path, reads the information and saves it in the class object.
Class object: an object that holds information about a class;
Class object fetching: class.forname (fully qualified name);
Class. The class
Object. GetClass ()
Class object use:
Class c = Class.forName(“java.util.Map”); Object o = c.newInstance(); c.getAnnotation(annotationClass); c.getFields(); c.getField(name); c.getMethods(); Method method = c.getMethod(name, parameterTypes); \
method.invoke(o, args);
27. Enumeration: Enum is the parent class of all enUms
Enum A {SPRING(” SPRING “), SUMMWER(” summer “); private String name; private A(String name) { this.name = name; } public String getValue() { return this.name; } \
}
28. Custom annotations:
@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD,ElementType.METHOD,ElementType.TYPE}) @interface In { public String value() default “hello”; \
}
29. Exception:
Throwable – Error
– Exception
| – RuntimeException
Throw new RuntimeExcepiton();
Throws Exception handling
try {} catch(Exception e) {} finally {}
Custom exceptions:
class MyException extends Exception { public MyException(String name) { super(name); } \
}
Network 30.
ServerSocket ss = new ServerSocket(); while(true) { Socket s = ss.accept(); PrintWriter out = new PrintWriter(s.getOutputStream()); out.println(“hello world”); out.flush(); } Socket s = new Socket(ip, port); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); String str = in.readLine(); \
System.out.println(str);
31. A base class Object
finalize();
getClass();
hashCode();
equals();
clone();
wait();
notify();
notifyall();
toString();
32. The modifier
public protected (default) private
static abstract final
synchronized
Transient modifies the property and does not serialize
33. Thread binding: ThreadLocal The principle of a local thread is a map with its own key
34. Keyword: instance Determines whether the actual type of an object belongs to a class
35. Generics: To define the type safety of collections or other classes
36. Integer Constant pool: -127 — 128
int a = 100; Integer in = new Integer(100); \
System.out.println(a==in);
The result is true;
int a = 500; Integer in = new Integer(500); \
System.out.println(a==in);
The result is also true
37. String pool: Constant
StringBuilder StringBuffer
String abc = “abc”; String bcd = new String(“abc”); \
System.out.println(abc==bcd);
The result is false
\
\