B.((x<100)&&(x>1))||(x<0)
C.((x<100)&&(x>1))&&(x<0)
D.(1>x>100)||(x<0)
9.Whichofthefollowingisthecorrectexpressionofcharactera?
A.'a'
B."a"
C.'\000a'
D.Noneoftheabove.
10.Whichofthefollowingstatementprintssmith\exam1\test.txt?
A.System.out.println("smith\exam1\test.txt");
B.System.out.println("smith\\exam1\\test.txt");
C.System.out.println("smith\"exam1\"test.txt");
D.System.out.println("smith"\exam1"\test.txt");
11.Supposeiisaninttypevariable.WhichofthefollowingstatementsdisplaythecharacterwhoseUnicodeisstoredinvariablei?
A.System.out.println(i);
B.System.out.println((char)i);
C.System.out.println((int)i);
D.System.out.println(i+"");
12.TheUnicodeof'a'is97.WhatistheUnicodefor'c'?
A.96
B.97
C.98
D.99
13.Whichofthefollowingisaconstant,accordingtoJavanamingconventions?
A.MAX_VALUE
B.Test
C.read
D.ReadInt
14.Whichofthefollowingassignmentstatementsisillegal?
A.floatf=-34;
B.intt=23;
C.shorts=10;
D.floatf=34.0;
15.AJavastatementendswitha__________.
A.comma(,)
B.semicolon(;)
C.period(.)
D.closingbrace
16.TheassignmentoperatorinJavais__________.
A.:
=
B.=
C.==
D.<-
17.Supposemandrareintegers.WhatisthecorrectJavaexpressionform/r^2toobtainafloatingpointresultvalue?
(r^2denotesrraisedtothepowerof2).
A.m/r*r
B.m/(r*r)
C.1.0*m/r*r
D.1.0*m/(r*r)
18.Whichofthesedatatypesrequirestheleastamountofmemory?
A.float
B.double
C.short
D.byte
19.Whichofthefollowingoperatorshasthehighestprecedence?
A.casting
B.+
C.*
D./
20.Anintvariablecanhold__________.
A.'x'
B.93
C.98.3
D.true
E.aandb
21.Whichofthefollowingassignmentstatementsiscorrecttoassigncharacter5toc?
A.charc='5';
B.charc=5;
C.charc="5";
D.charc="344";
22.NotethattheUnicodeforcharacterAis65.Theexpression"A"+1evaluatesto________.
A.66
B.B
C.A1
D.Illegalexpression
23.ThenotequalcomparisonoperatorinJavais__________.
A.<>
B.!
=
C.!
==
D.^=
24.Ifyouattempttoaddanint,abyte,along,andadouble,theresultwillbea__________value.
A.byte
B.int;
C.long;
D.double;
25.Whatisthevalueof(double)5/2?
A.2;
B.2.5;
C.3;
D.2.0;
26.Whatisthevalueof(double)(5/2)?
A.2;
B.2.5;
C.3;
D.2.0;
27.Analyzethefollowingcode.
publicclassTest{
publicstaticvoidmain(String[]args){
intmonth=09;
System.out.println("monthis"+month);
}
}
A.Theprogramdisplaysmonthis09
B.Theprogramdisplaysmonthis9
C.Theprogramdisplaysmonthis9.0
D.Theprogramhasasyntaxerror,because09isanincorrectliteralvalue.
28.Toassignadoublevariabledtoafloatvariablex,youwrite
A.x=(long)d
B.x=(int)d;
C.x=d;
D.x=(float)d;
29.whatisydisplayedinthefollowingcode?
publicclassTest1{
publicstaticvoidmain(String[]args){
intx=1;
inty=x=x+1;
System.out.println("yis"+y);
}
}
A.yis0.
B.yis1becausexisassignedtoyfirst.
C.yis2becausex+1isassignedtoxandthenxisassignedtoy.
D.Theprogramhasasyntaxerrorsincexisredeclaredinthestatementinty=x=x+1.
30.Ifaprogramcompilesfine,butitterminatesabnormallyatruntime,thentheprogramsuffers__________.
A.asyntaxerror
B.aruntimeerror
C.alogicerror
31.Supposex=0andy=0whatisxafterevaluatingtheexpression(y>0)&(1>x++).
A.0
B.-1
C.1
32.Supposex=0andy=0whatisxafterevaluatingtheexpression(y>0)&&(1>x++).
A.0
B.-1
C.1
33.SupposeyoudefineaJavaclassasfollows:
publicclassTest{
}
Inordertocompilethisclass,theclassshouldbestoredinafilenamed
A.Test.class
B.Test.doc
C.Test.txt
D.Test.java
E.Anynamewithextension.java
34.ThecommandtocompileaclassinthefileTest.javais
A.javaTest
B.javaTest.java
C.javacTest.java
D.javacTest
E.JAVACTest.java
35.WhichJDKcommandiscorrecttorunaJavaapplicationinByteCode.class?
A.javaByteCode
B.javaByteCode.class
C.javacByteCode.java
D.javacByteCode
E.JAVACByteCode
36.Whatis1%2?
A.0
B.1
C.2
37.Whatis"Welcome"+1+1*2?
A.Welcome11*2
B.Welcome4
C.Welcome12
D.Welcome3
38.Whatistheprintoutofthefollowingcode:
doublex=10.1;
inty=(int)x;
System.out.println("xis"+x+"andyis"+y);
A.xis10andyis10
B.xis10.0andyis10.0
C.xis11andyis11
D.xis10.1andyis10
E.xis10.1andyis10.0
39.Whichofthefollowingcodedisplaystheareaofacircleiftheradiusispositive.
A.if(radius!
=0)System.out.println(radius*radius*Math.PI);
B.if(radius>=0)System.out.println(radius*radius*Math.PI);
C.if(radius>0)System.out.println(radius*radius*Math.PI);
D.if(radius<=0)System.out.println(radius*radius*Math.PI);
40.Supposex=1,y=-1,andz=1.Whatistheprintoutofthefollowingstatement?
if(x>0)
if(y>0)
System.out.println("x>0andy>0");
elseif(z>0)
System.out.println("x<0andz>0");
A.x>0andy>0;
B.x<0andz>0;
C.x<0andz<0;
D.noprintout.
41.Analyzethefollowingcode:
booleaneven=false;
if(even=true){
System.out.println("Itiseven!
");
}
A.Theprogramhasasyntaxerror.
B.Theprogramhasaruntimeerror.
C.Theprogramrunsfine,butdisplaysnothing.
D.TheprogramrunsfineanddisplaysItiseven!
.
42.Analyzethefollowingcode:
//Enteraninteger
StringnumString=JOptionPane.showInputDialog(null,
"Enteranumber:
",
"ExamInput",
JOptionPane.QUESTION_MESSAGE);
intnumber=Integer.parseInt(numString);
if(number<=0)
System.out.println(number);
A.Theifstatementiswrong,becauseitdoesnothavetheelseclause;
B.System.out.println(number);mustbeplacedinsidebraces;
C.Ifnumberiszero,numberisdisplayed;
D.Ifnumberispositive,numberisdisplayed.
E.numberenteredfromthekeyboardcannotbenegative.
43.Analyzethefollowingcode.
importjavax.swing.*;
publicclassShowErrors{
publicstaticvoidmain(String[]args){
inti;
intj;
Strings=JOptionPane.showInputDialog(null,
"Enteraninteger","Input",
JOptionPane.QUESTION_MESSAGE);
j=Integer.parseInt(s);
i=(i+4);
}
}
A.Theprogramcannotcompilebecausejisnotinitialized.
B.Theprogramcannotcompilebecauseidoesnothaveaninitialvaluewhenitisusedini=i+4;
C.Theprogramcompilesbuthasaruntimeerrorbecauseideosnothaveaninitialvaluewhenitisusedini=i+4;
D.Theprogramcompilesandrunsfine.
44.Whatistheoutputofthefollowingcode:
(Pleaseindentthestatementcorrectlyfirst.)
intx=9,y=8,z=7;
if(x>9)
if(y>8)
System.out.println("x>9andy>8");
elseif(z>=7)
System.out.println("x<=9andz>=7");
else
System.out.println("x<=9andz<7");
A.x>9andy>8;
B.x<=9andz>=7;
C.x<=9andz<7;
D.Noneoftheabove.
45.Analyzethefollowingcode:
StringnumString=JOptionPane.showInputDialog(null,
"Enteranumber:
",
"ExamInput",
JOptionPane.QUESTION_MESSAGE);
intnumber=Integer.parseInt(numString);
if(number<=0)
System.out.println(number);
System.out.println(number);
A.numberisalwaysprintedoutatleastonce;
B.numberisprintedouttwiceifnumberiszero;
C.numberisprintedouttwiceifnumberisnegative;
D.numberisprintedoutonceifnumberispositive.
E.Alloftheabove.
46.Whatisyafterthefollowingswitchstatement?
intx=0;
inty=0;
switch(x+1){
case0:
y=0;
case1:
y=1;
default:
y=-1
}
A.1
B.-1
C.0
D.Noneoftheabove
47.Whatistheprintoutofthefollowingswitchstatement?
charch='a';
switch(ch){
case'a':
case'A':
System.out.print(ch);break;
case'b':
case'B':
System.out.print(ch);break;
case'c':
case'C':
System.out.print(ch);break;
case'd':
case'D':
System.out.print(ch);
}
A.abcd
B.a
C.aa
D.ab
E.abc
48.Analyzethefollowingcode.
intx=0;
inty=((x<100)&(x>0))?
1:
-1;
A.Thecodehasasyntaxerrorbecause&mustbe&&.
B.ybecomes1afterthecodeisexecuted.
C.ybecomes-1afterthecodeisexecuted.
D.Noneoftheabove.
49.Whichofthefollowingisnotavalidbooleanexpression.
A.(1B.(x=1)||(x!
=1)
C.a,bareallcorrect
D.a,bareallwrong
50.Whichofthefollowingexpressionisequivalentto(x>1