Skip to content

Instantly share code, notes, and snippets.

View BalicantaYao's full-sized avatar

Balicanta BalicantaYao

View GitHub Profile
class Base{
public void foo() throws FileNotFoundException {
thorw new FileNotFoundException();
}
}
class OverideTest extends Base{
public void foo() throws IOException{
throw new IOException();
}
private static void runCase1() {
int j = 10;
Point point = new Point(4, 4);
logger.info(“Before Modify Point {}, j ={}”, point, j);
setPointLocation(point, j);
logger.info(“After Modify Point {}, j ={}”, point, j);
// Result
// Before Modify Point Point{y=4, x=4}, j =10
private static void runCase2() {
int j = 10;
Point point = new Point(4, 4);
logger.info(“Before Modify Point {}, j ={}”, point, j);
setPointWithAssign(point, j);
logger.info(“After Modify Point {}, j ={}”, point, j);
// Result
// Before Modify Point Point{y=4, x=4}, j =10
public static void main (String args[]){
ServerSocket serverSocket = new ServerSocket(199);
try{
Socket socket = serverSocket.accept();
}
finally{
socket.close();
}
}
public void checkEmptyUserName(String username){
if(StringUtils.isBlank(userName)){
throws new LoginFailedException("Username is empty!");
}
}
public static class verfiyExceptionTest{
@Rule
public ExpectedException thrown= ExpectedException.none();
@Test
public void throwsExceptionWithMessage() {
// 預期 LoginFailed 會產生以及對應的 Exception message
thrown.expect(LoginFailedException.class);
thrown.expectMessage(startsWith("UserName"));
public void demoException() throws Exception{
try{
throw new ("Exception A");
} catch (Exception e){
throw new Exception("Exception B");
} finally {
throw new Exception("Exception C");
}
}
public void demoException() throws Exception{
try{
throw new ("Exception A");
} catch (Exception e){
throw new NestableException("Exception B", e);
}
}
class Excperf {
public void method1(int size){
int [] ia = new int[size];
try{
for (int i = 0;i<size ; i++){
ia[i] = i;
}
} catch (Exception e){
}
package hello;
public class OCR {
public static void main(String[] args)
{
String first = "ba6";
String second = "1Ad";
boolean res = Ocr(first, second);
System.out.println(countingWordsLength(first));