Java试题.docx
《Java试题.docx》由会员分享,可在线阅读,更多相关《Java试题.docx(18页珍藏版)》请在冰豆网上搜索。
Java试题
博大正方公司
JAVA开发人员招聘试题
姓名:
分数:
一、基本概念题(共30分)
1、请说出2种J2EE服务器(2分)
2、什么是JSP(JavaServerPages)技术?
JSP技术是如何工作的?
(5分)
3、请说出JSP规范中定义的四种对象作用域。
(4分)
4.请说明下面两种JSP注释的区别。
(2分)
--COMMENT-->
<%--COMMENT--%>
5.填空(3分)
Directives语法:
<%___directive%>
Declarations语法:
<%___declaration%>
Expressions语法:
<%___expression%>
6.填空(5分)
当用户A,B两个用户先后调用同一个SERVLET,假定B用户在A用户不再使用此SERVLET之后才提交请求,请对以下流程排序
A、用户A发出HTMLPOST请求
B、SERVLET响应请求,并返回处理结果
C、初始化SERVLET,调用INIT方法
D、用户B发出HTMLPOST请求
E、装载SERVLET
_____________________
7.填空(4分)
在java程序中访问数据库一定要哪个包?
Ajava.sql
Bjava.database
Coracle.jdbc.driver
Djava.database.sql
8.填空(5分,每空1分)
classSimpleExample{
publicstaticvoidmain(__A__){
Stringurl=".......";
try{
class.forName(".....");
___B___b=DriverManager.getConnection(url,"user","password");
Stringsqlstr="select*fromtest";
___C___c=b.createStatement();
___D___d=c.executeQuery(sql);
.........
}catch(__E___e){
System.out.println("Error");
}
}
}
二、素质试题(共70分,每小题3.5分,多选或少选均不得分)
Question1:
Giventhefollowingclassdefinition:
classA{
protectedinti;
A(inti){
this.i=i;
}
}
Whichofthefollowingwouldbeavalidinnerclassforthisclass?
Selectallvalidanswers.
a)
classB{
}
b)
classBextendsA{
}
c)
classB{
B(){
System.out.println("i="+i);
}
}
d)
classB{
classA{
}
}
e)
classA{
}
Answer____________
Question2:
Whatstatementsaretrueconcerningthemethodnotify()thatisusedinconjunctionwithwait()?
Selectallvalidanswers.
a)ifthereismorethanonethreadwaitingonacondition,onlythethreadthathasbeenwaitingthelongestisnotified
b)ifthereismorethanonethreadwaitingonacondition,thereisnowaytopredictwhichthreadwillbenotifed
c)notify()isdefinedintheThreadclass
d)itisnotstrictlynecessarytoownthelockfortheobjectyouinvokenotify()for
e)notify()shouldonlybeinvokedfromwithinawhileloop
Answer____________
Question3:
Giventhefollowingclass:
classCounter{
publicintstartHere=1;
publicintendHere=100;
publicstaticvoidmain(String[]args){
newCounter().go();
}
voidgo(){
//A
Threadt=newThread(a);
t.start();
}
}
WhatblockofcodecanyoureplaceatlineAabovesothatthisprogramwillcountfromstartHeretoendHere?
Selectallvalidanswers.
a)
Runnablea=newRunnable(){
publicvoidrun(){
for(inti=startHere;i<=endHere;i++){
System.out.println(i);
}
}
};
b)
aimplementsRunnable{
publicvoidrun(){
for(inti=startHere;i<=endHere;i++){
System.out.println(i);
}
}
};
c)
Threada=newThread(){
publicvoidrun(){
for(inti=startHere;i<=endHere;i++){
System.out.println(i);
}
}
};
Answer____________
Question4:
Whatiswrittentothestandardoutputgiventhefollowingstatement:
System.out.println(4|7);
Selecttheonerightanswer.
a)4
b)5
c)6
d)7
e)0
Answer____________
Question5:
Giventhefollowingclass:
classCounter{
publicstaticvoidmain(String[]args){
Threadt=newThread(newCounterBehavior());
t.start();
}
}
WhichofthefollowingisavaliddefinitionofCounterBehaviorthatwouldmakeCounter’smain()methodcountfrom1to100,countingoncepersecond?
Selecttheonerightanswer.
a)ThisclassisaninnerclasstoCounter:
classCounterBehavior{
for(inti=1;i<=100;i++);
try{
System.out.println(i);
Thread.sleep(1000);
}catch(InterruptedExceptionx){}
}
}
b)ThisclassisaninnerclasstoCounter:
classCounterBehaviorimplementsRunnable{
publicvoidrun(){
for(inti=1;i<=100;i++);
try{
System.out.println(i);
Thread.sleep(1000);
}catch(InterruptedExceptionx){}
}
}
}
c)Thisclassisatop-levelclass:
staticclassCounterBehaviorimplementsRunnable{
publicvoidrun(){
try{
for(inti=1;i<=100;i++){
System.out.println(i);
Thread.sleep(1000);
}
}catch(InterruptedExceptionx){}
}
}
Answer____________
Question6:
Giventhefollowingclassdefinition:
classA{
publicintx;
privateinty;
classB{
protectedvoidmethod1(){
}
classC{
privatevoidmethod2(){
}
}
}
}
classDextendsA{
publicfloatz;
}
Whatcanmethod2()accessdirectly,withoutareferencetoanotherinstance?
Selectallvalidanswers.
a)thevariablexdefinedinA
b)thevariableydefinedinA
c)method1definedinB
d)thevariablezdefinedinD
Answer____________
Question7:
Youhavean8-bitfileusingthecharactersetdefinedbyISO8859-8.YouarewritinganapplicationtodisplaythisfileinaTextArea.Thelocalencodingisalreadysetto8859-8.Howcanyouwriteachunkofcodet