如何用wordpress做視頻網(wǎng)站品牌seo培訓(xùn)咨詢
單元測(cè)試
-
? ?操作步驟:
? ? ? ?a.導(dǎo)包import org.junit;
? ? ? ?b.三個(gè)注解 ?@Test @Before @After
? ? ? ?c.點(diǎn)擊@Test 運(yùn)行就可以了
? ?用在不需要控制臺(tái)輸入的情境下:javaweb,框架項(xiàng)目,微服務(wù)項(xiàng)目 供開(kāi)發(fā)人員自己做測(cè)試。
package com.page.test;import com.page.entry.DVD;
import com.page.service.DvdService;
import com.page.service.impl.DvdServiceImpl;
import com.page.controller.DvdController;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@SuppressWarnings("all")
public class DVDTest {@Testpublic void test1(){DvdController controller=new DvdController();controller.menu();}DvdService service=null;@Beforepublic void testB(){service=new DvdServiceImpl();}@Testpublic void test2(){int i= service.getDataCount(new DVD());System.out.println("一共有"+i+"條數(shù)據(jù)");}@Testpublic void test3(){int i= service.getDataCount(new DVD());System.out.println("一共有"+i+"條數(shù)據(jù)");}@Afterpublic void testA(){System.out.println("測(cè)試結(jié)束!");}}
注解
一,注解的分類
1,jdk中的常用注解:
? ? ? ? ? ? ? ? ? @SuppressWarnings("all") ? 抑制警告
? ? ? ? ? ? ? ? ? @Deprecated ?標(biāo)記過(guò)時(shí)
? ? ? ? ? ? ? ? ? @Override ? ?表示重寫(xiě)方法
2,單元測(cè)試?yán)锏淖⒔?#xff1a;
? ? ? ? ? ? ? ? @Test
? ? ? ? ? ? ? ? @Before
? ? ? ? ? ? ? ? @After
3,javadao注釋里的注解;
4,框架、javaweb里的注解。
5,元注解:修飾注解的注解就是元注解。
其中注意:
? @param @return和@exception這三個(gè)標(biāo)記都是只用于方法的。
? @param的格式要求: @param 形參名 形參類型 形參說(shuō)明
? @return的格式要求: @return 返回值類型返回值說(shuō)明,如果方法的返回值類型是void就不能寫(xiě)
? @exception的格式要求: @exception 異常類型異常說(shuō)明
? @param和@exception可以并列多個(gè)
枚舉
一,創(chuàng)建
package page.enumdemo;public enum DVDType {恐怖,搞笑,穿越,古裝
}
二,使用
package page.test;import page.entry.DVD;
import page.enumdemo.DVDType;import java.util.Scanner;public class EnumTest {public static void main(String[] args) {//賦值,取值,轉(zhuǎn)換,枚舉DVD dvd=new DVD();//1,直接賦值dvd.setDvdType(DVDType.古裝);//2,控制臺(tái)輸入賦值Scanner input=new Scanner(System.in);String s=input.next();DVDType dvdType=DVDType.valueOf(s);dvd.setDvdType(dvdType);System.out.println(dvd.getDvdType());}
}
三,Enum類常用方法
package com.msb.enum03;public class TestSeason {//這是一個(gè)main方法,是程序的入口:public static void main(String[] args) {//用enum關(guān)鍵字創(chuàng)建的Season枚舉類上面的父類是:java.lang.Enum,常用方法子類Season可以直接拿過(guò)來(lái)使用://toString();--->獲取對(duì)象的名字Season autumn = Season.AUTUMN;System.out.println(autumn/*.toString()*/);//AUTUMNSystem.out.println("--------------------");//values:返回枚舉類對(duì)象的數(shù)組Season[] values = Season.values();for(Season s:values){System.out.println(s/*.toString()*/);}System.out.println("--------------------");//valueOf:通過(guò)對(duì)象名字獲取這個(gè)枚舉對(duì)象//注意:對(duì)象的名字必須傳正確,否則拋出異常Season autumn1 = Season.valueOf("AUTUMN");System.out.println(autumn1);}
}
網(wǎng)絡(luò)編程
- 客戶端
package page.socketdemo;/*** 客戶端:發(fā)送信息給服務(wù)器 問(wèn) “中午吃啥了?”*/import java.io.*; import java.net.Socket; import java.util.Scanner;public class Asocket {public static void main(String[] args) throws IOException {while (true) {Scanner input = new Scanner(System.in);//設(shè)置一個(gè)socket對(duì)象,鎖定服務(wù)器的IP和端口Socket socket = new Socket("127.0.0.1", 8888);//2.獲得輸出節(jié)點(diǎn)流OutputStream outputStream = socket.getOutputStream();DataOutputStream dos = new DataOutputStream(outputStream);//3.寫(xiě)入數(shù)據(jù)/* dos.writeUTF("中午吃啥了?");*/System.out.println("請(qǐng)輸入你要發(fā)送的信息:");dos.writeUTF(input.next());//4.接受服務(wù)器端回復(fù)的消息InputStream inputStream = socket.getInputStream();DataInputStream dis = new DataInputStream(inputStream);System.out.println("服務(wù)器回復(fù):" + dis.readUTF());//4.關(guān)閉流資源dis.close();dos.close();}} }
- 服務(wù)器端
package page.socketdemo;import java.io.*; import java.net.ServerSocket; import java.net.Socket; import java.util.Scanner;/*** 服務(wù)器端*/ public class SSocket {public static void main(String[] args) throws IOException {Scanner input = new Scanner(System.in);ServerSocket ss = new ServerSocket(8888);while (true) {System.out.println("服務(wù)器已啟動(dòng)!");//通過(guò)系統(tǒng)類,一直關(guān)注一個(gè)端口號(hào),判斷是否有客戶端發(fā)送請(qǐng)求//2.接收發(fā)送過(guò)來(lái)的請(qǐng)求:Socket socket = ss.accept();//accept();---可以阻塞線程//3.獲得輸入流InputStream inputStream = socket.getInputStream();DataInputStream dis = new DataInputStream(inputStream);//4.讀出String s = dis.readUTF();System.out.println("客戶端發(fā)來(lái)了的消息:" + s);//5.回復(fù)OutputStream outputStream = socket.getOutputStream();DataOutputStream dos = new DataOutputStream(outputStream);System.out.println("請(qǐng)回復(fù)客戶:");dos.writeUTF(input.next());//5.關(guān)閉資源dos.close();dis.close();}} }
cmd