table of Contents
- Key words
- learning target
- A Brief History of java
- jdk- download and install
- Features java-
- eclipse installation
- http protocol
- http1.1 configuration protocol request message
- http1.1 protocol response message structure
- HTTP status code
- REST
- Java Web
- Exercise 1: java basic algorithm
- A binary search run results screenshot
- TestSearch.java dichotomy lookup code
- Bubble algorithm run results screenshot
- BubbleSort.java bubble algorithm code
- Exercise 2: Building the java web project to write a servlet
Key words
- Static and dynamic resources
- And cross-domain origin policy
- Homologous concept:
- Protocol, domain names, the same port, said they homology.
- Only the same-origin policy restrictions dom js to read and write data in other domains have been restricted, such as javascript, css, pictures and other static resource loading is still considered to be homologous.
- Homologous concept:
learning target
- java development environment to build
- http protocol
- Overview and Java web project creation
A Brief History of java
- In 1995, SUN JAVA release
- In 2009, Oracle announced the acquisition of Sun
- In 2010, one of the co-founder of Java James Gosling resigned from Oracle * Company
- In 2011, Java7 officially released
- 2014, released the official version Java8
jdk- download and install
JDK to version 13, currently still the most used JDK8
- Jdk8 download the installation files to a local
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html - Installation and configuration environment variable
Features java-
Java is a write once run everywhere, cross-platform
java virtual machine JVM, running bytecode .class
java is aObject-OrientedProgramming language, classes and objects
stack, heap, area method, runtime constant pool
eclipse installation
- Eclipse is an open source, Java-based extensible development platform. The official version of Eclipse is an integrated development environment (IDE).
- Decompression that is installed
- Configuration jre
http protocol
- Hypertext Transfer Protocol, Hypertext Transfer Protocol
- "Communicate" is the norm between the browser and server
- http are "application layer protocol", TCP / IP-based protocol
- http stateless protocol
HTTP1.0 request defines three methods:GET, POSTAnd HEAD methods.
HTTP1.1 five new request method: OPTION,PUT, DELETE, TRACE and CONNECT method.
http1.1 configuration protocol request message
- A http request complete message, comprising a request line, a plurality of message header (request header), line feed, solid content
http1.1 protocol response message structure
- In response to data representative of a http server will send the client, which includes a status line, a plurality of headers, and an empty row, the entity content.
HTTP status code
- The Status Code the HTTP
1xx: indication information - indicates a request has been received, processing continues
2xx: Success - indicates that the request has been successfully received, understood, accepted
3xx: Redirection - to fulfill the request must be carried out further operations
4xx: Client Error - Request syntax error or a request can not be achieved
5xx: server-side error - the server failed to achieve a legitimate request
Common status codes:
The OK 200 is
201 ...... (to be added)
REST
REST (Representational State Transfer): Representational State Transfer
If a REST framework in line with the principle of the call Restful architecture, lightweight, cross-platform, cross-language design;
Based url HTTP protocol: https: //ke.qq.com/course/402016
GET (SELECT): Remove the resource from the server (one or more).
POST (CREATE): a new resource on the server.
PUT (UPDATE): update the resource (after the complete resources provided by the client to change) in the server.
PATCH (UPDATE): Updating Resource (provided by the client to change the properties) in the server.
DELETE (DELETE): Delete the resource from the server.
Java Web
- Java Web, Java technology is used to solve the sum of the areas of technology-related web Internet.
- web include: web server and web client in two parts. Now the browser can be used as a client, the ability to develop server-side.
- Technology: servlet, jsp, tomcat
- New web project in eclipse
Exercise 1: java basic algorithm
A binary search run results screenshot
TestSearch.java dichotomy lookup code
public class TestSearch {
public static void main(String[] args) {
int[] arr = new int[] { 11, 22, 33, 45, 66, 67, 77, 88, 90 };
System.out.println(search(arr, 11));
System.out.println(search(arr, 45));
System.out.println(search(arr, 67));
System.out.println(search(arr, 88));
System.out.println(search(arr, 99));
}
public static int search(int[] arr, int key) {
int start = 0;
int end = arr.length - 1;
while (start <= end) {
int middle = (start + end) / 2;
if (key < arr[middle]) {
end = middle - 1;
} else if (key > arr[middle]) {
start = middle + 1;
} else {
return middle;
}
}
return -1;
}
}
Bubble algorithm run results screenshot
BubbleSort.java bubble algorithm code
public class BubbleSort {
public static void main(String[] args) {
int[] array={2,8,9,1,10,31,0};
getSortD_X(array);
getSortX_D(array);
}
public static void getSortD_X(int[] array){
for (int i = 0; i < array.length; i++) {
for(int j=0;j<array.length-1;j++){
if(array[i]>array[j]){
int temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
System.out.print("从大到小:");
for (int i = 0; i < array.length; i++) {
if(i==array.length-1){
System.out.println(array[i]);
}else{
System.out.print(array[i]+",");
}
}
}
public static void getSortX_D(int[] array){
for (int i = 0; i <array.length; i++) {
for(int j=0;j<array.length-i-1;j++){
if(array[j]>array[j+1]){
int temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
System.out.print("从小到大:");
for (int i = 0; i < array.length; i++) {
if(i==array.length-1){
System.out.println(array[i]);
}else{
System.out.print(array[i]+",");
}
}
}
}
Exercise 2: Building the java web project to write a servlet
Screenshot operating results
Project Screenshot
HelloWeb.java Code
package com.one.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class HelloWeb
*/
@WebServlet("/HelloWeb")
public class HelloWeb extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HelloWeb() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().append("Served at: ").append(request.getContextPath());
PrintWriter pw = response.getWriter();
pw.print("hello world");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}