Xiaoao Java interview - noodle cultivation manual (source video code needs practice)
Xiaoao Java interview - noodle cultivation manual
The contents to be learned in Chapter 1 are: interpreting five rules, how to write a resume that the interviewer can't refuse, comments on 10-year interviewer desensitization resume, comments on 10-year interviewer desensitization resume cmL46679910
A classmate's mental journey, "10 years of interviewer desensitization resume review" feedback, becoming a Leader in small and medium-sized factories, students with no resume entered, and found their deficiencies from the "typical".
public void listen(int port) throws IOException { serverSocket = new ServerSocket(port); while(true) { this.accept(); } } void accept() throws IOException { // Blocking... // Thread--->Sleep ---> Other Threads try { var socket = serverSocket.accept(); System.out.println("A socket created"); var iptStream = new DataInputStream(socket.getInputStream()); var bfReader = new BufferedReader(new InputStreamReader(iptStream)); var requestBuilder = new StringBuilder(); String line = ""; // Readline -> line end '\n' while (true) { line = bfReader.readLine(); if(line == null || line.isBlank()) { break; } requestBuilder.append(line + '\n'); } var request = requestBuilder.toString(); System.out.println(request); var bfWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); var response = this.handler.apply(request); bfWriter.write(response); bfWriter.flush(); socket.close(); }catch(SocketException e) { e.printStackTrace(); } }
The contents to be learned in Chapter 2 include: Java proficiency, container, set and mapping: random sequence generator, IDEA development environment and Java configuration, container, set and mapping: (video resource vx (cmL46679910)) LRU for realizing key value, java8 stream interface: stream and pipeline are the basic usage, and java8 stream interface: parallel computing of handwritten stream.
public void listen(int port) throws IOException { serverSocket = new ServerSocket(port); while(true) { this.accept(); } } void accept() throws IOException { // Blocking... var socket = serverSocket.accept(); new Thread(() -> { try { this.handler(socket); } catch (IOException e) { e.printStackTrace(); } }).start(); } void handler(Socket socket) throws IOException { // Blocking... // Thread--->Sleep ---> Other Threads try { System.out.println("A socket created by Thread:" + Thread.currentThread().getId()); var iptStream = new DataInputStream(socket.getInputStream()); var bfReader = new BufferedReader(new InputStreamReader(iptStream)); var requestBuilder = new StringBuilder(); String line = ""; // Readline -> line end '\n' while (true) { line = bfReader.readLine(); if(line == null || line.isBlank()) { break; } requestBuilder.append(line + '\n'); } var request = requestBuilder.toString(); System.out.println(request); var bfWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); var response = this.handler.apply(request); bfWriter.write(response); bfWriter.flush(); socket.close(); }catch(SocketException e) { e.printStackTrace(); } }
Talk with the interviewer about the cornerstone of pipeline and flow computing: functional Monad, the principle and usage scenario of Buffer - Interpretation of interview questions, in-depth Buffer coding - Ali interview questions: Chinese garbled code processing and word frequency statistics of large files.
public class Request { static Pattern methodRegex = Pattern.compile("(GET|PUT|POST|DELETE|OPTIONS|TRACE|HEAD)"); public String getBody() { return body; } public String getMethod() { return method; } public HashMap<String, String> getHeaders() { return headers; } private final String body; private final String method; private final HashMap<String, String> headers; public Request(Socket socket) throws IOException { // DataInputStream -> primitives(Char, Float) // InputStream -> bytes var iptStream = new DataInputStream(socket.getInputStream()); var bfReader = new BufferedReader(new InputStreamReader(iptStream)); // GET /path HTTP/1.1 var methodLine = HttpParser.readLine(iptStream, "UTF-8"); var m = methodRegex.matcher(methodLine); m.find(); var method = m.group(); // Content-Type:xxxx // Length : xxx var headers = HttpParser.parseHeaders(iptStream, "UTF-8"); var headMap = new HashMap<String, String>(); for(var h : headers) { headMap.put(h.getName(), h.getValue()); } var bufferReader = new BufferedReader(new InputStreamReader(iptStream)); var body = new StringBuilder(); char[] buffer = new char[1024]; while(iptStream.available() > 0) { bufferReader.read(buffer); body.append(buffer); } this.body = body.toString(); this.method = method; this.headers = headMap; } }
Non equivalence of synchronization and blocking, asynchrony and non blocking, (video resource vx (cmL46679910)) reflection + metaprogramming interview questions, two reflections, Coding training: realizing AOP annotation, metaprogramming interview special, new features of Java 8-11, and document sorting of Java 8-11.
public class Response { Socket socket; private int status; static HashMap<Integer, String> codeMap; public Response(Socket socket) { this.socket = socket; if(codeMap == null) { codeMap = new HashMap<>(); codeMap.put(200, "OK"); } } public void send(String msg) throws IOException { var resp = "HTTP/1.1 " + this.status + " " + this.codeMap.get(this.status) + "\n"; resp += "\n"; resp += msg; this.sendRaw(resp); } public void sendRaw(String msg) throws IOException { var bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); bufferedWriter.write(msg); bufferedWriter.flush(); socket.close(); } }
The contents to be learned in Chapter 3 are: introduction level of algorithm data structure, insertion, selection, bubbling, divide and conquer strategy, quick sorting scheme, sorting, complexity analysis and performance thinking.
public class Step4Server{ ServerSocketChannel ssc; public void listen(int port) throws IOException { ssc = ServerSocketChannel.open(); ssc.bind(new InetSocketAddress(port)); // Reactive / Reactor ssc.configureBlocking(false); var selector = Selector.open(); ssc.register(selector, ssc.validOps(), null); ByteBuffer buffer = ByteBuffer.allocate(1024*16); for(;;) { int numOfKeys = selector.select(); Set selectedKeys = selector.selectedKeys(); Iterator it = selectedKeys.iterator(); while(it.hasNext()) { var key = (SelectionKey)it.next(); if(key.isAcceptable()) { var channel = ssc.accept(); if(channel == null) { continue; } // Kernel -> mmap(buffer) -> Channel -> User(Buffer) channel.configureBlocking(false); channel.register(selector, SelectionKey.OP_READ); } else { var channel = (SocketChannel)key.channel(); // _ _ _ _ _ _ _ // P(position) // L buffer.clear(); channel.read(buffer); String request = new String(buffer.array()); // Logic... buffer.clear(); buffer.put("HTTP/1.1 200 ok\n\nHello NIO!!".getBytes()); // H T T P / 1 ... ! _ _ // P(L) // P L buffer.flip(); channel.write(buffer); channel.close(); }
Handwritten linked list related algorithm, how to use stack and queue to realize expression parsing, handwritten tree related algorithm, eight queens and search problem, handwritten stack, queue related algorithm, hash table: cmL46679910 HashMap implementation principle and concurrent HashMap, handwritten dynamic programming.