收藏 分销(赏)

上海交通银行笔试题及答案.docx

上传人:a199****6536 文档编号:9874393 上传时间:2025-04-11 格式:DOCX 页数:15 大小:26.66KB 下载积分:8 金币
下载 相关 举报
上海交通银行笔试题及答案.docx_第1页
第1页 / 共15页
上海交通银行笔试题及答案.docx_第2页
第2页 / 共15页


点击查看更多>>
资源描述
上海交通银行笔试题及答案 资料仅供参考 选择题: 1. 下面两段代码,输出为() public class A { { System.out.println("A"); } static{ System.out.println("B"); } A(){ System.out.println("C"); } } public class B extends A{ { System.out.println("D"); } static{ System.out.println("E"); } B(){ System.out.println("F"); } public static void main(String [] args){ B b = new B(); System.out.println("G"); } } 参考答案: B E A C D F G 2. spring 配置事物的属性是 参考答案: 事务属性一般由事务的传播行为,事务的隔离级别,事务的超时值和事务只读标志组成。 Spring在TransactionDefinition接口中定义这些属性,以供PlatfromTransactionManager使用, 3. ajax 核心对象 xmlhttprequest 对象 参考答案:XMLHttpRequest对象在Ajax中占据着十分重要的地位,因为一般意义上的和服务器进行交互是经过提交表单的形式,而在Ajax中的客户端经过XMLHttpRequest对象实现与服务器的通信。也就是说正是因为XMLHttpRequest才使得Ajax得以实现,于是我们的与服务器的交互速度明显提升,消除了令人头疼的等待之后用户体验便也更加良好。 4. 在执行下面两条SQL语句后: create table t1 ( c1 char(10) not null primary key, c2 int, c3 char(10), c4 char(10) not null, constraint c4 unique (c1,c4) ) create index index1 on t1 (c2 asc) 表t1上有几个索引?() 参考答案:3 5. LDAP是指什么? 参考答案:轻型目录访问协议,即Lightweight Directory Access Protocol 是一个访问在线目录服务的协议。 目录是一组具有类似属性、以一定逻辑和层次组合的信息。常见的例子是电话簿,由以字母顺序排列的名字、地址和电话号码组成。最新版本的LDAP协议由RFC 4511所定义。 6. 实现DAO的设计模式有哪些? 参考答案: Data Accessor 模式和 Active Domain Object 模式 7. 使用“游标稳定性”可能会出现什么现象情况?(不可重复读、幻像读) 参考答案: 可能会出现不可重复读和幻像读现象 8. HashTable、Vector、TreeSet、LinkedList 哪些属于线程安全的? 参考答案: HashMap是线程安全的Map,Vector是线程安全的ArrayList TreeSet和LinkedList都是非线程安全的 9. 标准Statement的类对象有哪些? 参考答案: Statement PreparedStatement CallableStatement 10. 泳道图属于那种类图? 参考答案:活动图 11. transient变量,在以下那几个类中使用? (serialization) 参考答案: serialization 选择题知识点:J2EE;EJB;JPA;SSH;IBatis;AIX;WAS;Statement;数据库日志满;CPU瓶颈;泳道图;静态类;事物;spring;游标稳定性;MVC;设计模式 编程题 1. 编写一个人民币金额数字转换成大写的函数,无小数,最大。 例如:12304 转为 壹万两仟三佰零四元整 40000 转为 4万元整 参考答案: public class Num2Rmb {     private String[] hanArr={"零","壹","贰","叁","肆","伍",             "陆","柒","捌","玖"};     private String[] unitArr={"拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"};       private String toHanStr(String numStr)     {         String result="";         int numLen=numStr.length();         for (int i=0;i<numLen; i++)         {             int num=numStr.charAt(i)-48;             if(i!=numLen-1 && num!=0)             {                 result+=hanArr[num]+unitArr[numLen-2-i];             }             else             {                 result+=hanArr[num];             }         }         return result;     }     public static void main(String[] args)     {         Num2Rmb nr = new Num2Rmb();                   System.out.println(nr.toHanStr(""));     } } 2. 字符串截取,中文不会被截取半个。 例如:我和你ABC 截取4位 : 我和你A 我和你ABC 截取2位: 我和 参考答案: public static String subString(String str, int len) { if (str == null && "".equals(str)) { return null; } // 将字符串中的char数组转换成指定编码方式的byte数组的函数 byte[] strBytes = null; try { strBytes = str.getBytes("GBK"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } // 得到字符串的长度,判断截取字符串的长度是否在判断的范围内,否则返回原串 int strLen = strBytes.length; if (len >= strLen || len < 1) { return str; } System.out.println("strBytes.length=" + strBytes.length); System.out.println("len=" + len); int count = 0; for (int i = 0; i < len; i++) { // 将每个字节数组转换为整型数,以为后面根据值的正负来判断是否为汉字 int value = strBytes[i]; System.out.print(value + ","); // 我ABC你 -50,-46,65,66,67,-60,-29 // 对于第一种情况: // 注,一个函数转换成整型数就为两个负整数,上面的”我ABC你“, // 转换成整型数就为-50,-46,65,66,67,-60,-29,可是len=6,因此截取下来的就是-50,-46,65,66,67,-60,count就为3 // 如果是汉字(负),则统计截取字符串中的汉字所占字节数 if (value < 0) { count++; } System.out.println("zh count=" + count); } // 依据判断给定的字符串是否含有汉字,利用String类的substring()方法来截取不同的长度 // 根据所统计的字节数,判断截取到字符是否为半个汉字,奇数为半个汉字 if (count % 2 != 0) { // 如果在截取长度为1时,则将该汉字取出, // 其它情况则不截取这里的截取长度则按字符长度截取(截取字节长度数-截取汉字字节数/2-截取到的半个汉字的字节数) len = (len == 1) ? len : len - count / 2 - 1; // len=6-3/2-1=4 我ABC // System.out.println("处理后的len="+len); } else { // 截取字符长度为字节长度-汉字所占字节长度/2(汉字占两个字节) len = len - (count / 2); } return str.substring(0, len); } 3. 个人所得税的计算,不同阶段的工资给出不同阶段的个人所得税的交付。输入工资salary 计算出应付的税款tax。 计算公式:tax = n * ( salary – 850 ) n为税率 税率表为: 工资 税率 salary<850 0% 850<salary<3000 5% 3000<salary<5000 10% 5000<salary<8000 15% 8000<salary<10000 20% 10000<salary 25% 参考答案: Double cal(Double salary) { if (salary < 850) { // } else if (salary > 850 && salary < 3000) { salary = 0.05 * (salary - 850d); } else if (salary > 3000 && salary < 5000) { salary = 0.1 * (salary - 850d); } else if (salary > 5000 && salary < 8000) { salary = 0.15 * (salary - 850d); } else if (salary > 8000 && salary < 10000) { salary = 0.2 * (salary - 850d); } else if (salary > 10000) { salary = 0.22 * (salary - 850d); } return salary; } 问答题 1. 使用系统设计的思想实现程序对不同语言,不同时区的支持。 参考:对不同语言,不同时区的支持,涉及国际化和本地化。 国际化是指在设计软件时,将软件与特定语言及地区脱钩的过程。当软件被移植到不同的语言地区时,软件本身不用做内部工程上的改变或修正。本地化则是指当移植软件时,加上与特定区域设置有关的资讯和翻译文件的过程。 一般作法是将文本和其它环境相关的资源与程序代码相分离。这样在理想的情况下,应对变化的环境时无需修改代码,只要修改资源,从而显著简化了工作。 2. 什么是快速迭代失效?如何解决? 参考: Vector等Collection类,都有类似的说明:由 Vector 的 iterator 和 listIterator 方法所返回的迭代器是快速失败的:如果在迭代器创立后的任意时间从结构上修改了向量(经过迭代器自身的 remove 或 add 方法之外的任何其它方式),则迭代器将抛出 ConcurrentModificationException。因此,面对并发的修改,迭代器很快就完全失败,而不是冒着在将来不确定的时间任意发生不确定行为的风险。 解决办法:不适用Collection自身的remove()方法,而使用Iterator本身的方法remove()来删除对象,因为这样子能够删掉原对象,同时当前迭代对象的索引也得到同步。 3. 下面是一段对数据库异常处理的代码: public class DBUtil { private static final int CAN_CONNECT = 5001; private static final int SQL_ERROR = 5002; public void exceptionHandle(int exception){ switch(exception){ case CAN_CONNECT : { //do something... System.out.println("The DB can't be connected...."); } case SQL_ERROR : { //do something... System.out.println("The SQL is Error..."); } default : //do something... System.out.println("Other reasons..."); } } } 若需要添加其它错误码,则只需添加case分支即可。可是在异常非常多时这种方式处理会造成代码的冗余。而且经常改动已经完成的代码还很可能会带来其它代码块的错误,带来未知的风险。请使用设计模式改造该代码。 参考: 可用策略模式改造。 知识点:多态、反射 一:枚举类: package strategy; public enum ErrorTypeEnum { CANNOT_CONNECT(5001, "The DB can't be connected...."), SQL_ERROR(5002, "The SQL is Error..."); /** * 状态值 */ private int value; /** * 类型描述 */ private String description; private ErrorTypeEnum(int value, String description) { this.value = value; this.description = description; } public int value() { return value; } public String description() { return description; } public static ErrorTypeEnum valueOf(int value) { for (ErrorTypeEnum type : ErrorTypeEnum.values()) { if (type.value() == value) { return type; } } return null; } } 二:Strategy接口: package strategy; public interface Strategy { // 可添加通用方法 String outline(); } 三:Cannot_ConnectStrategy类: package strategy; public class Cannot_ConnectStrategy implements Strategy { @Override public String outline() { return "The DB can't be connected...."; } } 四:Sql_ErrorStrategy类: package strategy; public class Sql_ErrorStrategy implements Strategy { @Override public String outline() { return "The SQL is Error..."; } } 五:Context类: package strategy; public class Context { private Strategy strategy; public String contextOutline(int exception) { strategy = StrategyFactory.getInstance().creator(exception); if (strategy != null) { return strategy.outline(); } else { return "Other reasons..."; } } public Strategy getStrategy() { return strategy; } public void setStrategy(Strategy strategy) { this.strategy = strategy; } } 六:Client类,测试 package strategy; public class Client { public static void exceptionHandle(int exception){ Context context = new Context(); String outline = context.contextOutline(exception); System.out.println(outline); } public static void main(String[] args) { exceptionHandle(5001); } }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 考试专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服