版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、开发必备测试题集说明:(1)“”表示是初级题;(2)“”表示是中级题;(3)“”表示是高级题。目录开发必备测试题集1一、JAVA上机测试题3题1.类模块动态加载()3题2.自定义对象比较()3题3.自定义对象序列化()4题4.Java重载()4题5.单实例类()5题6.正则表达式()6题7.数据输出()6题8.URL调用()6题9.HttpURLConnection操作()7题10.数据类型转换()9题11.字符集转换()11题12.字符串截取()12题13.写一个方法实现字符串左对齐()13题14.Byte转字符串()13题15.递归算法()14题16.写文件操作()14题17.文件内容复制
2、()16题18.采用NIO方式实现文件copy()17题19.Excel操作()18题20.排序操作()24题21.用JAVA实现插入法排序()25题22.金额转换()26题23.XML解析()30题24.SOCKET编程()32题25.SOCKET编程()34题26.SOCKET编程()39题27.JDBC操作()41题28.数据库操作()43题29.数据库存储过程调用()54题30.解压缩操作()56题31.计算矩形面积()57题32.时间处理()58题33.配置文件操作()60题34.ArrayList操作()61题35.目录操作1:目录建立()62题36.目录操作2:目录检查与删除()
3、62题37.目录操作3:目录重命名()63题38.目录操作4:目录遍历()63题39.接口实现()64题40.JAVA中实现获得本机IP地址和名称()68二、Jsp上机测试题69题41.字符串处理()69题42.字符串处理()69三、Struts上机测试题70题43.Action操作()70四、Hibernate上机测试题75题44.Hibernate基本操作()75五、Oracle上机测试题87题45.Sql语句编写()87题46.Sql语句编写()87题47.Sql语句编写()87题48.Sql语句编写(/)87题49.Sql语句编写()88题50.Sql语句编写()88题51.外连接查询
4、()89题52.替换空值()89六、Javascript上机测试题89题53.去掉字符串的前后空白字符(/)89题54.判断输入字符串是否是纯数字()90题55.验证是否为有效日期格式(yyyy-MM-dd)()90题56.日期加减()91题57.动态生成超链接()92题58.显示当前时间()92题59.限制文本框的输入()93题60.解析XML并生成表格()93题61.助记码输入框的实现()95题62.单击按钮,checkbox全选中()96题63.表格行调换()97题64.动态样式变化()98题65.Select对象操作()100题66.手机号码有效性验证()101七、HTML+CSS上机
5、测试题103题67.静态页面编写()103一、 JAVA上机测试题题1. 类模块动态加载()请写出两种加载类模块“com.cplatform.test”并实例化对象的方法?类模块路径:d:/test/lib/test.jar答案:方法1:Class c = Class.forName(com.cplatform.test); Test object = (Test)c.newInstance();方法2:URL url = new URL(file:/d:/test/lib/); URLClassLoader urlCL = new URLClassLoader(new URLurl); Cl
6、ass c = urlCL.loadClass(com.cplatform.test); Test object = (Test)c.newInstance();题2. 自定义对象比较()自定义对象Test2public class Test2 public String s;public int n;public Test2()请写出如何比较两个Test2对象是否相等?答案:public class Test2 public String s;public int n;public Test2(String s1,int n1)s=s1;n=n1public int hashCode()re
7、turn s.hashCode();public boolean equals(Object obj)return (this.s.equals(Test2)obj).s) &this.n = (Test2)obj).n);Test2 t1 = new Test2(“test”,1);Test2 t2 = new Test2(“test”,1);Test2 t3 = new Test2(“test2”,1);System.out.println(“t1 equals t2 is:” + t1. equals(t2);System.out.println(“t1 equals t3 is:” +
8、 t1. equals(t3);System.out.println(“t3 equals t2 is:” + t3. equals(t2);题3. 自定义对象序列化()自定义对象Test2public class Test2 public String s;public int n;public Test2()请写出如何序列化读写Test2对象的方法?答案:public class Test2 implements Serializablepublic String s;public int n;public Test2(String s1,int n1)s = s1;n = n1;Test
9、2 t = new Test2(test,1);FileOutputStream fos = new FileOutputStream(c:tempt.txt);ObjectOutputStream oos = new ObjectOutputStream(fos);oos.writeObject(t);oos.close();FileInputStream fis = new FileInputStream(c:tempt.txt);ObjectInputStream ois = new ObjectInputStream(fis);Test2 tt = (Test2) ois.readOb
10、ject();ois.close();题4. Java重载()设计Application字符界面程序,定义三个重载方法mol并调用。三个方法分别为:接收一个int参数,执行平方运算并输出结果;接收两个int参数,执行相乘运算并输出结果;接收一个字符串参数,输出该字符串参数信息。要求在main( )方法中分别用参数区别调用这三个方法。如调用格式为: mol(128); mol(12,8); mol(“teacher”); 则可输出:128的平方等于16384 12*8=96 Hello,teacher!答案:public class Test public int mol(int i) retu
11、rn i*i; public int mol(int i,int j) return i*j; public void mol(String str) System.out.println(Hello,+str+!); public static void main(String args) Test t=new Test(); System.out.println(128的平方等于+t.mol(128); System.out.println(12*8=+t.mol(12,8); t.mol(teacher); 题5. 单实例类()请写出一个简单的单实例类答案:public class Bl
12、ackListprivate static BlackList instance = null;public static synchronized BlackList getInstance()if (instance = null)instance = new BlackList();return instance;private BlackList()题6. 正则表达式()请写出输入条件为:1012位的数字或字母的正则表达式答案:a-z0-9A-Z 10,12或 a-z0-9A-Z 10,12$题7. 数据输出()指定变量b=50为字节类型,变量f=0.55F为单精度实型,将这两个变量打
13、印输出。答案:import java.io.*;public class Assignpublic static void main(String args) int b=50; float f=0.55F;System.out.println(b=+b);System.out.println(f=+f);题8. URL调用()写出一个HTTP POST调用的方法,输入参数(URL,POST请求的内容,超时时间),返回,HTTP RESP的内容。答案:public static String getHttpResp(String url,String sParam,String timeOut
14、) throws IOException URL urlServer; String result=null; try if(sParam!=null & sParam.equals() url=url+sParam; urlServer=new URL(url); System.out.println(url) ; HttpURLConnection urlConn=(HttpURLConnection)urlServer.openConnection(); urlConn.setDoOutput(true); urlConn.setDoInput(true); urlConn.setReq
15、uestMethod(GET); urlConn.setUseCaches(true); result=urlConn. getResponseMessage (); catch(IOException ex) ex.printStackTrace(); throw ex; catch(Exception ex) ex.printStackTrace(); Log.printError(ex,Tools.getHttpResp(),Param.errorFile); return result; 题9. HttpURLConnection操作()使用HttpURLConnection实现将WE
16、B站点上的图片下载到本地,假设图片URL为:1/xglloa/image/img01.jpg答案:import .*;import java.util.*;import java.io.*;public class urlConnHttpURLConnection hcon = null;public urlConn()public void openConn()tryhcon = (HttpURLConnection) new URL(1/xglloa/image/img01.jpg).openConne
17、ction();hcon.connect(); catch (Exception e)e.printStackTrace();public void down()tryBufferedInputStream in = new BufferedInputStream(hcon.getInputStream();BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(d:test.jpg);byte b = new byte1024 * 4;int i = in.read(b, 0, b.length);wh
18、ile (i != -1)out.write(b, 0, i);out.flush();i = in.read(b, 0, b.length);out.close();in.close(); catch (Exception e)e.printStackTrace();System.out.println(e.getMessage();OutputStream out = null;InputStream in = null;public static void main(String args)urlConn t = new urlConn();t.openConn();t.down();题
19、10. 数据类型转换()实现以下几种类型转换方法:byte转int,byte转long,int转byte,long转byte,byte转16进制答案:public class NumericOper private static String HexCode = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f ; private NumericOper() public static String byteToHexString(byte b) int n = b; if(n 0) n = 256 + n; int d1 = n / 16; int
20、 d2 = n % 16; return HexCoded1.concat(HexCoded2); public static String byteArrayToHexString(byte b) String result = ; for(int i = 0; i b.length; i+) result = result.concat(byteToHexString(bi); return result; public static int byte2int(byte b, int offset) return boffset + 3 & 0xff | (boffset + 2 & 0x
21、ff) 8 | (boffset + 1 & 0xff) 16 | (boffset & 0xff) 24; public static int byte2int(byte b) return b3 & 0xff | (b2 & 0xff) 8 | (b1 & 0xff) 16 | (b0 & 0xff) 24; public static long byte2long(byte b) return (long)b7 & (long)255 | (long)b6 & (long)255) 8 | (long)b5 & (long)255) 16 | (long)b4 & (long)255)
22、24 | (long)b3 & (long)255) 32 | (long)b2 & (long)255) 40 | (long)b1 & (long)255) 48 | (long)b0 56; public static long byte2long(byte b, int offset) return (long)boffset + 7 & (long)255 | (long)boffset + 6 & (long)255) 8 | (long)boffset + 5 & (long)255) 16 | (long)boffset + 4 & (long)255) 24 | (long)
23、boffset + 3 & (long)255) 32 | (long)boffset + 2 & (long)255) 40 | (long)boffset + 1 & (long)255) 48 | (long)boffset 24); b1 = (byte)(n 16); b2 = (byte)(n 8); b3 = (byte)n; return b; /* *n 为待转数据,buf为转换后的数据,offset为buf中转换的起始点 * 转换后数据从低到高位 */ public static void int2byte(int n, byte buf, int offset) bufo
24、ffset = (byte)(n 24); bufoffset + 1 = (byte)(n 16); bufoffset + 2 = (byte)(n 8); bufoffset + 3 = (byte)n; public static byte short2byte(int n) byte b = new byte2; b0 = (byte)(n 8); b1 = (byte)n; return b; public static void short2byte(int n, byte buf, int offset) bufoffset = (byte)(n 8); bufoffset +
25、 1 = (byte)n; public static byte long2byte(long n) byte b = new byte8; b0 = (byte)(int)(n 56); b1 = (byte)(int)(n 48); b2 = (byte)(int)(n 40); b3 = (byte)(int)(n 32); b4 = (byte)(int)(n 24); b5 = (byte)(int)(n 16); b6 = (byte)(int)(n 8); b7 = (byte)(int)n; return b; public static void long2byte(long
26、 n, byte buf, int offset) bufoffset = (byte)(int)(n 56); bufoffset + 1 = (byte)(int)(n 48); bufoffset + 2 = (byte)(int)(n 40); bufoffset + 3 = (byte)(int)(n 32); bufoffset + 4 = (byte)(int)(n 24); bufoffset + 5 = (byte)(int)(n 16); bufoffset + 6 = (byte)(int)(n 8); bufoffset + 7 = (byte)(int)n; 题11.
27、 字符集转换()请写出字符串在gb18030和ISO-8859-1之间转换的方法?答案:/ ISO-8859-1转换成gb18030new String(string1.getBytes(iso-8859-1), gb18030);/ gb18030转换成ISO-8859-1new String(string2.getBytes(gb18030), iso-8859-1);题12. 字符串截取()编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串。 但是要保证汉字不被截半个,如我ABC4,应该截为我AB,输入我ABC汉DEF,6,应该输出为我ABC而不是我ABC+汉的
28、半个。答案:package test; class SplitString String SplitStr; int SplitByte; public SplitString(String str,int bytes) SplitStr=str; SplitByte=bytes; System.out.println(The String is:+SplitStr+;SplitBytes=+SplitByte); public void SplitIt() int loopCount; loopCount=(SplitStr.length()%SplitByte=0)?(SplitStr.l
29、ength()/SplitByte):(SplitStr.length()/SplitByte+1); System.out.println(Will Split into +loopCount); for (int i=1;i=loopCount ;i+ ) if (i=loopCount) System.out.println(SplitStr.substring(i-1)*SplitByte,SplitStr.length(); else System.out.println(SplitStr.substring(i-1)*SplitByte,(i*SplitByte); public
30、static void main(String args) SplitString ss = new SplitString(test中dd文dsaf中男大343n中国43中国人0ewlfls=103,4); ss.SplitIt(); 题13. 写一个方法实现字符串左对齐()答案:public class StringUtilpublic static String lpad(String oldStr, String padChar, int length)StringBuffer str = new StringBuffer();str.append(padding(oldStr, pa
31、dChar, length);str.append(oldStr);return str.toString();public static String rpad(String oldStr, String padChar, int length)StringBuffer str = new StringBuffer();str.append(oldStr);str.append(padding(oldStr, padChar, length);return str.toString();private static String padding(String oldStr, String p
32、adChar, int length)StringBuffer str = new StringBuffer();for (int i = 0; i length - oldStr.length(); i+)str.append(padChar);return str.toString();题14. Byte转字符串()请实现将一个字节数组转换成字符串数组,如:0xA3,0xB4,0x01,0x34 转换成字符串“A3B40134”答案:private static String HexCode= 0,1,2,3,4,5,6,7,8,9, a,b,c,d,e,f;public static S
33、tring byteToHexString(byte b) int n = b; if(n 0) n = 256 + n; int d1 = n / 16; int d2 = n % 16; return HexCoded1 + HexCoded2;public static String byteArrayToHexString(byte b) String result = ; for(int i=0;i1时,F(n) = n * F(n-1)请用递归算法实现当n=100时候F(n)的值答案:System.out.println(F(100) = + func(100);public st
34、atic int func(int x) if (x 1) return (func(x - 1) * x; else return 1; 题16. 写文件操作()请写出向文件中写入内容的方法。答案:private static void printToFile(String msg,String fileName,boolean flag) /打印到文件中 BufferedWriter mBufWriter=null; try if(!createFile(fileName) return; FileWriter fileWriter=new FileWriter(fileName,flag
35、); mBufWriter=new BufferedWriter(fileWriter); mBufWriter.write(msg); mBufWriter.newLine(); mBufWriter.flush(); mBufWriter.close(); catch(Throwable e) try mBufWriter.close(); catch(Throwable t) ; return; public static boolean createFile(String fileName) throws IOException,Exception File file=new File
36、(fileName); if(file.exists() /* does file exist? If so, can it be written to */ if(file.canWrite()=false) return false; else String path=null; /* Does not exist. Create the directories */ int firstSlash=fileName.indexOf(File.separatorChar); int finalSlash=fileName.lastIndexOf(File.separatorChar); if
37、(finalSlash=0) /* error, not valid path */ else if(finalSlash=1) /* UNIX root dir */ path=File.separator; else if(firstSlash=finalSlash) /* for example c: Then make sure slash is part of path */ path=fileName.substring(0,finalSlash+1); else path=fileName.substring(0,finalSlash); File dir=new File(pa
38、th); dir.mkdirs(); return true; 题17. 文件内容复制()编写程序,完成文件复制功能,即将a.txt文件内容复制到b.txt文件中去。答案如下:import java.io.*; /*描述:将a.txt文件内容复制到b.txt文件中去。*/public class copyfile public static void main(String args) String oldPath=c:testa.txt; String newPath=c:testb.txt; try int bytesum = 0; int byteread = 0; File oldfi
39、le = new File(oldPath); /判断文件存是否存在-存在if (oldfile.exists() /读入a文件 InputStream inStream = new FileInputStream(oldPath); /读入b文件 FileOutputStream fs = new FileOutputStream(newPath); byte buffer = new byte1444; int length; while ( (byteread = inStream.read(buffer) != -1) /字节数 文件大小bytesum += byteread; /输出
40、到控制台System.out.println(bytesum); /写入文件fs.write(buffer, 0, byteread); /关闭文件流inStream.close(); catch (Exception e) System.out.println(复制单个文件操作出错); e.printStackTrace(); 题18. 采用NIO方式实现文件copy()答案:import java.io.*;import java.nio.*;import java.nio.channels.*;public class CopyFile public void copy (String
41、src,String dest) tryFileChannel fin = new FileInputStream(src).getChannel();FileChannel fout = new FileOutputStream(dest).getChannel();ByteBuffer buf = ByteBuffer.allocate(1024);long t = System.currentTimeMillis();System.out.println(t);while(fin.read(buf) != -1) buf.flip();fout.write(buf);buf.clear(
42、);System.out.println(System.currentTimeMillis()-t);catch (Exception e)public static void main(String args) new CopyFile().copy(args0, args1);题19. Excel操作()写一个Excel类,实现excel文件的读取和写入答案:import java.util.*;import java.io.*;import jxl.*;import jxl.write.*;/* * 提供了简单的的Excel读取和写入的方法 * Title: * Description:
43、 * Copyright: Copyright (c) 2004 * Company: * author * version 1.0 */public class Excel int sheetCount = 1; /excel工作簿,默认为1 WritableWorkbook wwb = null; /构建Workbook对象,只读Workbook对象 Vector vSheet = null; /* * 无参构造函数,生成默认名字的excel文件 */ public Excel() this(noName.excel); /* * 带有一个String类型参数的构造函数 * param fileName String 将要生成的excel文件名 */ public Excel(String fileName) try wwb = Workbook.createWorkbook(new File(fileName); vSheet = new Vector(5); catch (Exception e) /* * 带有一个File类
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025无锡科技职业学院教师招聘考试题目及答案
- 2025江西冶金职业技术学院教师招聘考试题目及答案
- 2025成都医学院教师招聘考试题目及答案
- 2026年辽宁高三上学期语文预测卷基础及答案
- 辽宁地理省统考试题及答案
- 2026四川九州电子科技股份有限公司招聘技安管理岗2人建设考试备考题库及答案解析
- 2026年陕西中烟工业招聘岗位表(汉中卷烟厂招18人)建设笔试备考题库及答案解析
- 2026年安庆安徽省岳顺人力资源服务有限公司公开招聘8名建设笔试备考题库及答案解析
- 2026湖北武汉城市公共设施运营管理集团有限公司招聘6人建设笔试备考题库及答案解析
- 2026江苏连云港市总工会招聘工会社会工作者17人建设考试备考题库及答案解析
- 白鹤滩500千伏配套工程温升改造工程对四川螺髻山省级自然保护区影响评价报告
- 外科学教学课件:颈、腰椎退行性疾病
- 天耀中华合唱简谱大剧院版
- 新生儿危重患者的抢救配合课件
- 石油化工行业新工艺、新技术与新产品
- 房地产户型分析与鉴赏
- 篮球往返绕杆运球教学设计
- 导管相关血流感染预防与控制指南
- 射频连接器与电缆组件
- GB/T 29863-2023服装制图
- 工程材料及成形技术基础塑性加工
评论
0/150
提交评论