java中字符型和整型的转换问题
众所周知,java中int型和char型数据不像c语言中那样可以任意转换,即不可以将一个int型变量自动转换为char型,如下面代码中的演示:
public class TestSort{
public static void main(String args[]){
int x='a';//不会产生编译错误,因为'a'赋给x是隐式转换
System.out.println(x);
char ch=x;//会产生编译错误,因为x类型比ch优先级高,必须强制类型转换,但是在C语言中这样是可以的
System.out.println(ch);
}
}
但是看下面的代码:
public class TestSort{
public static void main(String args[]){
int x='a';
System.out.println(x);
char ch=97;//不会产生编译错误
System.out.println(ch);
}
}
上面代码不会产生任何编译错误,此处的97虽然在数学意义上是一个整数(注意整数和整型的区别),但是java语言中它被作为常数来对待,也就是说一个值为97的int型变量和97本身是不同的概念,97在没有和某个类型关联以前赋给ch是完全没有错误的。其实我们用char ch='a'给ch赋值的时候,'a'在内存中的存储值就是97。
相关文档:
JSON 即 Java
Script Object Natation,它是一种轻量级的数据交换
格式,非常适合于服务器
与 Java
Script 的交互。本文将快速讲解 JSON 格式,并通过代码示例演示如何分别在客户端和服务器
端进行 JSON 格式数据的处理。
Json必需的包
commons-httpclient-3.1.jar
commons-lang-2.4.jar
......
public class TreeNodes{
IList<BranchInfo> branchs = BranchInfoManager.getAllBranchInfos();
foreach(BranchInfo branch in branchs){
TreeNode branchNode = new TreeNodeCreate(branch.BranchName,branch.BranchId.toString(),"","~/Images/menuclose.gif");
  ......
Groovy supports a few neat ways to work with SQL more easily and to make SQL more Groovy. You can perform queries and SQL statements, passing in variables easily with proper handling of statements, connections and exception handling thanks to closures.
import groovy.sql.Sql
def foo = 'cheese ......
最初我们用 Java 写 JSP 的时候,几乎可以不触及异常,因为 Servlet 容器会把 API 抛出的异常包装成
ServletException 丢给容器去处理。再后来应用分层,代码中要处理的异常便多了,一般会转换成自定义的业务异常类,用
try-catch-throw
customerException-finally。再到如今各种框架日臻成熟,代码中显式的异常处理又渐 ......