public class AssertTest {
public static void main(String[] args) {
AssertTest assertTest = new AssertTest();
assertTest.test(0);
}
public void test(int a) {
assert a != 0 : "参数不能为0";
int c = 10 / a ;
System.out.println(c);
System.out.println("hello");
}
}
import java.util.HashMap;
import java.util.Map;
public class LoginTest {
Map<String, User> map;
{
map = new HashMap<String, User>();
User user = new User("tom", "123");
map.put("tom",user);
}
public void login(String username,String password) throws LoginException {
if (!map.containsKey(username)) {
throw new LoginException("用户名不正确");
}else {
System.out.println("用户名正确");
}
User user = map.get(username);
if (!user.password.equals(password)) {
throw new LoginException("密码错误");
}else {
System.out.println("密码正确");
}
}
public static void main(String[] args) {
LoginTest loginTest = new LoginTest();
try {
loginTest.login("tom", "123");
} catch (LoginException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class LoginException extends Exception{
public LoginException(String massage) {
super(massage);
}
public LoginException() {
// TODO Auto-generated constructor stub
}
}
线程创建方法
public class MyThread extends Thread{
@Override
public void run() {
System.out.println(MyThread.currentThread());
for (int i = 0; i < 10; i++) {
System.out.println("helloworld");
}
}
}
Thread t1 =new Thread() {
public void run() {
for (int i = 0; i < 100; i++) {
System.out.println("hello" + i);
}
}
};
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println(Thread.currentThread());
//System.out.println("t2的线程");
}
},"t2线程");
定义Thread的Name
1. Thread xiaoli = new Thread(target,"xiaoli");
2. Thread jack = new Thread(target);
jack.setName("jack");