JAV JAVA REVIEW QUESTIONS
Instructions: 1. Answer Answer this this test test in 1 hour hour.. 2. Cellphones, Cellphones, tablets, tablets, or the the likes likes should be turned turned of. of. 3. No chatting chatting with seatmate seatmates. s. . Answers Answers should should be be clearl! clearl! writt written. en. ". #irect #irect !our !our $uestion $uestions s to !our !our “PROCTOR” . %. A&oid &oid erasu erasure re's( 's(.. Test I. Multiple-Choice. Wite o!l" the lette o# the coect $!s%e.
1. )hat is is the range range o* data data t!pe t!pe short short in +a&a +a&a a( -12 to 12/ b( -32/% to 32/%/ c( -21/3% to 21/3%/ d( None o* the mentioned 2. )hat is is the range range o* o* data t!pe t!pe b!te b!te in +a&a +a&a a( -12 to 12/ b( -32/% to 32/%/ c( -21/3% to 21/3%/ d( None o* the mentioned 3. )hich o* o* the *ollowing *ollowing are legal lines lines o* +a&a code code 1. int w 0 'int(. 2. b!te 0 'b!te(14 3. long ! 0 'b!te(1 . b!te 5 0 'b!te(14 a( 1 and 2 b( 2 and 3 c( 3 and d( All statements are correct. . An epression epression in&ol&ing in&ol&ing b!te, int, int, and literal literal numbers numbers is promoted promoted to which o* these a( int b( long c( b!te d( 6oat ". )hich data data t!pe &alue &alue is returned returned b! all all transcendental transcendental math *unctions a( int b( 6oat c( double d( long %. )hat is is the outpu outputt o* this this progr program am class con&ersion 7 public static &oid main'8tring args9(
1
7 double a 0 2;". int b 0 3 b!te c 0 'b!te( a b!te d 0 'b!te( b 8!stem.out.println'c < = = < d( > > a( 3 3 b( 3; c( 2;" 3 d( 2;". 3 /. )hat is the output o* this program class increment 7 public static &oid main'8tring args9( 7 int g 0 3 8!stem.out.print'< > a( 2" b( 2 c( 32 d( 33 . )hat is the numerical range o* a char in +a&a a( -12 to 12/ b( to 2"% c( to 32/%/ d( to %""3" ;. )hich o* these &alues can a boolean &ariable contain a( @rue Balse b( 1 c( An! integer &alue. d( oth a b 1.
11.
)hich one is a &alid declaration o* a boolean a( boolean b1 0 1 b( boolean b2 0 D*alseE c( boolean b3 0 *alse d( boolean b 0 DtrueE )hat is the output o* this program class booloperators 7 public static &oid main'8tring args9( 7 boolean &ar1 0 true boolean &ar2 0 *alse 8!stem.out.println''&ar2 &ar2(( > >
2
a( b( 1 c( true d( *alse 12.
)hich o* the *ollowing can be operands o* arithmetic operators a( Numeric b( oolean c( Characters d( oth oolean Characters
13.
Fodulus operator, G, can be applied to which o* these a( Integers b( Bloating H point numbers c( oth Integers and 6oating H point numbers. d( None o* the mentioned
1. )ith 0 , which o* the *ollowing are legal lines o* +a&a code *or changing the &alue o* to 1 1. << 2. 0 < 1 3. <0 1 . 0< 1 a( 1, 2 3 b( 1 c( 1, 2, 3 d( 3 2 1". #ecrement operator, H, decreases &alue o* &ariable b! what number a( 1 b( 2 c( 3 d( 1%.
I* has a &alue o* 3, what would be its &alue i* eecute -- a( 3 b( c( -3 d( -
1/.
1.
)hich o* these statements are incorrect a( Assignment operators are more ecientl! implemented b! +a&a run-time s!stem than their e$ui&alent long *orms. b( Assignment operators run *aster than their e$ui&alent long *orms. c( Assignment operators can be used onl! with numeric and character data t!pe. d( None )hat is the output o* this program class increment 7 public static &oid main'8tring args9( 7 double &ar1 0 1 < " double &ar2 0 &ar1 J
3
int &ar3 0 1 < " int &ar 0 &ar3 J 8!stem.out.print'&ar2 < = = < &ar( > > a( 1 1 b( 1 c( 1." 1 d( 1." 1. 1;.
)hat is the output o* this program class Fodulus 7 public static &oid main'8tring args9( 7 double a 0 2".% int b 0 2" a 0 a G 1 b 0 b G 1 8!stem.out.println'a < = = < b( > > a( ".%1 " b( ".%1 ". c( " " d( " ".%1
2.
)hat is the output o* this program
class Kutput 7 public static &oid main'8tring args9( 7 int , ! 0 1 << -- ! 0 << 8!stem.out.println' < = = < !( > > a( 11 11 b( 1 1 c( 11 1 d( 1 11 21.
)hat is the output o* this program class Kutput 7 public static &oid main'8tring args9( 7 int a 0 1 int b 0 2 int c int d
c 0 <
>
> a( 3 2 b( 3 2 3 c( 2 3 d( 3 22.
)hat is the &alue stored in in *ollowing lines o* code int , !, 5 0 ! 0 1 0 ! 0 5 0 a( b( 1 c( ; d(
23.
)hat is the output o* this program class operators 7 public static &oid main'8tring args9( 7 int 0 8!stem.out.println'<< ? 3 < = = < ( > > a( 2 b( 2 ; c( 2/ d( 2/ ;
2.
)hich o* these ke!words is used to make a class a( class b( struct c( int d( None o* the mentioned
2".
8tring in +a&a is a a( class b( obLect c( &ariable d( character arra!
2%.
)hat is the output o* this program class stringMdemo 7 public static &oid main'8tring args9(
"
7 8tring obL 0 =I= < =like= < =+a&a= 8!stem.out.println'obL( > > a( I b( like c( +a&a d( Ilike+a&a 2/.
)hat is the output o* this program class stringMclass 7 public static &oid main'8tring args9( 7 8tring obL 0 =I 4IO +APA= 8!stem.out.println'obL.charAt'3(( > > a( I b( 4 c( d( O
2.
)hat is the output o* this program class stringMclass 7 public static &oid main'8tring args9( 7 8tring obL 0 =I 4IO +APA= 8!stem.out.println'obL.length'(( > > a( ; b( 1 c( 11 d( 12
2;.
)h! do computers use 5eros and ones a( because combinations o* 5eros and ones can represent an! numbers and characters. b( because digital de&ices ha&e two stable states and it is natural to use one state *or and the other *or 1. c(because binar! numbers are simplest.
d( because binar! numbers are the bases upon which all other number s!stems are built. 3.
Computer can eecute the code in MMMMMMMMMMMM. a( machine language b( assembl! language c( high-le&el language d( none o* the abo&e %
31. MMMMMMMMMMM translates high-le&el language program into machine language program. a( An assembler b( A compiler c( CQR d( @he operating s!stem 32.
+a&a was de&eloped b! MMMMMMMMMMMM. a( 8un Ficros!stems b( Ficroso*t c( Kracle d( IF
33.
+a&a MMMMMMMMMMM can run *rom a )eb browser. a( applications b( applets c( ser&lets d( Ficro Odition programs
3.
MMMMMMMM is an obLect-oriented programming language. 'Choose three( a( +a&a b( C<< c( C d( CS
3".
@he main method header is written as: a( public static &oid main'string9 args( b( public static &oid Fain'8tring9 args( c( public static &oid main'8tring9 args( d( public static main'8tring9 args(
3%.
)hich o* the *ollowing statements is correct a( O&er! b( O&er! c( O&er! d( O&er!
line in a program must end with a semicolon. statement in a program must end with a semicolon. comment line must end with a semicolon. method must end with a semicolon.
3/. )hich o* the *ollowing statements is correct to displa! )elcome to +a&a on the console 'Choose two( a( 8!stem.out.println'T)elcome to +a&aT( b( 8!stem.out.println'=)elcome to +a&a=( c( 8!stem.println'T)elcome to +a&aT( d( 8!stem.out.print'=)elcome to +a&a=( 3.
+a&a compiler translates +a&a source code into MMMMMMMMM. a( +a&a b!tecode b( machine code c( assembl! code d( another high-le&el language code
/
3;.
MMMMMMMMM is a so*tware that interprets +a&a b!tecode. a( +a&a &irtual machine b( +a&a compiler c( +a&a debugger d( +a&a AQI
.
8uppose !ou deUne a +a&a class as *ollows: public class @est 7 > In order to compile this program, the source code should be stored in a Ule named a( @est.class b( @est.doc c( @est.tt d( @est.La&a
1.
)hich o* the *ollowing lines is not a +a&a comment a( J?? comments ?J b( JJ comments c( -- comments d( J? comments ?J
2.
)hich o* the *ollowing are the reser&ed words 'Choose all possible answer( a( public b( static c( &oid d( class
3. @o use 8canner in !our program, !ou ma! import it using: 'Choose all possible answer( a( import La&a.util.8canner b( import La&a.util.8canner c( import La&a.util.8canner d( import La&a.util.? .
Qrogramming st!le is important, because MMMMMMMMMMMMMM. a( a program ma! not compile i* it has a bad st!le b( good programming st!le can make a program run *aster c( good programming st!le makes a program more readable d( good programming st!le helps reduce programming errors
". I* a program compiles Une, but it produces incorrect result, then the program sufers MMMMMMMMMM. a( a compilation error b( a runtime error c( a logic error d( none o* these errors
%. I* !ou *orget to put a closing $uotation mark on a string, what kind error will be raised a( a compilation error b( a runtime error c( a logic error d( relati&e error /.
8uppose a 8canner obLect is created as *ollows: 8canner input 0 new 8canner'8!stem.in( )hat method do !ou use to read an int &alue a( input.netInt'( b( input.netInteger'( c( input.int'( d( input.integer'(
.
@he *ollowing code *ragment reads in two numbers:
8canner input 0 new 8canner'8!stem.in( int i 0 input.netInt'( double d 0 input.net#ouble'( 8!stem.out.println''i < d(( Assume the input is 2." 3.2, what will be the output a. b. c. d.
"./ ".% " %
;. )hat are the correct wa!s to enter these two numbers A. Onter an integer, a space, a double &alue, and then the Onter ke!. . Onter an integer, two spaces, a double &alue, and then the Onter ke!. C. Onter an integer, an Onter ke!, a double &alue, and then the Onter ke!. #. Onter a numeric &alue with a decimal point, a space, an integer, and then the Onter ke!. ".
I* !ou enter 1 2 3, when !ou run this program, what will be the output
import La&a.util.8canner public class @est1 7 public static &oid main'8tring9 args( 7 8canner input 0 new 8canner'8!stem.in( 8!stem.out.print'=Onter three numbers: =( double number1 0 input.net#ouble'( double number2 0 input.net#ouble'( double number3 0 input.net#ouble'( JJ Compute a&erage double a&erage 0 'number1 < number2 < number3( J 3 JJ #ispla! result 8!stem.out.println'a&erage(
;
> > A. 1. . 2. C. 3. #. . "1.
)hich o* the *ollowing is a &alid identiUer
A. V33 . class C. ;W #. radius "2. )hich o* the *ollowing are correct names *or &ariables according to +a&a naming con&entions 'Choose all that applies( A. radius . Xadius C. XA#IR8 #. UndArea "3.
)hich o* the *ollowing are correct wa!s to declare &ariables
A. int length int width . int length, width C. int length width #. int length, int width ".
MMMMMMMMMMMM is the +a&a assignment operator.
A. 00 . :0 C. 0 #. 0: "".
@o assign a &alue 1 to &ariable , !ou write
A. 1 0 . 0 1 C. :0 1 #. 1 :0 "%.
@o declare a constant FAWM4ONY@Z inside a method with &alue ;;.;, !ou write
A. Unal FAWM4ONY@Z 0 ;;.; . Unal 6oat FAWM4ONY@Z 0 ;;.; C. double FAWM4ONY@Z 0 ;;.; #. Unal double FAWM4ONY@Z 0 ;;.;
"/. )hich o* the *ollowing is a constant, according to +a&a naming con&entions 'Choose all that applies.( A. FAWMPA4RO
1
. @est C. read #. XeadInt ".
)hich o* these data t!pes re$uires the most amount o* memor!
A. long . int C. short #. b!te ";.
)hat is the result o* " J
A. 1 . 11 C. 11.2" #. 12 %.
)hich o* the *ollowing epression results in a &alue 1
A. 2 G 1 . 1" G C. 2" G " #. 3/ G % %1.
Anal!5e the *ollowing code.
public class @est 7 public static &oid main'8tring9 args( 7 int month 0 ; 8!stem.out.println'=month is = < month( > > A. @he program displa!s month is ; . @he program displa!s month is ; C. @he program displa!s month is ;. #. @he program has a s!nta error, because ; is an incorrect literal &alue. %2. @he epression < 2 J '3 - 1( ? 2 is e&aluated to A. . 2 C. 2 #. ; %3. @o add a &alue 1 to &ariable , !ou write A. 1 < 0 . <0 1 C. :0 1 #. 0 < 1 %. @o add number to sum, !ou write 'Note: +a&a is case-sensiti&e(
11
A. number <0 sum . number 0 sum < number C. sum <0 number #. sum 0 sum < number %". 8uppose is 1. )hat is a*ter <0 2 A. . 1 C. 2 #. 3 %%. )hat is a*ter the *ollowing statements int 0 2 int ! 0 1 ?0 ! < 1
A. is 1. . is 2. C. is 3. #. is . %/. )hat is the &alue o* i printed public class @est 7 public static &oid main'8tring9 args( 7 int L 0 int i 0 < > A. . 1 C. " #. % %. )hat is the &alue o* i printed in the *ollowing code public class @est 7 public static &oid main'8tring9 args( 7 int L 0 int i 0 L<< < L ? " 8!stem.out.println'=)hat is i = < i( > >
12
A. . 1 C. " #. % %;. )hat is ! displa!ed in the *ollowing code public class @est 7 public static &oid main'8tring9 args( 7 int 0 1 int ! 0 << < 8!stem.out.println'=! is = < !( > > A. ! is 1. . ! is 2. C. ! is 3. #. ! is . /. )hich o* the *ollowing assignment statements is illegal A. 6oat * 0 -3 . int t 0 23 C. short s 0 1 #. int t 0 'int(*alse
13