Java SE 异常
package demo;
class TestA{
public int devide(int x,int y) throws ArithmeticException , DevideByMinusException{
if(y<0)
throw new DevideByMinusException("被除数为负",y);
int result=x/y;
return result;
}
}
public class TestException {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
try{
// int result=new TestA().devide(3,0);
int result=new TestA().devide(3,-1);
System.out.println(result);
}catch(ArithmeticException e){
System.out.println("in >>ArithmeticException<< ");
System.out.println(e.getMessage());
// e.printStackTrace();
}catch(DevideByMinusException e){
System.out.println("in >>DevideByMinusException<< ");
System.out.println(e.getMessage());
// e.printStackTrace();
}
System.out.println("program is running here,that is normal!");
}
}
class DevideByMinusException extends Exception{
int devisor;
public DevideByMinusException(String msg,int devisor){
super(msg);
this.devisor=devisor;
}
public int getDevisor(){
return devisor;
}
}
相关文档:
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......
1.JAVA连接ACCESS数据库
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ="+application.getRealPath("/Data/ReportDemo.mdb");
Connection conn = DriverManager.getConnection(url,"","");
在上面的连接方法中,所涉及到的参数含义如下所示 ......
Java传递参数有两种 :值传递,引用传递
一般引用类型 是引用传递,值类型是值传递
值类型是原始数据类型 包括 int,byte,char short long,boolean,float,double
引用类型就是一般的class类 当然也包括原始数据的封装类型 比如int的
封装类型为Integer
一般情况下:
值传递:
例子 1 public void show1(int str ......
Reflection 的简单应用,包括field, method,constructor的应用。
package com.gaoqian.reflection;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Typ ......