备忘录

catch语句块一次捕获多个异常的语法是Java 1.7才有的

try {
    // ....
} catch (RuntimeException | IOException | ... ex) {
    // ....
}

 junit随记

import java.util.ArrayList;
import java.util.List;

// do not use junit.framework.Assert;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class TestJunit {

	private List<String> data;

	/**
	 * User @Before to do some setup before tests begin;
	 * 
	 * This is called <b>Fixture</b>
	 */
	@Before
	public void setUp() {
		System.out.println("Begin to set up");
		data = new ArrayList<String>();
	}

	/**
	 * Each test method should be annotated with @Test
	 */
	@Test
	public void test() {
		System.out.println("Testing test");
		int i = 10;
		int j = 10;
		int result = 20;
		// When you want to check a value,
		// import org.junit.Assert.* statically, call assertTrue() and
		// pass a boolean that is true if the test succeed
		Assert.assertTrue((i + j) == result);
	}

	/**
	 * If a test is expected to throw an Exception, then use <b>expected</b>
	 * parameter
	 */
	@Test(expected = IndexOutOfBoundsException.class)
	public void testException() {
		System.out.println("testing exception");
		data.get(0);
	}

}

 

用JS做的小时钟代码备份

<html>
<head>
    <title>Test Date</title>
    <script type="text/javascript">
        var p = null,
            d = null,
            year = null,
            year = null,
            month = null,
            day = null,
            hour = null,
            minutes = null,
            sec = null,
            dateStr = null;
            
        document.onreadystatechange = function(){   
            if(document.readyState=="complete") {   
                p = document.getElementById("panel");
                window.setInterval(start, 1000);
            }
        }
        function show(str) {
            p.innerHTML=str;
        }
        function start(){
            d = new Date();
            year = d.getFullYear();
            month = d.getMonth() + 1;
            day = d.getDate();
            hour = d.getHours();
            minutes = d.getMinutes();
            sec = d.getSeconds();
            
            if (hour < 10) {
                hour = "0" + hour;
            }
            if (minutes < 10) {
                minutes = "0" + minutes;
            }
            if (sec < 10) {
                sec = "0" + sec;
            }
                    
            var dateStr = year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + sec;
            show(dateStr);
            
            d = null;
            year = null;
            year = null;
            month = null;
            day = null;
            hour = null;
            minutes = null;
            sec = null;
        }
        
    </script>
</head>
<body>
    <h2 id="panel"></h2>
</body>
</html>

 

你可能感兴趣的:(备忘录)