克-to-win:checked和unchecked異常區(qū)別:結論就是:1)RuntimeException和他的子類都是unchecked異常。其他的都是checked異常。馬克-to-win:2)在編譯階段,編譯器會檢查每一個方法,看是否方法里面拋出了checked異常。假設拋出了checked異常,那個方法里必須加catch,或者加throws語句(下一節(jié)講解),否則的話編譯器會報錯。馬克-to-win:unchecked異常就沒這規(guī)矩。
馬克- to-win:馬克 java社區(qū):防盜版實名手機尾號: 73203。
java中throws子句是怎么用的?工作原理是什么?
throws子句
馬克-to-win:當你的方法里拋出了checked異常,如你不catch,代表你當時不處理(不想處理或沒條件處理),但你必須得通過"throws 那個異常"告訴系統(tǒng)說,這兒有個問題,我現(xiàn)在不處理,將來一定別人要處理,否則執(zhí)行到它,馬克-to-win:系統(tǒng)會"不優(yōu)雅"的崩潰。舉個例子,工兵張三發(fā)現(xiàn)了地雷,假如他處理,完事就完事兒了。但是他發(fā)現(xiàn)了地雷,自己卻沒帶齊工具,沒法處理,他必須做個標記,說這兒有一個地雷,別的工兵將來一定要處理,否則將來有人踩上去會爆炸。馬克-to-win:注意:throws只是標記,并沒處理,執(zhí)行到那,系統(tǒng)還是會崩潰!
馬克- to-win:馬克 java社區(qū):防盜版實名手機尾號: 73203。
馬克-to-win:語法總結就是:當你的方法里拋出了checked異常,如你不catch,必須throws,即告訴編譯器,我的調(diào)用者會處理。如果你已經(jīng)是main,則main的調(diào)用者jvm會替你收拾殘局。否則無法編譯通過。
馬克-to-win:有的同學可能會問:throws有什么意義?又不真正處理問題。throws的意義,在于和throw配合起來一起工作。有關throw的意義,請參照上面throw部分。
馬克-to-win:現(xiàn)在就出現(xiàn)了一個非常深入的問題。(新手可忽略)為什么sun公司的語法設計成:runtime異常不需要throws,而非 runtime異常需要呢?咱們先說非runtime異常為什么需要throws呢?因為程序員多一道工序宣稱一下,麻煩一下自己,會給sun公司的人(Java編譯器)提供很大便利,少了很多判斷等工作。
篇幅有限更多請見擴展鏈接:http://www.mark-to-win.com/tutorial/java_5_throws.html
.Checked Exception(受檢的異常)
馬克-to-win:為什么我大膽的把Checked Exception翻譯成受檢的異常?因為這類異常,編譯器檢查發(fā)現(xiàn)到它后會強令你catch它或throws它(我們之后講),馬克-to-win:而相對于本節(jié)前面我們提到的各種比如ArithmeticException,都是unchecked exception(不受檢)的異常,unchecked異常都是RuntimeException或者它的子類。馬克-to-win:換句話:編譯器檢查發(fā)現(xiàn)到它以后,什么都不管,也什么都不做,直接放行。見下面的例子:
例:1.6.1-本章源碼
public class Test {
void m1_mark_to_win() {
throw new RuntimeException("divide by 0");
}
public static void main(String[] args) {
Test t=new Test();
t.m1_mark_to_win();
}
}
輸出結果:
Exception in thread "main" java.lang.RuntimeException: divide by 0
at Test.m1_mark_to_win(Test.java:3)
at Test.main(Test.java:7)
馬克-to-win:注意上面一個例子ArithmeticException是個unchecked exception, 所以什么問題都沒有,編譯器不報錯。馬克-to-win:但是,當我們把ArithmeticException變成 FileNotFoundException這種checked exception時,就會出現(xiàn)問題。馬克-to-win:如下面例:1.6.2,根本就編譯不過去。必須變成1.6.3才能運行。
篇幅有限更多請見擴展鏈接:http://www.mark-to-win.com/tutorial/java_5_TranslationCheckedException.html
、表單在網(wǎng)頁中的應用:登錄、注冊常用到表單
2、表單的語法:
<form method="post" action="result.html">
<p> 名字:<input name="name" type="text" > </p>
<p> 密碼:<input name="pass" type="password" > </p>
<p>
<input type="submit" name="Button" value="提交"/>
<input type="reset" name="Reset" value="重填“/>
</p>
</form>
3、表單元素說明:
type:指定元素的類型。text、password、checkbox、radio、submit、reset、file、hidden、image 和 button,默認為 text.
name:指定表單元素的名稱.
value:元素的初始值。type 為 radio時必須指定一個值.
size:指定表單元素的初始寬度。當 type 為 text 或 password時,表單元素的大小以字符為單位。對于其他類型,寬度以像素為單位.
maxlength:type為text 或 password 時,輸入的最大字符數(shù).
checked:type為radio或checkbox時,指定按鈕是否是被選中.
4、示例:
<html >
<head>
<title>表單元素</title>
</head>
<body>
<!-- 表單 -->
<form method="POST" action="#">
<!-- 標簽 -->
<label for="username">姓名:</label>
<!-- 文本框 value屬性是設置默認顯示的值-->
<input id="username" value="songzetong" />
<!-- 密碼框 -->
<br/><label for="pwd">密碼:</label>
<input type="password" id="pwd">
<br/>
<!-- 單選框 -->
<label for="sex">性別:</label>
<input type="radio" name="sex" checked/>男
<input type="radio" name="sex"/>女
<!-- 復選框 -->
<br/>
<label for="hobby">愛好:</label>
<input type="checkbox" name="hobby" id="hobby"/>聽音樂
<input type="checkbox" name="hobby"/>旅游
<input type="checkbox" name="hobby"/>游泳
<br/>
<!-- 下拉列表 -->
<label for="month">月份:</label>
<select id="month"/>
<option>1月</option>
<option>2月</option>
<option>3月</option>
</select>
<br/>
<!-- 按鈕 -->
<input type="reset" value="重置按鈕"/>
<input type="submit" value="提交按鈕"/>
<input type="button" value="普通按鈕"/>
<br/>
<!-- 圖片按鈕 -->
<input type="image" src="one.jpg" width="200px" heigth="200px"/>
<br/>
<button type="submit">提交</button>
<button type="reset">重置</button>
<br/>
<label for="profile">
個人簡介:
</label>
<!-- 多行文本域 -->
<textarea >本人已同意什么條款</textarea>
<br/>
<br/>
<br/>
<!-- 文件域 -->
<label for="upload">上傳頭像:</label>
<input type="file"/>
<!-- 郵箱 -->
<br/>
<label for="QQ郵箱">郵箱:</label>
<input type="email"/>
<br/>
<!-- 網(wǎng)址 -->
<label for="ur">網(wǎng)址:</label>
<input type="url"/>
<!-- 數(shù)字 -->
<br/>
<label for="shuzi">數(shù)字:</label>
<input type="number" name="shuzi" min="0" max="100" step="10"/>
<br/>
<label for="huakuai">滑塊:</label>
<input type="range" />
<!-- 搜索框 -->
<br/>
<label for="sousuo">搜索</label>
<input type="search"/>
<!-- 隱藏域 -->
<br/>
<input type="hidden"value="1">
<!-- 只讀:只能看不能修改,禁用:不能用 -->
<input value="我是只讀的" readonly/>
<input type="button" value="我是禁用的" disabled/>
<!-- palceholder默認提示 -->
<br/>
<input placeholder="默認提示框"/>
<br/>
<!-- 文本框內(nèi)容提示不能為空,否則不允許用戶提交表單(網(wǎng)頁上的必填項) -->
<input required="必填項"/>
<button type="submit">提交</button>
<br/>
<!-- 用戶輸入的內(nèi)容必須符合正則表達式所指的規(guī)則,否則就不能提交表單-->
<input required pattern="^1[3578]\d{9}"/>
<button type="submit">提交</button>
</form>
</body>
</html>
效果圖鏈接:file:///D:/ruanjian/VS/wenjianxiangmu/htmlThree/form.html
*請認真填寫需求信息,我們會在24小時內(nèi)與您取得聯(lián)系。