-
Notifications
You must be signed in to change notification settings - Fork 208
/
Copy pathPRO192.txt
2629 lines (2628 loc) · 369 KB
/
PRO192.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
uting SQL statements | jdbc
method is used to wait for a client to initiate communications | accept()
drivers that are written partly in the Java programming language and partly in native code. These drivers use a native client library specific to the data source to which they connect | type 2
drivers that are pure Java and implement the network protocol for a specific data source. The client connects directly to the data source | type 4
drivers that use a pure Java client and communicate with a middleware server using a database-independent protocol. The middleware server then communicates the client's requests to the data source | type 3
drivers that implement the JDBC API as a mapping to another data access API, such as ODBC. Drivers of this type are generally dependent on a native library, which limits their portability | type 1
System.out.println(a.doit(4, 5)) | line 26 prints a to system.out
Which two are true if a NullPointerException is thrown on line 3 of class C | code on line 29, the exception
What lines are output if the constructor at line 3 throws a MalformedURLException | bad url, doing finally, carrying
What lines are output if the methods at lines 3 and 5 complete successfully without throwing any exceptions | success, doing, carrying
If lines 24, 25 and 26 were removed, the code would compile and the output would be 1 | 3.the code, would be 1, 2
An exception is thrown at runtime | an exception
first second first third snootchy 420 | third second first snootchy 420
dialog prevents user input to other windows in the application unitl the dialog is closed | modal
You would like to write code to read back the data from this file. Which solutions will work | 2.fileinputstream, randomaccessfile
A Java monitor must either extend Thread or implement Runnable | false
A monitor called mon has 10 threads in its waiting pool; all these waiting threads have the same priority. One of the threads is thr1 | you cannot specify
A programmer needs to create a logging method that can accept an arbitrary number of arguments. For example, it may be called in these ways | public void logit(string... msgs)
A signed data type has an equal number of non-zero positive and negative values available | false
A thread wants to make a second thread ineligible for execution. To do this, the first thread can call the yield() method on the second thread | false
catch (InterruptedException e) | running some time
object is used to submit a query to a database | statement
object is uses to obtain a Connection to a Database | drivermanager
After execution of the following code fragment, what are the values of the variables x, a, and b | x13, a7, b8
Yen and Euro both return correct Country value | 2.euro returns, error at line 25
BigOlLongStringWithMeaninglessName | tick all
Compilation of class A will fail. Compilation of class B will succeed | b fail, a succeed
Line 46 will compile if enclosed in a try block, where TestException is caught | 2.if the enclosing, is caught
Holder h = new Holder() | 101
Decrementer dec = new Decrementer() | 12.3
Test t = (new Base()).new Test(1) | 2.new test(1), new test(1, 2)
Base(int j, int k, int l) | 2.base(), base(int j, int k)
Line 12 will not compile, because no version of crunch() takes a char argument | output: int version
output results when the main method of the class Sub is run | value 5 this value 6
Float floater = new Float(3.14f) | line 6
The application must be run with the -enableassertions flag or another assertionenabling flag | dai nhat, one or more
After line 3 executes, the StringBuffer object is eligible for garbage collection | line 2 executes..collection
The code will compile but will throw an exception at line 7, because runtime conversion from an interface to a class is not permitted | type swampthing
The code will compile and run, but the cast in line 6 is not required and can be eliminated | the code will compile and run
for (int i = 0; i < 2; i++) | 4.i0,j12 - i1,j02
outer: for (int i = 0; i < 2; i++) | i = 1 j = 0
The code will compile but will throw an exception at line 7, because runtime conversion from an interface to a class is not permitted | line 7 will not compile
int[] x = new int[25] | 2.x[24]=0, x.length is 25
public float aMethod(float a, float b) throws Exception | int a,b float p,q
public float aMethod(float a, float b, int c) throws Exception | 3.int a,b. float a,b-int c. private
Given a string constructed by calling s = new String("xyzzy"), which of the calls modifies the string | none of the above
Given arrays a1 and a2, which call returns true if a1 and a2 have the same length, and a1[i].equals(a2[i]) for every legal index i | arrays.equals(a1, a2)
Assuming the class does not perform custom serialization, which fields are written when an instance of Xyz is serialized | 3.public, private, volatile
can legally be placed before aMethod() on line 3 and be placed before aMethod() on line 8 | 3: private; 8: protected
NUTMEG, CINNAMON, CORIANDER, ROSEMARY | 3.spice sp, spice, string
List<String> names = new ArrayList<String>() | 2.iterator, for
Compilation fails because of an error in line 15 | error in line 19
1 2 3 | 2 3
public interface B inheritsFrom A | b extends a
protected double getSalesAmount() { return 1230.45; } | 2.public, protected
Line 16 creates a directory named “d” and a file ‘f’ within it in the file system | 3.an exception, line 13, line 14
Nav.Direction d = Nav.Direction.NORTH | nav.direction.north
new class Foo { public int bar() { return 1; } } | new foo()
IllegalArgumentException | stackoverflowerror
Circle c = new Circle(); c.Shape.setAnchor(10,10); c.Shape.draw() | shape s = new circle...s.draw()
Compilation fails because of an error in line 12 | 1 2 3
NullPointerException | compilation fails
A NumberFormatException is thrown by the parse method at runtime | compilation fails
An exception is thrown at runtime | compilation fails
passed An AssertionException is thrown without the word “stuff” added to the stack trace | an assertionerror...with the
collie | collie harrier
doStuff x = 6 main x = 6 | dostuff x =5 main x =5
The setCardlnformation method breaks encapsulation | the ownername
The value of all four objects prints in natural order | compilation fails...line 29
The code on line 33 executes successfully | 3.33 throws, 35 throws, 33 executes
What is the result if a NullPointerException occurs on line 34 | ac
Compilation will fail because of an error in line 55 | line 57...value 3
java -ea test file1 file2 | 2.java -ea test, dai nhat
String s = “123456789”; s = (s-”123”).replace(1,3,”24”) - “89” | 2.delete(4,6), delete(2,5).insert( 1, “24”)
The Point class cannot be instatiated at line 15 | line.point p = new line.point()
for( int i=0; i< x.length; i++ ) System.out.println(x[i]) | 2.for(int z : x), dai nhat
int MY_VALUE = 10 | 3.final, static, public
Compilation fails because of an error in line: public void process() throws RuntimeException | a exception
How can you ensure that multithreaded code does not deadlock | there is no single
How can you force garbage collection of an object | garbage collection
How do you prevent shared data from being corrupted in a multithreaded environment | access the variables
How do you use the File class to list the contents of a directory | string[] contents
The number of bytes depends on the underlying system | 8
How many locks does an object have | one
If all three top-level elements occur in a source file, they must appear in which order | package declaration, imports
the two classes are in different packages, and class X has a protected method called abby(), then any instance of Y may call the abby() method of any | false
TestThread3 ttt = new TestThread3 | y
If you need a Set implementation that provides value-ordered iteration, which class should you use | treeset
In order for objects in a List to be sorted, those objects must implement which interface and method | comparable...compareto
after execution of line 1, sbuf references an instance of the StringBuffer class. After execution of line 2, sbuf still references the same instance | true
what are the possible types for variable result | int, long, float, double
helps manage the connection between a Java program and a database | connection
Is it possible to define a class called Thing so that the following method can return true under certain circumstances | y
Is it possible to write code that can execute only if the current thread owns multiple locks | y
JDBC supports ______ and ______ models | two-tier and three-tier
MVC is short call of | model-view-controller
No output because of compile error at line: System.out.println("b="+b) | b = b * b1
Object ob2= new Object() | have a nice day
Object ob2= ob1 | ob1 equals ob2, ob1==ob2
String s2 = "xyz" | line 4, line 6
String s2 = new String("xyz") | line 6
String s2 = new String(s1) | line 6
Select correct statement about RMI | all the above
Select correct statement(s) about remote class | all the others choices
Select correct statements about remote interface | all the others choices
Select INCORRECT statement about serialization | when an object output
Select INCORRECT statement about deserialize | we use readobject
Select incorrect statement about RMI server | a client accesses
Select incorrect statement about ServerSocket class | to make the new object
Select incorrect statement about Socket class | server through udp
Select the correct statement about JDBC two-tier processing model | a user's commands
SQL keyword ___ is followed by the selection criteria that specify the rows to select in a query | where
Statement objects return SQL query results as | resultset
When a JDBC connection is created, it is in auto-commit mode | both 1 and 2 are true
Suppose a method called finallyTest() consists of a try block, followed by a catch block, followed by a finally block | if the jvm doesn't crash
Suppose a source file contains a large number of import statements and one class definition. How do the imports affect the time required to load the class | no additional time
Suppose a source file contains a large number of import statements. How do the imports affect the time required to compile the source file | slightly more time
Suppose class A extends Object; Class B extends A; and class C extends B. Of these, only class C implements java.io.Externalizable | c must have a
Suppose class A extends Object; class B extends A; and class C extends B. Of these, only class C implements java.io.Serializable | b must have a
Suppose class A has a method called doSomething(), with default access. Suppose class B extends A and overrides doSomething() | private
Suppose class Supe, in package packagea, has a method called doSomething(). Suppose class Subby, in package packageb, overrides doSomething() | 2.public, protected
void doSomething(int a, float b) | public...(int a, float b)
Suppose interface Inty defines five methods. Suppose class Classy declares that it implements Inty but does not provide implementations for any of the five interface methods | 2.declared abstract, may not be
Suppose prim is an int and wrapped is an Integer. Which of the following are legal Java statements | all the above
Suppose salaries is an array containing floats. Which of the following are valid loop control statements for processing each element of salaries | for (float f:salaries)
Suppose the declared type of x is a class, and the declared type of y is an interface. When is the assignment x = y; legal | when the...x is object
Suppose the type of xarr is an array of XXX, and the type of yarr is an array of YYY. When is the assignment xarr = yarr; legal | sometimes
Suppose x and y are of type TrafficLightState, which is an enum. What is the best way to test whether x and y refer to the same constant | if (x == y)
Suppose you are writing a class that will provide custom deserialization. What access mode should the readObject() method have | private
Suppose you are writing a class that will provide custom serialization. What access mode should the writeObject() method have | private
Suppose you want to create a custom thread class by extending java.lang.Thread in order to provide some special functionality | override run()
Suppose you want to write a class that offers static methods to compute hyperbolic trigonometric functions. You decide to subclass java.lang.Math and provide the new functionality as a set of static methods | subclass java.lang.math
Swing components cannot be combined with AWT components | true
class is the primary class that has the driver information | drivermanager
class is used to implement a pull-down menu that provides a number of items to select from | menu
The element method alters the contents of a Queue | false
The Swing component classes can be found in the | javax.swing
There are two classes in Java to enable communication using datagrams namely | datapacket and datasocket
Compilation of Parrot.java fails at line 7 because method getRefCount() is static in the superclass, and static methods may not be overridden to be nonstatic | dai nhat: nonstatic
Compilation of Nightingale will succeed, but an exception will be thrown at line 10, because method fly() is protected in the superclass | the program...after: 2
void doSomething() throws IOException, EOFException | ngan-dai nhat, throws eofexception
URL referring to databases use the form | protocol:subprotocol:datasoursename
What are the legal types for whatsMyType | there are no possible legal types
What does the following code do | throws an exception
There is no output because the code throws an exception at line 1 | output is i = 20
1000 | -1
What happens when you try to compile and run the following application | thrown at line 9
The code compiles, and prints out >>null<< | out >>null<<
An exception is thrown at line 6 | thrown at line 7
What is -50 >> 2 | -13
What is 7 % -4 | 3
What is -8 % 5 | -3
What is the difference between the rules for method-call conversion and the rules for assignment conversion | there is no difference
The code will compile as is. No modification is needed | on line 1, remove
What is the range of values that can be assigned to a variable of type byte | ?2mu7 through 2mu7 ? 1
What is the range of values that can be assigned to a variable of type short | ?2mu15 through
The code compiles and executes; afterward, the current working directory contains a file called datafile | the code fails to compile
What is the return type of the instanceof operator | a boolean
What method of the java.io.File class can create a file on the hard drive | createnewfile()
The output: value is 99.99 | value is 9.0
The output: b contains 250 | b contains 5
What would be the output from this code fragment | message four
When a byte is added to a char, what is the type of the result | int
When a negative byte is cast to a long, what are the possible values of the result | negative
When a negative long is cast to a byte, what are the possible values of the result | all the above
When a short is added to a float, what is the type of the result | float
When comparing java.io.BufferedWriter to java.io.FileWriter, which capability exists as a method in only one of the two | writing a line
When does an exception's stack trace get recorded in the exception object | is constructed
When is it appropriate to pass a cause to an exception's constructor | in response to catching
When is it appropriate to write code that constructs and throws an error | never
When is x & y an int | sometimes
When the user attempts to close the frame window, _______ event in generated | window closing
When the user selects a menu item, _______ event is generated | action event
Java programming language, the compiler converts the human-readable source file into platform-independent code that a Java Virtual Machine can understand | bytecode
Whenever a method does not want to handle exceptions using the try block, the | throws
Which are the correct statements used for getting connection object to connect to SQL Server database | string url =jdbc:odbc
Which class and static method can you use to convert an array to a List | arrays.aslist
Which is four-step approach to help you organize your GUI thinking | identify, isolate, sketch
Which is the four steps are used in working with JDBC | connect, create, look
Which JDBC processing model that requires a JDBC driver that can communicate with the particular data source being accessed | two-tier
Which line of code tells a scanner called sc to use a single digit as a delimiter | sc.usedelimiter("\\d")
Man has the best friend who is a Dog | private dog bestfriend
Which methods return an enum constant’s name | 2.name(), tostring()
Which modifier or modifiers should be used to denote a variable that should not be written out as part of its class's persistent state | transient
Which of the following are legal argument types for a switch statement | 3.byte, int, char
Which of the following are legal enums | 3.ngan-dai nhat, lion int weight
Which of the following are legal import statements | 2.import...vector, vector.*
Which of the following are legal loop constructions | for (int k=0, j+k != 10; j++,k++)
Which of the following are legal loop definitions | none of the above
double d = 1.2d5 | 2.double d = 1.2d, 1.2d
int d = 0XABCD | 2.int c = 0xabcd, dai nhat
char c = 0x1234 | 2.0x.., '\u1234'
Vector <String> theVec = new Vector<String>() | 2.list...<string>(), dai nhat
Which of the following are methods of the java.util.SortedMap interface | headmap, tailmap, submap
Which of the following are methods of the java.util.SortedSet interface | all the above
System.out has a println() method | all the above
The JVM runs until there is only one non-daemon thread | are no non-daemon
When an application begins running, there is one non-daemon thread, whose job is to execute main() | 3.nhat, thread, non-daemon thread
When you declare a block of code inside a method to be synchronized, you can specify the object on whose lock the block should synchronize | 2.the method always, nhat
An enum definition should declare that it extends java.lang.Enum | 2.contain public, private
Primitives are passed by reference | 2.by value
An anonymous inner class that implements several interfaces may extend a parent class other than Object | implement at most, class may extend
Which of the following are valid arguments to the DataInputStream constructor | fileinputstream
Which of the following are valid mode strings for the RandomAccessFile constructor | all the above
Which of the following calls may be made from a non-static synchronized method | all the above
Which of the following classes implement java.util.List | 2.arraylist, stack
Which of the following classes implements a FIFO Queue | linkedlist
Which of the following declarations are illegal | 3.ngan-dai nhat, double d
int x = 6; if (!(x > 3)) | 2.dai nhat, x = ~x
String x = "Hello"; int y = 9; if (x == y) | 2.ngan nhat, x=x+y
Which of the following expressions results in a positive value in x | int x = –1; x = x >>> 5
Which of the following interfaces does not allow duplicate objects | set
Which of the following is not appropriate situations for assertions | preconditions of a public method
Which of the following is NOTa valid comment | /* comment
Which of the following is the most appropriate way to handle invalid arguments in a public method | illegalargumentexception
Readers have methods that can read and return floats and doubles | none of the above
An enum definition may contain the main() method of an application | all the above
Which of the following may appear on the left-hand side of an instanceof operator | a reference
Which of the following may appear on the right-hand side of an instanceof operator | 2.a class, an interface
Which of the following may be declared final | 2.classes, methods
Which of the following may be statically imported | 2.static method, static field
Which of the following may follow the static keyword | 3.data, methods, code blocks
Which of the following may legally appear as the new type (between the parentheses) in a cast operation | all of
Which of the following may not be synchronized | classes
Which of the following may override a method whose signature is void xyz(float f) | 2.void, public void xyz(float f)
Which of the following methods in the Thread class are deprecated | suspend() and resume()
Which of the following operations might throw an ArithmeticException | none of
Which of the following operators can perform promotion on their operands | 3.cong, tru, xap xi
Which of the following restrictions apply to anonymous inner classes | must be defined
Which of the following should always be caught | checked exceptions
Which of the following signatures are valid for the main() method entry point of an application | 2.static void...(string arg[])
Which of the following statements about the wait() and notify() methods is true | calls wait() goes into
Which of the following statements about threads is true | threads inherit their
A final class may not contain non-final data fields | may not be extended
An abstract class must declare that it implements an interface | none
An abstract class may not have any final methods | only statement 2
Only object references are converted automatically; to change the type of a primitive, you have to do a cast | both primitives
Transient methods may not be overridden | variables are not
Object references can be converted in both method calls and assignments, but the rules governing these conversions are very different | conversions are identical
Bytecode characters are all 16 bits | unicode characters
To change the current working directory, call the changeWorkingDirectory() method of the File class | none
When you construct an instance of File, if you do not use the file-naming semantics of the local machine, the constructor will throw an IOException | none
When the application is run, thread hp1 will execute to completion, thread hp2 will execute to completion, then thread hp3 will execute to completion | none of
Compilation succeeds, although the import on line 1 is not necessary. During execution, an exception is thrown at line 3 | fails at line 2
Compilation fails at line 1 because the String constructor must be called explicitly | succeeds. no exception
Line 4 executes and line 6 does not | line 6 executes
There will be a compiler error, because class Greebo does not correctly implement the Runnable interface | runnable interface
The acceptable types for the variable j, as the argument to the switch() construct, could be any of byte, short, int, or long | value is three
The returned value varies depending on the argument | returns 0
Lines 5 and 12 will not compile because the method names and return types are missing | output x = 3
Line 13 will not compile because it is a static reference to a private variable | output is x = 104
Which statements about JDBC are NOT true | 2.database system, dbms
Which two code fragments correctly create and initialize a static array of int elements | 2.a = { 100,200 }, static
Which two of the following interfaces are at the top of the hierarchies in the Java Collections Framework | 2.map, collection
A new directory called dirname and a new file called filename are created, both in the current working directory | no directory
protected class Cat extends Owner | public class cat extends pet
Date vaccinationDue | 2.boolean, string
What is -15 % -10 | -5
command line on a Windows system | 2.must contain the statement, the file
The string created on line 2 does not become eligible for garbage collection in this code | after line 3
When the application runs, what are the values of n and w.x after the call to bump() in the main | n is 10, w.x is 11
The addAll() method of that interface takes a single argument, which is a reference to a collection whose elements are compatible with E. What is the declaration of the addAll() method | addall(collection<? extends e> c)
If you want a vector in which you know you will only store strings, what are the advantages of using fancyVec rather than plainVec | attempting to...compiler error
When should objects stored in a Set implement the java.util.Comparable interface | set is a treeset
What relationship does the extends keyword represent | is a
class bbb.Bbb, which extends aaa.AAA, wants to override callMe(). Which access modes for callMe() in aaa.AAA will allow this | 2.public, protected
Lemon lem = new Lemon(); Citrus cit = new Citrus() | 3.cit = lem, cit=(citrus), lem=(lemon)
it also has a method called chopWoodAndCarryWater(), which just calls the other two methods | inappropriate cohesion, inappropriate coupling
sharedOb.wait() | 2.athread.interrupt, sharedob.notifyall
line prints double d in a left-justified field that is 20 characters wide, with 15 characters to the right of the decimal point | system.out.format("%-20.15f", d)
What code at line 3 produces the following output | string delim = “\\d+”
How do you generate a string representing the value of a float f in a format appropriate for a locale loc | numberformat.getinstance(loc)
you want to use a DateFormat to format an instance of Date. What factors influence the string returned by DateFormat’s format() method | 2.long, or full, the locale
you want to create a class that compiles and can be serialized and deserialized without causing an exception to be thrown. Which statements are true regarding the class | 2.dai nhat, ngan nhat
you are writing a class that will provide custom deserialization. The class implements java.io.Serializable (not java.io.Externalizable) | private
What interfaces can be implemented in order to create a class that can be serialized | 2.dai nhat, ngan nhat
The file contains lines of 8-bit text, and the 8-bit encoding represents the local character set, as represented by the cur- rent default locale. The lines are separated by newline characters | filereader instance
shorty is a short and wrapped is a Short | all
How is IllegalArgumentException used | 2.certain methods, public methods
While testing some code that you are developing, you notice that an ArrayIndexOutOf- BoundsException is thrown. What is the appropriate reaction | none
Which lines check that x is equal to four? Assume assertions are enabled at compile time and runtime | 2.assert x == 4
int[] ages = { 9, 41, 49 }; int sum = 0 | 2.i<ages.length, for (int i:ages)
Which of the following types are legal arguments of a switch statement | enums, bytes
class A extends java.util.Vector { private A(int x) | does not create a default
void callMe(String… names) | method, names is an array
Given a class with a public variable theTint of type Color, which of the following methods are consistent with the JavaBeans naming standards | public color getthetint()
are valid arguments to the DataInputStream constructor | fileinputstream
are valid mode strings for the RandomAccessFile constructor | r, rw, rws, rwd
method of the java.io.File class can create a file on the hard drive | createnewfile()
class A extends Object; Class B extends A; and class C extends B. Of these, only class C implements java.io.Externalizable | c must have
class A extends Object; class B extends A; and class C extends B. Of these, only class C implements java.io.Serializable | b must have
you are writing a class that will provide custom serialization. The class implements java.io.Serializable (not java.io.Externalizable) | private
How do you use the File class to list the contents of a directory | string[] contents = myfile.list();
call returns true if a1 and a2 have the same length, and a1[i].equals(a2[i]) for every legal index i | java.util.arrays.equals(a1, a2)
line of code tells a scanner called sc to use a single digit as a delimiter | sc.usedelimiter(“\\d”)
you want to write a class that offers static methods to compute hyperbolic trigonometric functions. You decide to subclass java.lang.Math and provide the new functionality as a set of static methods | java.lang.math
Given a string constructed by calling s = new String(“xyzzy”), which of the calls modifies the string | none
Suppose you want to create a custom thread class by extending java.lang.Thread in order to provide some special functionality. Which of the following must you do | override run()
you prevent shared data from being corrupted in a multithreaded environment | access the variables
Is it possible to write code that can execute only if the current thread owns multiple locks | yes
statements about the wait() and notify() methods is true | pool of waiting threads
methods in the Thread class are deprecated | suspend() and resume()
A Java monitor must either extend Thread or implement Runnable | false
One of the threads is thr1. How can you notify thr1 so that it alone moves from the Waiting state to the Ready state | you cannot specify
A thread wants to make a second thread ineligible for execution. To do this, the first thread can call the yield() method on the second thread | false
Which methods return an enum constant’s name | name(), tostring()
restrictions apply to anonymous inner classes | inside a code block
A pet has an owner, a registration date, and a vaccination-due date. A cat is a pet that has a flag indicating whether it has been neutered, and a textual description of its markings | boolean, string
Which of the following are valid declarations? Assume java.util | 1vector 2set 3map string,string
You can determine all the keys in a Map in which of the following ways | set object from the map
What keyword is used to prevent an object from being serialized | transient
abstract class can contain methods with declared bodies. | public, protected, default, private
access modifier allows you to access method calls in libraries not created in Java | native
Which of the following statements are true? (Select all that apply.) | object cannot reassigned
The keyword extends refers to what type of relationship | is a
keywords is used to invoke a method in the parent class | super
What is the value of x after the following operation is performed | 3
method call is used to tell a thread that it has the opportunity | notify()
Assertions are used to enforce all but which | exceptions
force garbage collection by calling System.gc(). | false
Select the valid primitive data type | 1.boolean 2.char 3.float
How many bits does a float contain | 32
What is the value of x after the following line is executed | 32
StringBuffer is slower than a StringBuilder, but a StringBuffer | true
list of primitives ordered in smallest to largest bit size representation | char, int, float, long
Which class provides locale-sensitive text formatting for date and time information | java.text.dateformat
int x = 9; byte b = x | false
Which of the following code snippets compile | 1.integer 2.integer 3.byte
Java arrays always start at index 1 | false
accurately describes how variables are passed to methods | that are primitive type are passed by value
change the value that is encapsulated by a wrapper class after you have instan | none of the above.
The class implements java.io.Serializable (and not java.io.Externalizable) | private readobject
A signed data type has an equal number of non-zero positive and negative values | false
signatures are valid for the main() method entry point of an application | public static void main(string[] args)
three top-level elements occur in a source file, they must appear | package declaration, imports, class/interface/enum definitions
int[] x = new int[25] | x[24] is 0 and x.length is 25
How can you force garbage collection of an object | garbage collection cannot be forced.
range of values that can be assigned to a variable of type short | -215 through 215 - 1
range of values that can be assigned to a variable of type byte | -27 through 27 - 1
How do the imports affect the time required to compile the source file | compilation takes slightly more time
How do the imports affect the time required to load the class? | class loading takes no additional time
legal import statements | 1.import java.util.vector 2.import static java.util.vector
may be statically imported | 1.static method names 2.static field names
int c = 0xabcd and int d = 0XABCD | 2 dap an
double d = 1.2d and double d = 1.2D | 2 dap an
char c = ‘\u1234’ | 1 dap an
passed by value and passed by value | 2 dap an
int x = 6; if (!(x > 3)) and int x = 6; x = ~x | 2 dap an
int x = –1; x = x >>> 5 | 1 dap an
int y = 9; x += y; and int y = 9; x = x + y; | 2 dap an
What is 7 % -4? | 3
ob1 == ob2 | no
When a byte is added to a char | int
When a short is added to a float | float
ArithmeticException | 1.none of these 2./
What is the return type of the instanceof operator | boolean
may appear on the left-hand side of an instanceof operator | reference
may appear on the right-hand side of an instanceof operator | class and interface
What is -50 >> 1 | -25
default String s ,, abstract double d ,, double hyperbolic | 3 dap an
A final class may not have any abstract methods | true
denote a variable that should not be written out as part of its class’s persistent state | transient
Both primitives and object references can be both converted and cast | dap an
and the rules governing these conversions are identical | dap an
may legally appear as the new type (between the parentheses) in a cast operation | all of the above
type of x is a class, and the declared type of y is an interface. When is the assignment x = y | when the type of x is object
xarr is an array of XXX, and the type of yarr is an array of YYY | sometimes
When is x & y an int | sometimes
negative long is cast to a byte | all of the above
negative byte is cast to a long | negative
operators can perform promotion on their operands | + - ~(nga)
difference between the rules for method-call conversion and the rules for assignment conversion | there is no difference
Which of the following are appropriate situations for assertions | dap an sai : preconditions of a public method
appropriate way to handle invalid arguments in a public method | illegalargumentexception
Suppose salaries is an array containing floats | for (float f:salaries)
Suppose a method called finallyTest() consists of a try block | if the jvm doesn’t crash and
appropriate to pass a cause to an exception’s constructor | thrown in response to catching of a different exception type
When does an exception’s stack trace get recorded in the exception object | is constructed
the string? | none of the above
Which one statement is true about the following code? | if (s1 == s2)
static methods. Which one statement is true about this strategy? | the strategy fails because you cannot subclass java.lang.math.
Which one statement is true about the following code fragment? | compilation fails at line 2.
E Which one statement is true about the following code fragment? | if (s1.equals(s))
2. sbuf.insert(3, "xyz"); | a.true
2. sbuf.append("xyz"); | a.true
4. System.out.println("Line 4"); | a.true
4. System.out.println("Line 4"); | b. false
D.wrapped = 9; | abcd
BD Which of the following are legal? (Choose all that apply.) | list<string> thelist = new vector<string>(); vector <string> thevec = new vector<string>();
which of the following are legal? (Choose all that apply.) | a.iterator<string> iter = names.iterator(); b. for (string s:names)
Which of the following are legal clone()methods in a class called Q13that extends Object? | public object clone()
Which of the following classes implement java.util.List? | a.java.util.arraylist d.java.util.stack
E. subSet | all
E. subMap | cde
F. sc.useDelimiter("\\d+"); | c
10. } | 7
a1[i].equals(a2[i])for every legal index i? | a.java.util.arrays.equals(a1, a2);
AD Which of the following statements are true? | a.stringbuilderis generally faster than stringbuffer. d.stringbufferis threadsafe;stringbuilderis not.
creating an object with the "new" operator, eg. str1 = new String("hello"); | instantiation
a description of a possible object | class
identity, state, behavior | three main characteristics of objects
a section of memory that contains both variables (state information) and methods (small programs) | object
a characteristic of a class definition that is not shared by its objects ("no matter how many objects are made, there will be only one of these") | static
the "new" operator is used with a _____ to create an object | constructor
used when an object is created | class description
accesses members (variables and methods) of an object, eg. len = str1.length(); | dot notation
allow you to use prewritten code/classes/toolkits/packages | library classes
attributes/variables that define the object's state; can hold numbers, characters, strings, other objects | field
actions that an object can take (behaviors) | methods
can be called only from constructors or methods of the same class | private methods
can be called from constructors or methods of any class | public methods
the ability to extend an existing type of objects, by adding new fields and methods, and/or overriding some of the methods | inheritance
hiding information from unwanted outside access and attaching that information only to methods that need access to it | encapsulation
It is a non-static field (dynamic variable). The values are unique to each instance of a class. Ex: the current speed of one bicycle is independent of the current speed of another. | define: instance variable
It is a static variable. There is only one copy of this variable no matter how many times a class has been initiated. Ex: Number of gears in a bicycle that doesn't differ within a class | define: class variable
Keyword: Final (used to indicate that the variable (number) will never change) | what modifier and keyword are used to declare a class variable.
Variable declared within a method that stores the temporary state of a variable. (Only visible to the methods they are declared in and not accessible from rest of the class) | define: local variable
variables that define ex: args | parameters
If variable is constant, use capitals. Ex: BigPinkBear | rules for naming
byte, short, into, long, float, double, boolean, char | what are the 8 primitive data types?
integer with min value of -128 and max value of +127(inclusive) 8 bit (for memory saving) | byte
integer with min value of -32,768 and max value of +32,767(inclusive) 16 bit (for memory saving) | short
integer 32 bit, big enough for most operations (2million) - default choice | int
integer 64 bit, (9 million) | long
32 bit decimal value - do not use for precise values | float
64 bit decimal value - do not use for precise values | double
Can only have two values - true/false | boolean
16 bit Unicode character | char
java.lang.String | character string class is represented by?
Objects have two properties. One is state. What is the other? | behavior
The behavior of an object is represented by ______ ______ | instance methods
The job of a _____ is to initialize instance variables at the time an object is created. | constructor
Nested inside a class declaration are three kinds of declarations. What are they? | constructor declarations
The words public and private are _____ _____ | access modifiers
A method is allowed to have _______, which represent data that will be supplied when the method is called. | parameters
Once a class has been declared, we can create objects that belong to the class. We say that these objects are ______ of the class. | instances
An object variable doesn't actually store an object. Instead, it stores a ______ to an object. | reference
The keyword ______ is placed before a class name in order to create an object. | new
To perform an operation on an object, we _______ one of the instance methods associated with the object. | call
How do you call an instance method | object.methodname(arguments)
Reference variables are known as _______ variables in other programming languages | pointer
What value can we assign to an object variable to indicate that it doesn't currently store an object? | null
A new object that's been created by copying an existing object is said to be a _______. | clone
An object that's no longer accessible through any object variable is said to be _______. | garbage
An instance method that returns the value of an instance variable is said to be an _______. | accessor/getter
An instance method that stores its parameter into an instance variable is said to be an ________. | mutator/setter
An object whose instance variables cannot be changed is said to be _______. | immutable
A mehtod that returns the contents of an object as a string should be named ______. | tostring
The act of joining two strings together to form a single string is called _______. | concatenation
Which method is used to remove extra space from the beginning and end of a string? | trim
What is the value of 11 + 38 + "THX"? | 49thx
is a set of java API for executing SQL statements | jdbc
There are a number of situations in software engineering when it is important for disparate groups of programmers to agree to a "contract" that spells out how their software ____. Each group should be able to write their code without any _____ of how the other group's code is written. Generally speaking, _____ are such contracts. | interacts, interfaces, knowledge
The auto manufacturers must publish an industry-standard ____ that spells out in detail what _____ can be invoked to make the car move (any car, from any manufacturer). | interface, methods
In the Java programming language, an interface is a _____ type, similar to a ____, that can contain only constants, method signatures, and nested types | reference, class
} | constants, method signatures, nested types
Can interfaces be instantiated? | no
Can classes be instantiated? | yes
Interfaces cannot be instantiated—they can only be ________ by classes or ______ by interfaces. | implemented, extended
Interfaces cannot be instantiated—they can only be implemented by _____ or extended by ______. | classes, interfaces
Fill the blank with a method signature of function1. | int turn(int intiger1);
make a public interface called Hello: | public interface hello {}
Fill the blank with a method signature of function1. | function1
Write a public class "Class1" that implements the interface "InterfaceGo" | public class class1 implements interfacego{}
Write a private class "GoClass" that implements the interface "InterfaceForClass" | private class goclass implements interfaceforclass{}
The robotic car example shows an interface being used as an industry standard _______ | application programming interface
A company calls SoftwareFactory makes a package of digital image processing ____ that are sold to companies making ____ graphics programs (Adobe). The image processing company (SoftwareFactory) writes its classes to implement an ____, which it makes public to it's costumers. Adobe then invokes the image processing methods using the signatures and return types defined in the interface. While the SoftwareFactory's API is made public (to its customers), its implementation of the API is kept as a closely guarded secret—in fact, it may revise the implementation at a later date as long as it continues to implement the original interface that its customers have relied on. | methods, end-user, interface
Consider the following application:1. class Q7 {2. public static void main(String args[]) {3. double d = 12.3;4. Decrementer dec = new Decrementer();5. dec.decrement(d);6. System.out.println(d);7. }8. } 9.10. class Decrementer {11. public void decrement(double decMe) 12. decMe = decMe - 1.0;13. }14. }What value is printed out at line 6? | 12.3
Which of the following are legal? | char c = '\u1234';
Consider the following code:1. StringBuffer sbuf = new StringBuffer();2. sbuf = null;3. System.gc();Choose all true statements: | after line 2 executes, the stringbuffer object is eligible for garbage collection.
Which of the following expressions results in a positive value in x? | int x = -1; x = x >>> 5;
Suppose ob1 and ob2 are references to instances of java.lang.Object. If (ob1 == ob2) is false, can ob1.equals(ob2) ever be true? | no
Which of the following operations might throw an ArithmeticException? | none of these
Which of the following operations might throw an ArithmeticException? | /
Which of the following may appear on the left-hand side of an instanceof operator? | a reference
Which of the following may appear on the right-hand side of an instanceof operator? (Choose all that apply.) | a class vs an interface
What is -50 >> 1? | -25
What is the minimal modification that will make this code compile correctly?1. final class Aaa2. {3. int xxx;4. void yyy() { xxx = 1; }5. } 6.7.8. class Bbb extends Aaa9. {10. final Aaa finalref = new Aaa(); 11.12. final void yyy()13. {14. System.out.println("In method yyy()");15. finalref.xxx = 12345;16. }17. } | on line 1, remove the final modifier.
Which of the following statements is true? | transient variables are not serialized.
Which modifier or modifiers should be used to denote a variable that should not be written out as part of its class's persistent state? (Choose the shortest possible answer.) | transient
This question concerns the following class definition:1. package abcde; 2.3. public class Bird {4. protected static int referenceCount = 0;5. public Bird() { referenceCount++; }6. protected void fly() { / Flap wings, etc. / }7. static int getRefCount() { return referenceCount; }8. }Which statement is true about class Bird and the following class Parrot?1. package abcde; 2.3. class Parrot extends abcde.Bird {4. public void fly() {5. / Parrot-specific flight code. /6. }7. public int getRefCount() {8. return referenceCount;9. }10. } | compilation of parrot.java fails at line 7 because method getrefcount() is static in the superclass, and static methods may not be overridden to be nonstatic.
1. package singers; 2.3. class Nightingale extends abcde.Bird {4. Nightingale() { referenceCount++; } 5.6. public static void main(String args[]) {7. System.out.print("Before: " + referenceCount);8. Nightingale florence = new Nightingale();9. System.out.println(" After: " + referenceCount);10. florence.fly();11. }12. } | the program will compile and execute. the output will be before: 0 after: 2.
Suppose class Supe, in package packagea, has a method called doSomething(). Suppose class Subby, in package packageb, overrides doSomething(). What access modes may Subby's version of the method have? (Choose all that apply.) | public vs protected
Which of the following statements are true? | none of the above.
Inty but does not provide implementations for any of the five interface methods. Which is/are true? | the class will compile if it is declared abstract vs the class may not be instantiated.
Which of the following may be declared final? (Choose all that apply.) | classesvsdatavsmethods
Which of the following may follow the static keyword? (Choose all that apply.) | datavsmethodsvscode blocks enclosed in curly brackets
Suppose class A has a method called doSomething(), with default access. Suppose class B extends A and overrides doSomething(). Which access modes may apply to B's version of doSomething()? (Choose all that apply.) | publicvsprotectedvsdefault
True or false: If class Y extends class X, the two classes are in different packages, and class X has a protected method called abby(), then any instance of Y may call the abby() method of any other instance of Y. | false
Which of the following statements are true?1 | a final class may not be extended.
Which of the following statements is correct? (Choose one.) | both primitives and object references can be both converted and cast.
Consider the following class:1. class Cruncher {2. void crunch(int i) {3. System.out.println("int version");4. }5. void crunch(String s) {6. System.out.println("String version");7. } 8.9. public static void main(String args[]) {10. Cruncher crun = new Cruncher();11. char ch = 'p';12. crun.crunch(ch);13. }14. }Which of the following statements is true? (Choose one.) | the code will compile and produce the following output: int version.
Which of the following statements is true? (Choose one.) | object references can be converted in both method calls and assignments, and the rules governing these conversions are identical.
Consider the following code. Which line will not compile?1. Object ob = new Object();2. String[] stringarr = new String[50];3. Float floater = new Float(3.14f);4. ob = stringarr;5. ob = stringarr[5];6. floater = ob;7. ob = floater; | line 6
Consider the following code:1. Cat sunflower;2. Washer wawa;3. SwampThing pogo; 4.5. sunflower = new Cat();6. wawa = sunflower;7. pogo = (SwampThing)wawa;Which of the following statements is true? (Choose one.) | the code will compile but will throw an exception at line 7, because the runtime class of wawa cannot be converted to type swampthing.
Consider the following code:1. Raccoon rocky;2. SwampThing pogo;3. Washer w; 4.5. rocky = new Raccoon();6. w = rocky;7. pogo = w;Which of the following statements is true? (Choose one.) | line 7 will not compile; an explicit cast is required to convert a washer to a swampthing.
Which of the following may legally appear as the new type (between the parentheses) in a cast operation? | all of the above
Suppose the type of xarr is an array of XXX, and the type of yarr is an array of YYY. When is the assignment xarr = yarr; legal? | sometimes
When is x & y an int? (Choose one). | sometimes
What are the legal types for whatsMyType? short s = 10; whatsMyType = !s; | there are no possible legal types.
When a negative long is cast to a byte, what are the possible values of the result? | all of the above
What is the difference between the rules for method-call conversion and the rules for assignment conversion? | there is no difference; the rules are the same.
Consider the following code:1. outer: for (int i = 0; i < 2; i++) {2. for (int j = 0; j < 3; j++) {3. if (i == j) {4. continue outer;5. }6. System.out.println("i = " + i + " j = " + j);7. }8. }Which lines would be part of the output? (Choose all that apply.) | i = 1 j = 0
Which of the following are legal loop constructions? (Choose all that apply.) | int j = 0;for (int k=0, j+k != 10; j++,k++) { system.out.println("j=" + j + ", k=" + k);}
What would be the output from this code fragment?1. int x = 0, y = 4, z = 5;2. if (x > 2) {3. if (y < 5) {4. System.out.println("message one");5. }6. else {7. System.out.println("message two");8. }9. }10. else if (z > 5) {11. System.out.println("message three");12. }13. else {14. System.out.println("message four");15. } | message four
Which statement is true about the following code fragment?1. int j = 2;2. switch (j) {3. case 2:4. System.out.println("value is two");5. case 2 + 1:6. System.out.println("value is three");7. break;8. default:9. System.out.println("value is " + j);10. break;11. } | the output would be the text value is two followed by the text value is three.
Which of the following are legal argument types for a switch statement? | bytevsintvschar
When is it appropriate to pass a cause to an exception's constructor? | when the exception is being thrown in response to catching of a different exception type
Which of the following should always be caught? | checked exceptions
When does an exception's stack trace get recorded in the exception object? | when the exception is constructed
When is it appropriate to write code that constructs and throws an error? | never
Consider the following classes, declared in separate source files:1. public class Base {2. public void method(int i) {3. System.out.print("Value is " + i);4. }5. }1. public class Sub extends Base {2. public void method(int j) {3. System.out.print("This value is " + j);4. }5. public void method(String s) {6. System.out.print("I was passed " + s);7. }8. public static void main(String args[]) {9. Base b1 = new Base();10. Base b2 = new Sub();11. b1.method(5);12. b2.method(6);13. }14. }What output results when the main method of the class Sub is run? | consider the following classes, declared in separate source files:1. public class base {2. public void method(int i) {3. system.out.print("value is " + i);4. }5. }1. public class sub extends base {2. public void method(int j) {3. system.out.print("this value is " + j);4. }5. public void method(string s) {6. system.out.print("i was passed " + s);7. }8. public static void main(string args[]) {9. base b1 = new base();10. base b2 = new sub();11. b1.method(5);12. b2.method(6);13. }14. }what output results when the main method of the class sub is run? | Consider the following classes, declared in separate source files:
1. public class Base {2. public void method(int i) {3. System.out.print("Value is " + i);4. }5. }1. public class Sub extends Base {2. public void method(int j) {3. System.out.print("This value is " + j);4. }5. public void method(String s) {6. System.out.print("I was passed " + s);7. }8. public static void main(String args[]) {9. Base b1 = new Base();10. Base b2 = new Sub();11. b1.method(5);12. b2.method(6);13. }14. }What output results when the main method of the class Sub is run? | value is 5this value is 6
Consider the following class definition:1. public class Test extends Base {2. public Test(int j) {3. }4. public Test(int j, int k) {5. super(j, k);6. }7. }Which of the following forms of constructor must exist explicitly in the definition of the Baseclass? Assume Test and Base are in the same package. (Choose all that apply.) | base() { }vsbase(int j, int k) { }
Which of the following statements are true? (Choose all that apply.) | given that inner is a nonstatic class declared inside a public class outer and that appro- priate constructor forms are defined, an instance of inner can be constructed like this: new outer().new inner()
Which of the following may override a method whose signature is void xyz(float f)? | void xyz(float f)vspublic void xyz(float f)
Suppose x and y are of type TrafficLightState, which is an enum. What is the best way to test whether x and y refer to the same constant? | if (x == y)
Which of the following restrictions apply to anonymous inner classes? | they must be defined inside a code block.
Which methods return an enum constant's name? | name()vstostring()
Which of the following methods may appear in class Y, which extends X? | void dosomething(int a, float b) { ... }
16. } | there will be a compiler error, because class greebo does not correctly implement the
20. } | when the application is run, all three threads (hp1, hp2, and hp3) will execute concurrently, taking time-sliced turns in the cpu.
13. } | yes
A Java monitor must either extend Thread or implement Runnable. | false
Which of the following methods in the Thread class are deprecated? | suspend() and resume()
Which of the following statements about threads is true? | threads inherit their priority from their parent thread.
Which of the following statements about the wait() and notify() methods is true? | the thread that calls wait() goes into the monitor's pool of waiting threads
How many locks does an object have? | one
Is it possible to write code that can execute only if the current thread owns multiple locks? | yes.
How do you prevent shared data from being corrupted in a multithreaded environment? | access the variables only via synchronized methods.
How can you ensure that multithreaded code does not deadlock? | a, b, and c do not ensure that multithreaded code does not deadlock.
Suppose you want to write a class that offers static methods to compute hyperbolic trigonometric functions. You decide to subclass java.lang.Math and provide the new functionality as a set of static methods. Which one statement is true about this strategy? | the strategy fails because you cannot subclass java.lang.math.
4. myMath.cos(0.123)); | compilation fails at line 2.
6. s = null; | compilation succeeds. no exception is thrown during execution.
2. sbuf.insert(3, "xyz"); | true
2. sbuf.append("xyz"); | true
4. System.out.println("Line 4"); | true
4. System.out.println("Line 4"); | false
Which of the following are legal? (Choose all that apply.) | list<string> thelist = new vector<string>();vector <string> thevec = new vector<string>();
Which of the following classes implement java.util.List? | java.util.arraylistvsjava.util.stack
Which line of code tells a scanner called sc to use a single digit as a delimiter? | sc.usedelimiter("\\d");
Which of the following statements are true? | stringbuilder is generally faster than stringbuffer.vsstringbuffer is threadsafe; stringbuilder is not.
Which of the statements below are true? (Choose all that apply.) | unicode characters are all 16 bits.
Which of the statements below are true? (Choose all that apply.) | none of the above.
9. catch (IOException e) { } | 12
2. File f2 = new File(f1, "filename"); | no directory is created, and no file is created.
13. catch (IOException e) { } | the code fails to compile.
Suppose you are writing a class that will provide custom serialization. The class implements java.io.Serializable (not java.io.Externalizable). What access mode should the writeObject() method have? | private
Suppose you are writing a class that will provide custom deserialization. The class implements java.io.Serializable (not java.io.Externalizable). What access mode should the readObject() method have? | private
Suppose class A extends Object; class B extends A; and class C extends B. Of these, only class C implements java.io.Serializable. Which of the following must be true in order to avoid an exception during deserialization of an instance of C? | b must have a no-args constructor.
Suppose class A extends Object; Class B extends A; and class C extends B. Of these, only class C implements java.io.Externalizable. Which of the following must be true in order to avoid an exception during deserialization of an instance of C? | c must have a no-args constructor.
What method of the java.io.File class can create a file on the hard drive? | createnewfile()
15. } | an exception is thrown at line 9.
Given a class with a public variable theTint of type Color, which of the following methods are consistent with the JavaBeans naming standards? | public color getthetint()
void callMe(String... names) { } | within the method, names is an array containing strings.
Which statements are true? | the compiler does not create a default constructor.
Which of the following types are legal arguments of a switch statement? | enumsvsbytes
Which of the following are legal ways to add the elements of the array? | for (int i=0; i<ages.length; i++) sum += ages[i];vsfor (int i:ages) sum += i;
Which lines check that x is equal to four? Assume assertions are enabled at compile time and runtime. | assert x == 4;vsassert x == 4 : "x is not 4";
} | object streamvsfinally
While testing some code that you are developing, you notice that an ArrayIndexOutOf- BoundsException is thrown. What is the appropriate reaction? | none of the above.
Suppose you want to use a DateFormat to format an instance of Date. What factors influence the string returned by DateFormat's format() method? | the style, which is one of short, medium, long, or fullvsthe locale
How do you generate a string representing the value of a float f in a format appropriate for a locale loc? | numberformat nf = numberformat.getinstance(loc); string s = nf.format(f);
aeiou AEIOU | string delim = "\\d+";
Which line prints double d in a left-justified field that is 20 characters wide, with 15 characters to the right of the decimal point? | system.out.format("%-20.15f", d);
} | the code prints "going to sleep," then "waking up," and then "all done."
} | class zebra generates a compiler error
What code at line 4 results in a class that compiles? | super();vsthis(1.23f);
What relationship does the extends keyword represent? | "is a"
When should objects stored in a Set implement the java.util.Comparable interface? | when the set is a treeset
Which methods below honor the hash code contract? | public int hashcode() { return a; }vs public int hashcode() { return (int)math.random();}
Give the following declarations: Vector plainVec; Vector<String> fancyVec;If you want a vector in which you know you will only store strings, what are the advantages of using fancyVec rather than plainVec? | attempting to add anything other than a string to fancyvec results in a compiler error.
The addAll() method of that interface takes a single argument, which is a reference to a collection whose elements are compatible with E. What is the declaration of the addAll() method? | public boolean addall(collection<? extends e> c)
Which of the following may appear in a subclass of Fish named Tuna that is not in the ocean package? | public void swim() { }vssize = 12;
main() method? | n is 10, w.x is 11
5. t = null; | after line 3
What is -15 % -10? | -5
method is used to wait for a client to initiate communications. | accept()
What is the result? (Choose one.) | line 26 prints "a" to system.out.
C? (Choose two.) | the code on line 29 will be executed.vsthe exception will be propagated back to line 27.
What is the result? (Choose one.) | an exception is thrown at runtime.
What is the result? (Choose one.) | third second first snootchy 420
A monitor called mon has 10 threads in its waiting pool; all these waiting threads have the same priority. One of the threads is thr1. How can you notify thr1 so that it alone moves from the Waiting state to the Ready state? (Choose one.) | you cannot specify which thread will get notified.
Which declaration satisfies this requirement? (Choose one.) | public void logit(string... msgs)
A signed data type has an equal number of non-zero positive and negative values available. | false
A thread wants to make a second thread ineligible for execution. To do this, the first thread can call the yield() method on the second thread. | false
Assuming the thread is not interrupted, which one of the following statements is correct? | at line 2, the thread will stop running. it will resume running some time after 100 milliseconds have elapsed.
Which is true about the two classes? (Choose one.) | compilation of class b will fail. compilation of class a will succeed.
What value is printed out at line 6? | 101
Which of the following statements is true? (Choose one.) | the code will compile and run.
After execution, which statements are true? (Choose two.) | x[24] is 0vsx.length is 25
'What is the result? (Choose one.) | compilation fails.
calls modifies the string? (Choose one.) | none of the above
Given arrays a1 and a2, which call returns true if a1 and a2 have the same length, and a1[i].equals(a2[i]) for every legal index i? (Choose one.) | java.util.arrays.equals(a1, a2);
9. } | line 3: private; line 8: protected
A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct? (Choose one.) | public interface b extends a { }
Which code, inserted at line 14, allows the Sprite class to compile? (Choose one.) | nav.direction d = nav.direction.north;
Which code, inserted at line 15, allows the class Sprite to compile? (Choose one.) | new foo() { public int bar(){return 1; } }
Which exception or error should be thrown by the virtual machine? (Choose one.) | stackoverflowerror
and a class Circle that extends and fully implements the Shape class. Which is correct? (Choose one.) | shape s = new circle(); s.setanchor(10,10); s.draw();
What is the result? (Choose one.) | 1 2 3
What is the result? (Choose one.) | compilation fails.
What is the result? (Choose one.) | passed an assertionerror is thrown with the word "stuff" added to the stack trace.
What is the result? (Choose one.) | collie harrier
What is the result? (Choose one.) | dostuff x = 5 main x = 5
Which is true? (Choose one.) | the ownername variable breaks encapsulation.
What is the result? (Choose one.) | compilation fails due to an error in line 29.
Which is true? (Choose one.) | line 57 will print the value 3.
Which code, inserted at line 15, creates an instance of the Point class defined in Line? (Choose one.) | line.point p = new line.point();
What is the result? (Choose one.) | a exception
How can you ensure that multithreaded code does not deadlock? (Choose one.) | there is no single technique that can guarantee non-deadlocking code
How do you use the File class to list the contents of a directory? (Choose one.) | string[] contents = myfile.list();
9. catch (IOException e) { } | 8
which class should you use? (Choose one.) | treeset
In order for objects in a List to be sorted, those objects must implement which interface and method? (Choose one.) | comparable interface and its compareto method.
2. sbuf.append("-University"); | true
2. sbuf.insert(3, "-University"); | true
Is it possible to define a class called Thing so that the following method can return true under certain circumstances? boolean weird(Thing s) { Integer x = new Integer(5); return s.equals(x);} | yes
Is it possible to write code that can execute only if the current thread owns multiple locks? | yes
What is the output? | no output because of compile error at line: b = b * b1;
What is the output? | have a nice day!
What is the output? | ob1 equals ob2
What is the output? | line 4 line 6
What is the output? | line 6
Select correct statement(s) about remote class.(choose one) | all the others choices
Select correct statements about remote interface. (choose 1) | all the others choices
Select INCORRECT statement about deserialize. (choose 1) | we use readobject() method of objectoutputstream class to deserialize.
Suppose a source file contains a large number of import statements and one class definition. How do the imports affect the time required to load the class? (Choose one.) | class loading takes no additional time.
Suppose class A has a method called doSomething(), with default access. Suppose class B extends A and overrides doSomething(). Which access modes may not apply to B's version of doSomething()? (Choose one) | private
Suppose prim is an int and wrapped is an Integer. Which of the following are legal Java statements? (Choose one.) | all the above
Suppose the declared type of x is a class, and the declared type of y is an interface. When is the assignment x = y; legal? (Choose one.) | when the type of x is object
Suppose the type of xarr is an array of XXX, and the type of yarr is an array of YYY. When is the assignment xarr = yarr; legal? (Choose one.) | sometimes
Suppose you are writing a class that will provide custom deserialization.The class implements java.io.Serializable (not java.io.Extenalizable). What access mode should the readObject() method have? (Choose one.) | private
Suppose you are writing a class that will provide custom serialization. The class implements java.io.Serializable (not java.io.Externalizable). What access mode should the writeObject() method have? (Choose one.) | private
Suppose you want to create a custom thread class by extending java.lang.Thread in order to provide some special functionality. Which of the following must you do? (Choose one.) | override run().
The class is the primary class that has the driver information. | drivermanager
The element method alters the contents of a Queue. | false
There are two classes in Java to enable communication using datagrams namely. | datapacket and datasocket
URL referring to databases use the form: | protocol:subprotocol:datasoursename
if (i != null & i.intValue() == 5) System.out.println("Value is 5"); | throws an exception.
9. System.out.println("i = " + i); | the output is i = 20.
} | -1
} | the code compiles, and prints out >>null<<
10. } | an exception is thrown at line 7.
What is -8 % 5? | -3
What is the range of values that can be assigned to a variable of type byte?(Choose one.) | -2^7 through 2^7 - 1
What is the range of values that can be assigned to a variable of type short?(Choose one.) | -2^15 through 2^15 - 1
When a byte is added to a char, what is the type of the result? | int
When a negative byte is cast to a long, what are the possible values of the result? (Choose one.) | negative
When a negative long is cast to a byte, what are the possible values of the result? (Choose one.) | all the above
When a short is added to a float, what is the type of the result? | float
When comparing java.io.BufferedWriter to java.io.FileWriter, which capability exists as a method in only one of the two? (Choose one.) | writing a line separator to the stream
When you compile a program written in the Java programming language,the compiler converts the human-readable source file into platform- independent code that a Java Virtual Machine can understand. What is this platform-independent code called? | bytecode
Whenever a method does not want to handle exceptions using the try block, the is used. | throws
Which of the following are legal loop definitions? (Choose one.) | none of the above.
Which of the following are legal? (Choose two.) | double d = 1.2d;vsdouble d = 1.2d;
Which of the following are legal? (Choose two.) | int c = 0xabcd;vsint d = 0xabcd;
Which of the following are methods of the java.util.SortedSet interface?(Choose one.) | all the above
Which of the following are true? (Choose two.) | an enum may contain public method definitions.vsan enum may contain private data.
Which of the following are valid arguments to the DataInputStream constructor? (Choose one.) | fileinputstream
Which of the following are valid mode strings for the RandomAccessFile constructor? (Choose one.) | all the above
Which of the following calls may be made from a non-static synchronized method? (Choose one.) | all the above
Which of the following classes implement java.util.List? (Choose two.) | java.util.arraylistvsjava.util.stack
Which of the following classes implements a FIFO Queue? (Choose one.) | linkedlist
Which of the following interfaces does not allow duplicate objects? | set
Which of the following is not appropriate situations for assertions?(Choose one) | preconditions of a public method
Which of the following is NOTa valid comment: | /* comment
Which of the following is the most appropriate way to handle invalid arguments in a public method? | throw java.lang.illegalargumentexception.
Which of the following may legally appear as the new type (between the parentheses) in a cast operation? (Choose one.) | all of the above
Which of the following should always be caught? (Choose one.) | checked exceptions
2)A final class may not have any abstract methods. | only statement 2
} | it always returns 0.
13. } | the code compiles and execution produces the output x = 3.
16. } | the program compiles and the output is x = 104.
1. public class A { 2. public String doit(int x, int y) { 3. return “a”; 4. } 5. 6. public String doit(int... vals) { 7. return “b”; 8. } 9. } Given: 25. A a=new A(); 26. System.out.println(a.doit(4, 5)); What is the result? (Choose one.) | line 26 prints “a” to system.out.
1. public class A { 2. public void method1() { 3. B b=new B(); 4. b.method2(); 5. // more code here 6. }7.} 1. public class B { 2. public void method2() { 3. C c=new C(); 4. c.method3(); 5. // more code here 6. } 7.} 1. public class C { 2. public void method3() { 3. // more code here 4. } 5.} 25. try { 26. A a=new A(); 27. a.method1(); 28. }catch (Exception e) { 29. System.out.print(”an error occurred”); 30. } Which two are true if a NullPointerException is thrown on line 3 of class C? (Choose two.) | the code on line 29 will be executed.the exception will be propagated back to line 27.
______ is a set of java API for executing SQL statements. | jdbc
______ method is used to wait for a client to initiate communications. | accept()
___________ drivers that are written partly in the Java programming language and partly in native code. These drivers use a native client library specific to the data source to which they connect. Again, because of the native code, their portability is limited. | type 2
____________ drivers that are pure Java and implement the network protocol for a specific data source. The client connects directly to the data source. | type 4
____________ drivers that use a pure Java client and communicate with a middleware server using a database-independent protocol. The middleware server then communicates the client's requests to the data source. | type 3
______________ drivers that implement the JDBC API as a mapping to another data access API, such as ODBC. Drivers of this type are generally | type 1
1. try { 2. // assume s is previously defined 3. URL u = new URL(s); 4. // in is an ObjectInputStream 5. Object o = in.readObject(); 6. System.out.println("Success"); 7. } 8. catch (MalformedURLException e) { 9. System.out.println("Bad URL"); 10. } 11. catch (StreamCorruptedException e) { 12. System.out.println("Bad file contents"); 13. } 14. catch (Exception e) { 15. System.out.println("General exception"); 16. } 17. finally { 18. System.out.println("Doing finally part"); 19. } 20. System.out.println("Carrying on"); Where: IOException extends Exception StreamCorruptedException extends IOException MalformedURLException extends IOException What lines are output if the constructor at line 3 throws a MalformedURLException? (Choose three.) | bad url doing finally part carrying on
1. try { 2. // assume s is previously defined 3. URL u = new URL(s); 4. // in is an ObjectInputStream 5. Object o = in.readObject(); 6. System.out.println("Success"); 7. } 8. catch (MalformedURLException e) { 9. System.out.println("Bad URL"); 10. } 11. catch (StreamCorruptedException e) { 12. System.out.println("Bad file contents"); 13. } 14. catch (Exception e) { 15. System.out.println("General exception"); 16. } 17. finally { 18. System.out.println("Doing finally part"); 19. } 20. System.out.println("Carrying on"); What lines are output if the methods at lines 3 and 5 complete successfully without throwing any exceptions? (Choose three.) | success doing finally part carrying on
10. interface Foo { 11. int bar(); 12. } 13. 14. public class Beta { 15. 16. class A implements Foo { 17. public int bar() { return 1; } 18. } 19. 20. public int fubar( Foo foo) { return foo.bar(); } 21. 22. public void testFoo() { 23. 24. class A implements Foo { 25. public int bar() { return 2; } 26. } 27. 28. System.out.println( fubar( new A())); 29. } 30. 31. public static void main( String[] argv) { 32. new Beta().testFoo(); 33. } 34. } Which three statements are true? (Choose three.) | the code compiles and the output is 2. if lines 16, 17 and 18 were removed, the code would compile and the output would be 2. if lines 24, 25 and 26 were removed, the code would compile and the output would be 1.
10. public class ClassA { 11. public void methodA() { 12. ClassB classB = new ClassB(); 13. classB.getValue();14. } 15.} And:20. class ClassB { 21. public ClassC classC; 22. 23. public String getValue() { 24. return classC.getValue(); 25. }26.} And: 30. class ClassC { 31. public String value; 32. 33. public String getValue() { 34. value = “ClassB”; 35. return value; 36. }37.} ClassA a = new ClassA(); a.methodA(); What is the result? (Choose one.) | an exception is thrown at runtime.
11. public class Bootchy { 12. int bootch; 13. String snootch; 14. 15. public Bootchy() { 16. this(”snootchy”); 17. System.out.print(”first “); 18. } 19. 20. public Bootchy(String snootch) { 21. this(420, “snootchy”); 22. System.out.print(”second “); 23. } 24. 25. public Bootchy(int bootch, String snootch) { 26. this.bootch = bootch; 27. this.snootch = snootch; 28. System.out.print(”third “); 29. } 30. 31. public static void main(String[] args) { 32. Bootchy b = new Bootchy();33. System.out.print(b.snootch +“ “ + b.bootch); 34. } 35. } | third second first snootchy 420
A _____ dialog prevents user input to other windows in the application unitl the dialog is closed. | modal
A file is created with the following code: 1. FileOutputStream fos = new FileOutputStream("datafile"); 2. DataOutputStream dos = new DataOutputStream(fos); 3. for (int i=0; i<500; i++) 4. dos.writeInt(i); You would like to write code to read back the data from this file. Which solutions will work? (Choose two.) | construct a fileinputstream, passing the name of the file. onto the fileinputstream, chain a datainputstream, and call its readint() method. construct a randomaccessfile, passing the name of the file. call the random access file’s readint() method.
A programmer needs to create a logging method that can accept an arbitrary number of arguments. For example, it may be called in these ways: logIt(”log message 1 “); logIt(”log message2”,”log message3”); logIt(”log message4”, “log message5”, “log message6“); Which declaration satisfies this requirement? (Choose one.) | public void logit(string... msgs)
A thread’s run() method includes the following lines: 1. try { 2. sleep(100); 3. } catch (InterruptedException e) { } Assuming the thread is not interrupted, which one of the following statements is correct? | at line 2, the thread will stop running. it will resume running some time after 100 milliseconds have elapsed.
A(n) ___ object is used to submit a query to a database | statement
A(n) ___ object is uses to obtain a Connection to a Database | drivermanager
After execution of the following code fragment, what are the values of the variables x, a, and b? 1. int x, a = 6, b = 7; 2. x = a++ + b++; | x = 13, a = 7, b = 8
Assume that country is set for each class. Given: 10. public class Money { 11. private String country, name; 12. public String getCountry() { return country; } 13.} and: 24. class Yen extends Money { 25. public String getCountry() { return super.country; } 26. } 28. class Euro extends Money { 29. public String getCountry(String timeZone) { 30. return super.getCountry(); 31. } 32. } Which two are correct? (Choose two.) | euro returns correct country value. compilation fails because of an error at line 25.
Choose the valid identifiers from those listed here. (Choose all that apply.) | all: $int bytes $1 finalist bigollongstringwithmeaninglessname
Class SomeException: 1. public class SomeException { 2. } Class A: 1. public class A { 2. public void doSomething() { } 3. } Class B: 1. public class B extends A { 2. public void doSomething() throws SomeException { } 3. } Which is true about the two classes? (Choose one.) | compilation of class b will fail. compilation of class a will succeed.
Class TestException:1. public class TestException extends Exception { 2. } Class A: 1. public class A { 2. 3. public String sayHello(String name) throws TestException { 4. 5. if(name == null) { 6. throw new TestException(); 7. } 8. 9. return “Hello “+ name; 10. } 11. 12. } A programmer wants to use this code in an application: 45. A a=new A(); 46. System.out.println(a.sayHello(”John”)); Which two are true? (Choose two.) | line 46 will compile if the enclosing method throws a testexception. line 46 will compile if enclosed in a try block, where testexception is caught.
1. class Q6 {2. public static void main(String args[]) {3. Holder h = new Holder();4. h.held = 100;5. h.bump(h);6. System.out.println(h.held);7. }8. }9.10. class Holder {11. public int held;12. public void bump(Holder theHolder) {13. theHolder.held++; 14 }15. }15. }What value is printed out at line 6? | 101
1. class Q7 { 2. public static void main(String args[]) { 3. double d = 12.3; 4. Decrementer dec = new Decrementer(); 5. dec.decrement(d); 6. System.out.println(d); 7. } 8. } 9. 10. class Decrementer {11. public void decrement(double decMe) { 12. decMe = decMe - 1.0; 13. } 14. } What value is printed out at line 6? | 12.3
1. public class Test extends Base { 2. public Test(int j) { 3. } 4. public Test(int j, int k) { 5. super(j, k); 6. } 7. } Which of the following are legitimate calls to construct instances of the Test class? (Choose two.) | test t = new test(1); test t = new test(1, 2);
1. public class Test extends Base { 2. public Test(int j) { 3. } 4. public Test(int j, int k) { 5. super(j, k); 6. } 7. } Which of the following forms of constructor must exist explicitly in the definition of the Base class? Assume Test and Base are in the same package. (Choose two.) | base() { } base(int j, int k) { }
1. class Cruncher { 2. void crunch(int i) { 3. System.out.println("int version"); 4. } 5. void crunch(String s) { 6. System.out.println("String version"); 7. } 8. 9. public static void main(String args[]) { 10. Cruncher crun = new Cruncher(); 11. char ch = "p"; 12. crun.crunch(ch); 13. } 14. } Which of the following statements is true? (Choose one.) | the code will compile and produce the following output: int version.
1. public class Base { 2. public void method(int i) { 3. System.out.print(“Value is “ + i); 4. } 5. } 1. public class Sub extends Base { 2. public void method(int j) { 3. System.out.print(“This value is “ + j); 4. } 5. public void method(String s) { 6. System.out.print(“I was passed “ + s); 7. } 8. public static void main(String args[]) { 9. Base b1 = new Base(); 10. Base b2 = new Sub(); 11. b1.method(5); 12. b2.method(6); 13. } 14. } What output results when the main method of the class Sub is run?(Choose one.) | value is 5this value is 6
Which line will not compile? (Choose one.) 1. Object ob = new Object(); 2. String[] stringarr = new String[50]; 3. Float floater = new Float(3.14f); 4. ob = stringarr; 5. ob = stringarr[5]; 6. floater = ob; 7. ob = floater; | line 6
1. public class Assertification { 2. public static void main(String[] args) { 3. assert args.length == 0; 4 } 5. } Which of the following conditions must be true in order for the code to throw an AssertionError? Assume you are using release 5.0. (Choose two.) | the args array must have one or more elements. the application must be run with the -enableassertions flag or another assertionenabling flag.
1. StringBuffer sbuf = new StringBuffer(); 2. sbuf = null; 3. System.gc(); Choose true statement. (Choose one.) | after line 2 executes, the stringbuffer object is eligible for garbage collection.
1. Cat sunflower; 2. Washer wawa; 3. SwampThing pogo; 4. 5. sunflower = new Cat(); 6. wawa = sunflower; 7. pogo = (SwampThing)wawa; Which of the following statements is true? (Choose one.) Where: Mammal extends Animal Cat, SwampThing extends Mammal Cat implements Washer | the code will compile but will throw an exception at line 7, because the runtime class of wawa cannot be converted to type swampthing.
1. Dog rover, fido; 2. Animal anim; 3. 4. rover = new Dog(); 5. anim = rover; 6. fido = (Dog)anim; Where: Mammal extends Animal Dog extends Mammal Which of the following statements is true? (Choose one.) | the code will compile and run, but the cast in line 6 is not required and can be eliminated.
1. for (int i = 0; i < 2; i++) { 2. for (int j = 0; j < 3; j++) { 3. if (i == j) { 4. continue; 5. } 6. System.out.println("i = " + i + " j = " + j); 7. } 8. } Which lines would be part of the output? (Choose four.) | 0-1 0-2 1-0 1-2
1. outer: for (int i = 0; i < 2; i++) { 2. for (int j = 0; j < 3; j++) { 3. if (i == j) { 4. continue outer; 5. } 6. System.out.println("i = " + i + " j = " + j); 7. } 8. } Which lines would be part of the output? (Choose one.) | i = 1 j = 0
1. Raccoon rocky; 2. SwampThing pogo; 3. Washer w; 4. 5. rocky = new Raccoon(); 6. w = rocky; 7. pogo = w; Which of the following statements is true? (Choose one.) Where: Mammal extends Animal Dog, Raccoon, Swamp Thing extends Mammal Raccoon implements Washer | line 7 will not compile; an explicit cast is required to convert a washer to a swampthing
1. public class Outer { 2. public int a = 1; 3. private int b = 2; 4. public void method(final int c) { 5. int d = 3, f=10; 6. class Inner { 7. private void iMethod(int e) { 8. 9. } 10. } 11. } 12. } Which variables can be referenced at line 8? (Choose four.) | abce
int[] x = new int[25]; After execution, which statements are true? (Choose two.) | x[24] is 0 x.length is 25
1. public class Test1 { 2. public float aMethod(float a, float b) throws IOException {.. } 3. } 1. public class Test2 extends Test1 { 2. 3.} Which of the following methods would be legal (individually) at line 2 in class Test2? (Choose two) | public int amethod(int a, int b) throws exception {...} public float amethod(float p, float q) {...}
1. public class Test1 { 2. public float aMethod(float a, float b) { 3. } 4. 5. } Which of the following methods would be legal if added (individually) at line 4? (Choose three.) | public int amethod(int a, int b) { } public float amethod(float a, float b, int c) throws exception { } private float amethod(int a, int b, int c) { }
11. public static Iterator reverse(List list) { 12. Collections.reverse(list); 13. return list.iterator(); 14. } 15. public static void main(String[] args) { 16. List list = new ArrayList(); 17. list.add(” 1”); list.add(”2”); list.add(”3”); 18. for (Object obj: reverse(list)) 19. System.out.print(obj + “,”); 20. } ‘What is the result? (Choose one.) | compilation fails.
Given a string constructed by calling s = new String("xyzzy"), which of the calls modifies the string? (Choose one.) | none of the above
Given the following class: public class Xyz implements java.io.Serializable { public int iAmPublic; private int iAmPrivate; static int iAmStatic; transient int iAmTransient; volatile int iAmVolatile; } Assuming the class does not perform custom serialization, which fields are written when an instance of Xyz is serialized? (Choose three.) | iampublic iamprivate iamvolatile
Given the following code, and making no other changes, which combination of access modifiers (public, protected, or private) can legally be placed before aMethod() on line 3 and be placed before aMethod() on line 8? (Choose one.) 1. class SuperDuper 2. { 3. void aMethod() { } 4. } 5. 6. class Sub extends SuperDuper 7. { 8. void aMethod() { } 9. } | line 3: private; line 8: protected
enum Spice { NUTMEG, CINNAMON, CORIANDER, ROSEMARY; } | spice sp = spice.nutmeg; object ob = sp; spice sp = spice.nutmeg; object ob = (object)sp;object ob = new object(); spice sp = (spice)ob;
List<String> names = new ArrayList<String>(); which of the following are legal? (Choose two.) | iterator<string> iter = names.iterator(); for (string s:names)
11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. static class B extends A { 15. void process() { System.out.println(”B “); }16. } 17.public static void main(String[] args) { 18. A a=new B(); 19. a.process(); 20. }What is the result? (Choose one.) | compilation fails line 19.
public class Bar { public static void main(String [] args) { int x =5; boolean b1 = true; boolean b2 = false; if((x==4) && !b2) System.out.print("l "); System.out.print("2 "); if ((b2 = true) && b1) System.out.print("3"); }}What is the result? (Choose one.) | 2 3
1. public interface A { 2. String DEFAULT_GREETING = “Hello World”; 3. public void method1(); 4. } A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct? (Choose one.) | public interface b extends a { }
10. abstract public class Employee { 11. protected abstract double getSalesAmount(); 12. public double getCommision() { 13. return getSalesAmount() * 0.15; 14. } 15. } 16. class Sales extends Employee { 17. // insert method here 18. } Which two methods, inserted independently at line 17, correctly complete the Sales class? (Choose two.) | public double getsalesamount() { return 1230.45; } protected double getsalesamount() { return 1230.45; }
10. class MakeFile { 11. public static void main(String[] args) { 12. try { 13. File directory = new File(”d”); 14. File file = new File(directory,”f”); 15. if(!file.exists()) { 16. file.createNewFile(); 17. } 18. }catch (IOException e) { 19. e.printStackTrace ();20. } 21. } 22. } The current directory does NOT contain a directory named “d.” Which three are true? (Choose three.) | an exception is thrown at runtime. line 13 creates a file object named “d.” line 14 creates a file object named “f.’
10. class Nav{ 11. public enum Direction { NORTH, SOUTH, EAST, WEST } 12. } 13. public class Sprite{ 14. // insert code here 15. } Which code, inserted at line 14, allows the Sprite class to compile? (Choose one.) | nav.direction d = nav.direction.north;
10. interface Foo { int bar(); } 11. public class Sprite { 12. public int fubar( Foo foo) { return foo.bar(); } 13. public void testFoo() { 14. fubar( 15. // insert code here 16. ); 17. } 18. } Which code, inserted at line 15, allows the class Sprite to compile? (Choose one.) | new foo() { public int bar(){return 1; } }
10. public class ClassA { 11. public void count(int i) { 12. count(++i); 13. } 14. } And: 20. ClassA a = new ClassA(); 21. a.count(3); Which exception or error should be thrown by the virtual machine? (Choose one.) | stackoverflowerror
11. public abstract class Shape { 12. int x; 13. int y; 14. public abstract void draw(); 15. public void setAnchor(int x, int y) { 16. this.x = x; 17. this.y = y; 18. } 19. } and a class Circle that extends and fully implements the Shape class. Which is correct? (Choose one.) | shape s = new circle(); s.setanchor(10,10); s.draw();
11. public static void main(String[] args) { 12. Object obj =new int[] { 1,2,3 }; 13. int[] someArray = (int[])obj; 14. for (int i: someArray) System.out.print(i +" ");15. } What is the result? (Choose one.) | 1 2 3
11. public static void main(String[] args) { 12. try { 13. args=null; 14. args[0] = “test”; 15. System.out.println(args[0]); 16. }catch (Exception ex) { 17. System.out.println(”Exception”); 18. }catch (NullPointerException npe) { 19. System.out.println(”NullPointerException”); 20. } 21. } What is the result? (Choose one.) | compilation fails.
11. public static void parse(String str) { 12. try { 13. float f= Float.parseFloat(str); 14. } catch (NumberFormatException nfe) { 15. f = 0; 16. } finally { 17. System.out.println(f); 18. } 19. } 20. public static void main(String[] args) { 21. parse("invalid"); 22. } What is the result? (Choose one.) | compilation fails.
11. String test = “This is a test”; 12. String[] tokens = test.split(”\s”); 13. System.out.println(tokens.length); What is the result? (Choose one.) | compilation fails.
12. public class AssertStuff { 14. public static void main(String [] args) { 15. int x= 5; 16. int y= 7; 18. assert (x > y): “stuff”; 19. System.out.println(”passed”); 20. } 21. } And these command line invocations: java AssertStuff java -ea AssertStuff What is the result? (Choose one.) | passed an assertionerror is thrown with the word “stuff” added to the stack trace.
12. public class Test { 13. public enum Dogs {collie, harrier}; 14. public static void main(String [] args) { 15. Dogs myDog = Dogs.collie; 16. switch (myDog) { 17. case collie: 18. System.out.print(”collie “); 19. case harrier: 20. System.out.print(”harrier “); 21. } 22. } 23. } What is the result? (Choose one.) | collie harrier
13. public class Pass { 14. public static void main(String [] args) { 15. int x = 5; 16. Pass p = new Pass(); 17. p.doStuff(x); 18. System.out.print(" main x = "+ x); 19. } 20. 21. void doStuff(int x) { 22. System.out.print("doStuff x = "+ x++); 23. } 24. } What is the result? (Choose one.) | dostuff x = 5 main x = 5
13. public class Pass { 14. public static void main(String [] args) { 15. int x = 5; 16. Pass p = new Pass(); 17. p.doStuff(x); 18. System.out.print(" main x = "+ x); 19. } 20. 21. void doStuff(int x) { 22. System.out.print("doStuffx = "+ x++); 23. } 24. } What is the result? (Choose one.) | dostuffx = 5 main x = 5
public class Q { public static void main(String argv[]){ int anar[]=new int[]{1,2,3}; System.out.println(anar[1]); | 2
Which of the following statements is INCORRECT | a method in an interface can access class level variables
Which of the following is legal? | double d = 1.2d;
Which of the following operations might throw an ArithmeticException? | %
class Base {} class Sub extends Base {} class Sub2 extends Base {} public class CEx { public static void main(String argv[]) { Base b = new Base(); Sub s = (Sub) b; }} | compile time exception
Which of the following statements is incorrect | vector does not allow duplicate elements
select the most correct statement | a (non-local) inner class may be declared as public, protected, private, static, final or abstract.
which of the following statements is true about two base protocols used for networking: TCP (Transmissions Control Protocol) and UDP (User Datagram Protocol)? | tcp is a connection-based protocol and udp is not connection-based protocol
Which of the statements below are true? | to check whether the file denoted by the abstract pathname is a directory or not, call the isdirectory() method of the file class
public class Main{ public static void main(String argv[]){ String s = "Hi there"; int pos = s.indexOf(" "); String r = s.substring(0,pos); String s2 = new String(new char[]{'H','i'}); if (r.equals(s2)) System.out.println("EQUAL"); else System.out.println("NOT EQUAL"); System.out.println(""); } } | equal
which of the following methods of the collections class can be used to find the largest value in a vector? | collection.max()
select the correct statement which set the layout manager of a given frame to flowlayoutmanager | setlayout(new flowlayout());
public class Bground extends Thread{ public static void main(String argv[]){ Bground b = new Bground(); b.run(); } public void start(){ for (int i = 0; i <10; i++){ System.out.println("Value of i = " + i); } } } | clean compile but no output at runtime
public class EqTest{ public static void main(String argv[]}{ EqTest e = new EqTest(); } | if(s.equalsignorecase(s2))
public class Main { public static void main(String Argv[]) { A t = new A("One"); t.run(); A h = new A("Two"); h.run(); } } class A extends Thread { private String sTname = ""; A(String s) { sTname = s; } } public void run(){ for(int i =0;i<2;i++){ try{ sleep(1000); } catch(InterruptedException e){} yield(); System.out.print(sTname+""); } } | compile time error, class rpcraven does not import java.lang.thread
abstract class Base{ abstract public void myfunc(); public void another(){ System.out.println("Another method"); }}public class Abs extends Base{ public static void main(String argv[]){ Abs a = new Abs(); a.amethod(); } public void myfunc(){ System.out.println("My Func"); } public void amethod(){ myfunc(); }} | the code will compile and run, printing out the words "my func"
public class MyMain{ public static void main(String argv){ System.out.println("Hello cruel world"); } } | the code will compile but will complain at run time that main is not correctly defined
Which of the following are Java modifiers? | public private transient
class Base{ abstract public void myfunc(); public void another(){ System.out.println("Another method"); }}public class Abs extends Base{ public static void main(String argv[]){ Abs a = new Abs(); a.amethod(); } public void myfunc(){ System.out.println("My func"); } public void amethod(){ myfunc(); }} | the compiler will complain that the base class is not declared as abstract.
which of the following methods of java.io.file can be used to create a new file | there is no such method. just do file f = new file("filename.txt"), then the new file, named filename.txt will be created
Why might you define a method as native? | to get to access hardware that java does not know about to write optimised code for performance in a language such as c/c++
class Base{ public final void amethod(){ System.out.println("amethod"); } } public class Fin extends Base{ public static void main(String argv[]){ Base b = new Base(); b.amethod(); } } | success in compilation and output of "amethod" at run time.
public class Mod{ public static void main(String argv[]){ } public static native void amethod(); } | compilation and execution without error
private class Base{} public class Vis{ transient int iVal; public static void main(String elephant[]){ } } | compile time error: base cannot be private
//File P1.java package MyPackage; class P1{ void afancymethod(){ System.out.println("What a fancy method"); } } //File P2.java public class P2 extends P1{ public static void main(String argv[]){ P2 p2 = new P2(); p2.afancymethod(); }} | p1 compiles cleanly but p2 has an error at compile time
public class MyAr{ public static void main(String argv[]){ int[] i = new int[5]; System.out.println(i[5]); } } | an error at run time
20. public class CreditCard { 22. private String cardlD; 23. private Integer limit; 24. public String ownerName; 26. public void setCardlnformation(String cardlD, 27. String ownerName, 28. Integer limit) { 29. this.cardlD = cardlD; 30. this.ownerName = ownerName; 31. this.limit = limit; 32. } 33. } | the ownername variable breaks encapsulation.
23. Object [] myObjects = { 24. new Integer(12), 25. new String(”foo”), 26. new Integer(5), 27.new Boolean(true) 28. }; 29. java.util.Array.sort(myObjects); 30. for( int i=0; i<myObjects.length; i++) { 31. System.out.print(myObjects[i].toString()); 32. System.out.print(” “); 33. } What is the result? (Choose one.) | compilation fails due to an error in line 29.
31. // some code here 32. try { 33. // some code here 34. } catch (SomeException se) { 35. // some code here 36. } finally { 37. // some code here 38. } Under which three circumstances will the code on line 37 be executed? (Choose three.) | the code on line 33 throws an exception. the code on line 35 throws an exception. the code on line 33 executes successfully.
33. try { 34. // some code here 35. }catch (NullPointerException e1) { 36. System.out.print(”a”); 37. }catch (RuntimeException e2) { 38. System.out.print(”b”); 39. } finally { 40. System.out.print(”c”); 41. } What is the result if a NullPointerException occurs on line 34? (Choose one.) | ac
55. int []x= {1, 2,3,4, 5}; 56. int y[] =x; 57. System.out.println(y[2]); Which is true? (Choose one.) | line 57 will print the value 3.
8. public class test { 9. public static void main(String [] a) { 10. assert a.length == 1; 11. } 12.} Which two will produce an AssertionError? (Choose two.) | java -ea test, java -ea test file1 file2
1. public class TestString3 { 2. public static void main(String[] args) { 3. // insert code here 5. System.out.println(s); 6. } 7. } Which two code fragments, inserted independently at line 3, generate the output 4247? (Choose two.) | stringbuffer s = new stringbuffer(”123456789”); s.delete(0,3).replace( 1,3, “24”).delete(4,6); stringbuilder s = new stringbuilder(”123456789”); s.delete(0,3).delete( 1 ,3).delete(2,5).insert( 1, “24”);
10. class Line { 11. public static class Point { } 12. } 13. 14. class Triangle { 15. // insert code here 16. } Which code, inserted at line 15, creates an instance of the Point class defined in Line? (Choose one.) | line.point p = new line.point();
10. public class Bar { 11. static void foo(int...x) { 12. // insert code here 13. } 14. } Which two code fragments, inserted independently at line 12, will allow the class to compile? (Choose two.) | for(int z : x) system.out.println(z); for( int i=0; i< x.length; i++ ) system.out.println(x[i]);
11. public interface Status { 12. /* insert code here */ int MY_VALUE = 10; 13. } Which three are valid on line 12? (Choose three.) | final static public
class A { public void process() { System.out.print("A "); } public static void main(String[] args) { try { ((A)new B()).process(); } catch (Exception e) { System.out.print("Exception "); } }}class B extends A { public void process() throws RuntimeException { super.process(); if (true) throw new RuntimeException(); System.out.print("B"); }} | a exception b
How can you ensure that multithreaded code does not deadlock? (Choose one.) | there is no single technique that can guarantee non-deadlocking code.
How can you force garbage collection of an object? (Choose one.) | garbage collection cannot be forced.
How do you prevent shared data from being corrupted in a multithreaded environment? (Choose one.) | access the variables only via synchronized methods.
How many bytes does the following code write to file dest? (Choose one.) 1. try { 2. FileOutputStream fos = newFileOutputStream("dest"); 3. DataOutputStream dos = new DataOutputStream(fos); 4. dos.writeInt(3); 5. dos.writeFloat(0.0001f); 6. dos.close(); 7. fos.close(); 8. } 9. catch (IOException e) { } | 12
How many locks does an object have? (Choose one.) | one
If all three top-level elements occur in a source file, they must appear in which order? (Choose one.) | package declaration, imports, class/interface/enum definitions.
If class Y extends class X, the two classes are in different packages, and class X has a protected method called abby(), then any instance of Y may call the abby() method of any other instance of Y. | false
If you attempt to compile and execute the following application, will it ever print out the message In xxx? 1. class TestThread3 extends Thread { 2. public void run() { 3. System.out.println("Running"); 4. System.out.println("Done"); 5. } 6. 7. private void xxx() { 8. System.out.println(“In xxx”); 9. } 10. 11. public static void main(String args[]) { 12. TestThread3 ttt = new TestThread3(); 13. ttt.xxx(); 14. ttt.start(); 12. } 13. } | yes
If you need a Set implementation that provides value-ordered iteration, which class should you use? (Choose one.) | treeset
In order for objects in a List to be sorted, those objects must implement which interface and method? (Choose one.) | comparable interface and its compareto method.
In the following code fragment, after execution of line 1, sbuf references an instance of the StringBuffer class. After execution of line 2, sbuf still references the same instance. 1. StringBuffer sbuf = new StringBuffer("FPT"); 2. sbuf.append("-University"); | true
In the following code fragment, after execution of line 1, sbuf references an instance of the StringBuffer class. After execution of line 2, sbuf still references the same instance. 1. StringBuffer sbuf = new StringBuffer("FPT"); 2. sbuf.insert(3, "-University"); | true
In the following code, what are the possible types for variable result? (Choose the most complete true answer.) 1. byte b = 11; 2. short s = 13; 3. result = b * ++s; | int, long, float, double
Interface ____ helps manage the connection between a Java program and a database | connection
Is it possible to define a class called Thing so that the following method can return true under certain circumstances? boolean weird(Thing s) { Integer x = new Integer(5); return s.equals(x); } | yes
JDBC supports ______ and ______ models. | two-tier and three-tier
public class Test{ public static void main(String[] args){ byte b = 2; byte b1 = 3; b = b * b1; System.out.println("b="+b); } } What is the output? | no output because of compile error at line: b = b * b1;
public class Test{ public static void main(String[] args){ Object ob1= new Object(); Object ob2= new Object(); if(ob1.equals(ob2)) System.out.println("ob1 equals ob2"); if(ob1==ob2) System.out.println("ob1==ob2"); System.out.println("Have a nice day!"); } } What is the output? | have a nice day!
public class Test{ public static void main(String[] args){ Object ob1= new Object(); Object ob2= ob1; if(ob1.equals(ob2)) System.out.println("ob1 equals ob2"); if(ob1==ob2) System.out.println("ob1==ob2"); System.out.println("Have a nice day!"); } } What is the output? | ob1 equals ob2 ob1==ob2 have a nice day!
public class Test{ public static void main(String[] args){ String s1 = "xyz"; String s2 = "xyz"; if (s1 == s2) System.out.println("Line 4"); if (s1.equals(s2)) System.out.println("Line 6"); } } What is the output? | line 4 line 6
public class Test{ public static void main(String[] args){ String s1 = "xyz"; String s2 = new String("xyz"); if (s1 == s2) System.out.println("Line 4"); if (s1.equals(s2)) System.out.println("Line 6");} } What is the output? | line 6
public class Test{ public static void main(String[] args){ String s1 = "xyz"; String s2 = new String(s1); s2.intern(); if (s1 == s2) System.out.println("Line 4"); if (s1.equals(s2)) System.out.println("Line 6");} } What is the output? | line 6
public class Test{ public static void main(String[] args){ String s1 = "xyz"; String s2 = new String(s1); s2=s2.intern(); if (s1 == s2) System.out.println("Line 4"); if (s1.equals(s2)) System.out.println("Line 6"); } } What is the output? (choose 1) | line 4 line 6
Select correct statement about RMI. (choose 1) | all the above
Select INCORRECT statement about serialization. (choose 1) | when an object output stream serializes an object that contains references to another object, every referenced object is not serialized along with the original object.
Select incorrect statement about RMI server.(choose 1) | a client accesses a remote object by specifying only the server name.
Select incorrect statement about ServerSocket class. (choose 1) | to make the new object available for client connections, call its accept() method, which returns an instance of serversocket
Select incorrect statement about Socket class. (choose 1) | the java.net.socket class contains code that knows how to find and communicate with a server through udp
Select the correct statement about JDBC two-tier processing model. | a user's commands are delivered to the database or other data source, and the results of those statements are sent back to the user.
Statement objects return SQL query results as ___ objects | resultset
Study the statements: 1)When a JDBC connection is created, it is in auto-commit mode 2)Once auto-commit mode is disabled, no SQL statements will be committed until you call the method commit explicitly | both 1 and 2 are true
Suppose a method called finallyTest() consists of a try block, followed by a catch block, followed by a finally block. Assuming the JVM doesn’t crash and the code does not execute a System.exit() call, under what circumstances will the finally block not begin to execute? (Choose one.) | if the jvm doesn't crash and the code does not execute a system.exit() call, the finally block will always execute.
Suppose a source file contains a large number of import statements. How do the imports affect the time required to compile the source file? (Choose one.) | compilation takes slightly more time.
Suppose class A extends Object; Class B extends A; and class C extends B. Of these, only class C implements java.io.Externalizable. Which of the following must be true in order to avoid an exception during deserialization of an instance of C? (Choose one.) | c must have a no-args constructor.
Suppose class A extends Object; class B extends A; and class C extends B. Of these, only class C implements java.io.Serializable. Which of the following must be true in order to avoid an exception during deserialization of an instance of C? (Choose one.) | b must have a no-args constructor.
Suppose class A has a method called doSomething(), with default access. Suppose class B extends A and overrides doSomething(). Which access modes may not apply to B’s version of doSomething()? (Choose one) | private
Suppose class Supe, in package packagea, has a method called doSomething(). Suppose class Subby, in package packageb, overrides doSomething(). What access modes may Subby’s version of the method have? (Choose two.) | public protected
Suppose class X contains the following method: void doSomething(int a, float b) { … } Which of the following methods may appear in class Y, which extends X? (Choose one.) | public void dosomething(int a, float b) { … }
Suppose interface Inty defines five methods. Suppose class Classy declares that it implements Inty but does not provide implementations for any of the five interface methods. Which are true? (Choose two.) | the class will compile if it is declared abstract. the class may not be instantiated.
Suppose salaries is an array containing floats. Which of the following are valid loop control statements for processing each element of salaries? (Choose one.) | for (float f:salaries)
Suppose x and y are of type TrafficLightState, which is an enum. What is the best way to test whether x and y refer to the same constant? (Choose one.) | if (x == y)
Suppose you are writing a class that will provide custom deserialization. The class implements java.io.Serializable (not java.io.Externalizable). What access mode should the readObject() method have? (Choose one.) | private
Swing components cannot be combined with AWT components. | true
The ______ class is the primary class that has the driver information. | drivermanager
The ______ class is used to implement a pull-down menu that provides a number of items to select from. | menu
The border layout resizes the ______ components to fill the remaining centre space. | center
public class MyClass1 { public static void main(String argv[]) {} /*Modifier at XX*/ class MyInner {} } What modifier would be illegal at XX in the above code? | friend
What will happen when you attempt to compile and run this code? class Base{ abstract public void myfunc(); public void another(){ System.out.println("Another method"); }} public class Abs extends Base{ public static void main(String argv[]){ Abs a = new Abs(); a.amethod(); } public void myfunc(){ System.out.println("My func"); } public void amethod(){ myfunc(); } } | the compiler will complain that the base class is not declared as abstract
Given the following class definition, which if the following methods could be legally placed after the comment //Here? (Select two) public class Rid{ public void amethod(int i, String s){} //Here } | public void amethod(int i, string s){} public void amethod(string s, int i){}
Select correct statement (1) The Swing's list component(JList) can display text only (2) The Swing's button(JButton) can not contain an image. (3) The Swing's label(JLabel) can present an image | 1 3
What is the output of the following code: class Main{ public static void main(String[] argv){ byte b1 = 10; byte b2 = 9; b1 = (byte)(b1 | b2); system.out.println(b1); }} | 11
What is the purpose of the finally clause of a try-catch-finally statement? (Select correct answer) | the finally clause is used to provide the capability to execute code no matter whether or matter whether or not an exception is throw or caught
Consider the following class:1. class Test {2. void foo(int i) {3. System.out.println("int version");4. }5. void foo(String s) {6. System.out.println("String version");7. }8.9. public static void main(String args[]) {10. Test t = new Test();11. char ch = 'p';12. t.foo(ch);13. }14. }Which of the following statements is true? | the code will compile and produce the following output: int version.
What will happen when you try compiling and running this code? public class Ref{ public static void main(String argv[]){ Ref r = new Ref(); r.amethod(r); } public void amethod(Ref r){ int i = 99; multi(r); System.out.println(i); } public void multi(Ref r){ r.i = r.i*2; }} | error at compile time
Which of following Java operations cause compile-time errors? int m=5, n=7; float x=m; //1 double y=n; //2 m = y; //3 n = x; //4 | 3, 4
Select correct statement(s). (Select one option only) (1) Swing is part of the Java Foundation Classes and provides a rich set of GUI components. (2) Before you think about what your GUI will look like, it's important to think about what it will. | 1, 2
With respect to processing models for database access, in the ... model a Java application talks directly to the data source | two-tier
What will happen when you attempt to compile and run the following program (please note that the Object class does not have the foo() method): class A{ void foo(){ System.out.print("A");}} class B{ void foo(){ System.out.print("B");}} class C extends A{ void foo(){ System.out.print("C");}} class Main{ public static void main(String[] args){ Object t = new A(); t.foo(); t = new B(); t.foo(); t = new C(); t.foo(); } } | compile-time error
What is the output of the following code: class Main{ public static void main(String args[]){ int k=11; System.out.print(k>>3); System.out.print(4&3); System.out.print(4 | 3); system.out.println(); }} | 107
Suppose class X contains the following method: void doSomething(int a, float b){ ... } Which of the following methods may appear in class Y, which extends X? | public void dosomething(int a, float b){ ... }
int j; for(int i=0; i<14; i++){ if(i<10){ j = 2 + i; } System.out.println("j: " + j + "i: " +i); } What is WRONG with the above code? | integer "j" is not initialized.
What is -8%5? | -3
What happens when you try to compile and run the following program? import java.ulti.*; public class Main{ public static void main(String args[]){ String s = "ABC 4 5 6 8"; Scanner sc = new Scanner(s); sc.next(); System.out.println(sc.nextInt() + sc.nextInt() + sc.nextInt()); }} | the program will have a runtime exception.
Which is the INCORRECT answer for the following question: What can cause a thread to stop executing? | a call to the halt method of the thread class
Which of the following classes supports developers to get the pointer of a file? | java.io.randomaccessfile
Which of the following is Java keyword? | new
With respect to steps in RMI implementation: (1) Create the remote interface (2) Create the remote object (3) Create the client object (4) Create the Stub The order should be followed: | 1, 2, 4, 3
Give the following code, which of the following will not compile? enum Spice{ NUTMEG, CINNAMON, CORIANDER, ROSEMARY; } | string ob = new string(); spice sp = ob;
Select the correct statement: | an object reference can be cast to an interface reference when the object implements the referenced interface.
The default layout manager for every JPane is | flowlayout
Which of the following is NOT a valid comment | /*comment
Suppose salaries is an array containing floats. Which of the following are valid loop control statements for processing each element of salaries? | for(float f:salaries)
With respect to networking and the client-server model. (1) A server runs on a specific computer and has a socket that is bound to a specific port number. The server just waits, listening to the socket for a client to make a connection request.(2) To connect to the server, the client must know the hostname or IP of the machine on which the server is running and the port number on which the server is listening | true, true.
With respect to networking and the client-server model. (1) A socket is one endpoint (a combination of an IP address and a port number) of a two-way communication link between two programs running on the network..(2) TCP (Transmission Control Protocol) is a connection-based protocol that provides a reliable flow of data between two computers.(3) UDP (User Datagram Protocol) is a protocol that sends independent packets of data, called datagrams, from one computer to another with no guarantees about arrival. | true, true, true
How do you change the value of the object k that is encapsulated by a wrapper class after you have instantiated it? | use the k.setxxx() method defined for the wrapper class
What happens when you try to compile and run the following program? import java.ulti.*; public class Main{ public static void main(String argv[]){ Vector<Integer> t = new Vector<Integer>(); t.add(12); t.add(2); t.add(5); t.add(2); Iterator<Integer> i = t.iterator(); int sum=0; while(i.hasNext()) sum += i.next(); System.out.println(sum); }} | the program will print out 21
Which of the following are true? (Select two) | system.out has a println() method. system.out has a format() method.
What will happen when you attempt to compile and run the following program: class Box{ int a,b; Box(){} Box(int x, int y){a=x;b=y;} } class Reg extends Box{ int c; Reg(){} Reg(int x, int y, int z){ this.c = z; super(x,y); } void display(){ System.out.println(a+b+c); }} class Main{ public static void main(String[] args){ Reg t = new Reg(2,3,4); t.display(); }} | compile time error
What results from running the following code? 1. public class Xor{ 2. public static void main(String args[]){ 3. byte b = 10; //00001010 binary 4. byte c = 15; //00001111 binary 5. b = (byte)(b ^ c); 6. System.out.println("b contains " + b); 7. } 8. } | the output: b contains 5
Which component can display an image, but cannot get focus? | jlabel
Which of the following is legal loop construction? | int j = 0; for(int k=0; j+k != 10; j++, k++){ system.out.println("j=" + j + ", k="+k); }
import java.util.*; public class Main{ public static void main(String argv[]){ String s = "ABCk23k5.9"; Scanner t = new Scanner(s); t.useDelimiter("[k]");//use the character k as delimiter String u = t.next(); while(t.hasNext()) u += t.next(); System.out.println(u.substring(2)); }} | c235.9
Which of the following best describes the use of the synchronized keyword? | ensures only one thread at a time may access a method or object
Select the order of access modifiers from least restrictive to most restrictive. | public, protected, default, private
When is x & y an int? | when neither x nor y is a float, or a double
What will be printed out if this code is run with the following command line? java mypro good morning public class mypro{ public static void main(String argv[]){ System.out.println(argv[2]); }} | exception raised "java.lang.arrayindexoutofboundsexception: 2"
class Test{ public int fun(int x){ int count=1; try{ count += x; foo(count); count++; } catch(Exception e){ count -= x; } return (count); } public int foo(int k){ if(true) throw new ArithmeticException(); return(k);}} class Main{ public static void main(String[] args){ Test t = new Test(); System.out.println(t.fun(2)); }}} | 1
public int fubar(Foo foo){ return foo.bar(); } public void testFoo(){ class A implements Foo{ public int bar(){ return 2; } } System.out.println(fubar(new A())); } public static void main(String[] argv){ new Beta().testFoo(); } } Which statement is true? | the code compiles and the output is 2
class Base{ public void Base(){ System.out.println("Base"); } } public class In extends Base{ public void main(String argv[]){ In i = new In(); } } | compilation and no output at runtime
Which of the following are true? (Select two) | once the thread terminates, it cannot be restarted by calling the function start() again when a thread terminates its processing, it enters the dead state
Which of the following are true about garbage collection? | garbage collection does not guarantee that a program will not run out of memory
What will be printed out if you attempt to compile and run the following code? int i=9; switch(i){ default: System.out.println("default"); case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); } | default zero
Which of the following is INCORRECT? | char c = \u1234;
Which of the following statements is true? | constructors are not inherited
public class C{ public void method3(){ //more code here }} try{ A a = new A(); a.method1(); }catch(Exception e){ System.out.print("an error occurred"); } Which is true if a NullPointerException is thrown on line 3 of class C? | the code on line 29 will be executed.
Which of the following statements is true? | given that inner is a nonstatic class declared inside a public class outer and that appropriate constructor forms are defined, an instance of inner can be constructed like this: new outer().new inner()
Which of the following is illegal statement? | float f=1.01;
What will happen when you compile and run the following code? public class Scope{ private int i; public static void main(String argv[]){ Scope s = new Scope(); s.amethod(); }//End of main public static void amethod(){ System.out.println(i); }//end of amethod }//End of class | a compile time error
Suppose class X contains the following method: | void dosomething(int a, float b){ ... }
Which line contains only legal statements? | string x = "hello", int y = 9; x = x + y;
Which of the following operations might throw an ArithmeticException? (select two) | % /
How do you prevent shared data from being corrupted in a multithreaded environment? | access the variables only via synchronized methods
Which of the following is true? | the >> operator carries the sign bit when shifting right. the >>> zero-fills bits that have been shifted out
Select the most correct statement: | a protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.
11. public inteface Status{ 12. /*insert code here*/ int MY_VALE = 10; 13. } Which three are valid in line 12? (select three) | final static public
Consider the following code: 1. Dog rover, fido; 2. Animal anim; 3. 4. rover = new Dog(); 5. anim = rover; 6. fido = (Dog)anim; Where: Mammal extends Animal Dog extends Mammel Which of the following statements is true? | the code will compile and run
You want to loop through an array and stop when you come to the last element. Being a good java programmer and forgetting everything you ever knew about C/C++ you know that arrays contain information about their size. Which of the following can you use? | myarray.length;
import java.awt.*; public class FlowAp extends Frame{ public static void main(String argv[]){ FlowAp fa=new FlowAp(); fa.setSize(400,300); fa.setVisible(true); } FlowAp(){ add(new Button("One")); add(new Button("Two")); add(new Button("Three")); add(new Button("Four")); }//End of constructor }//End of Application | a frame with one large button marked four in the centre
How do you indicate where a component will be positioned using Flowlayout? | do nothing, the flowlayout will position the component
How do you change the current layout manager for a container | use the setlayout method
Which of the following are fields of the GridBagConstraints class? | ipadx fill insets
import java.awt.*; public class CompLay extends Frame{ public static void main(String argv[]){ CompLay cl = new CompLay(); } CompLay(){ Panel p = new Panel(); p.setBackground(Color.pink); p.add(new Button("One")); p.add(new Button("Two")); p.add(new Button("Three")); add("South",p); setLayout(new FlowLayout()); setSize(300,300); setVisible(true); } } | the buttons will run from left to right along the top of the frame
Which statements are correct about the anchor field? | it is a field of the gridbagconstraints class for controlling component placement a valid settting for the anchor field is gridbagconstraints.north
Is the following statement true or false? When using the GridBagLayout manager, each new component requires a new instance of the GridBagConstraints class. | false
Which most closely matches a description of a Java Map? | an interface that ensures that implementing classes cannot contain duplicates
How does the set collection deal with duplicate elements? | the add method returns false if you attempt to add an element with a duplicate value
What can cause a thread to stop executing? | the program exits via a call to exit(0); the priority of another thread is increased a call to the stop method of the thread class
For a class defined inside a method, what rule governs access to the variables of the enclosing method? | the class can only access final variables
Under what circumstances might you use the yield method of the Thread class | to call from the currently running thread to allow another thread of the same or higher priority to run
public class Hope{ public static void main(String argv[]){ Hope h = new Hope(); } protected Hope(){ for(int i =0; i <10; i ++){ System.out.println(i); } } } | compilation and running with output 0 to 9
public class MySwitch{ public static void main(String argv[]){ MySwitch ms= new MySwitch(); ms.amethod(); } public void amethod(){ int k=10; switch(k){ default: //Put the default at the bottom, not here System.out.println("This is the default output"); break; case 10: System.out.println("ten"); case 20: System.out.println("twenty"); break; } } } | none of these options
Which of the following is the correct syntax for suggesting that the JVM performs garbage collection | system.gc();
public class As{ int i = 10; int j; char z= 1; boolean b; public static void main(String argv[]){ As a = new As(); a.amethod(); } public void amethod(){ System.out.println(j); System.out.println(b); } } | compilation succeeds and at run time an output of 0 and false
public class Arg{ String[] MyArg; public static void main(String argv[]){ MyArg=argv; } public void amethod(){ System.out.println(argv[1]); } } | compile time error
public class StrEq{ public static void main(String argv[]){ StrEq s = new StrEq(); } private StrEq(){ String s = "Marcus"; String s2 = new String("Marcus"); if(s == s2){ System.out.println("we have a match"); }else{ System.out.println("Not equal"); } } } | output of "not equal"
Which of the following classes implement java.util.List? (Choose two.) | arraylist+stack
Which of the following classes implements a FIFO Queue? (Choose one.) | linkedlist
Which of the following declarations are illegal? (Choose three.) | default string s;abstract double d;abstract final double hyperboliccosine();
Which of the following expressions are legal? (Choose two.) | int x = 6; if (!(x > 3)) {};int x = 6; x = ~x;
Which of the following expressions are legal? (Choose two.) | string x = "hello"; int y = 9; x += y;string x = "hello"; int y = 9; x = x + y;
Which of the following expressions results in a positive value in x? (Choose one.) | int x = –1; x = x >>> 5;
Which of the following interfaces does not allow duplicate objects? (Choose one.) | set
Which of the following is not appropriate situations for assertions? (Choose one) | preconditions of a public method
Which of the following is true? (Choose one.) | none of the above
Which of the following is(are) true? (Choose one.) | all the above
Which of the following may appear on the right-hand side of an instanceof operator? (Choose two.) | a class+an interface
Which of the following may be declared final? (Choose two.) | classes+methods
Which of the following may be statically imported? (Choose two.) | static method names+ static field names
Which of the following may follow the static keyword? (Choose three.) | data+methods+code blocks enclosed in curly brackets
Which of the following may legally appear as the new type (between the parentheses) in a cast operation? (Choose one.) | all of the others
Which of the following may not be synchronized? (Choose one.) | classes
Which of the following may override a method whose signature is void xyz(float f)? (Choose two.) | void xyz(float f)+public void xyz(float f)
Which of the following methods in the Thread class are deprecated? (Choose one.) | suspend() and resume()
Which of the following operations might throw an ArithmeticException? (Choose one.) | none of these
Which of the following operations might throw an ArithmeticException? (Choose one.) | /
Which of the following operators can perform promotion on their operands? (Choose three.) | +,-,~
Which of the following restrictions apply to anonymous inner classes? (Choose one.) | they must be defined inside a code block.
Which of the following signatures are valid for the main() method entry point of an application? (Choose two.) | public static void main(string arg[]),public static void main(string[] args)
Which of the following statements about the wait() and notify() methods is true? (Choose one.) | the thread that calls wait() goes into the monitor’s pool of waiting threads.
Which of the following statements about threads is true? (Choose one.) | threads inherit their priority from their parent thread.
Which of the following statements are true? (Choose one.) | a final class may not be extended.
Which of the following statements are true? (Choose one.) | given that inner is a nonstatic class declared inside a public class outer and that appropriate constructor forms are defined, an instance of inner can be constructed like this: new outer().new inner()
Which of the following statements are true? (Choose one.) | none of the above
Which of the following statements are true? (Choose two.) | stringbuilder is generally faster than stringbuffer.stringbuffer is threadsafe; stringbuilder is not.
Which of the following statements are true?1)An abstract class may not have any final methods.2)A final class may not have any abstract methods. | only statement 2
Which of the following statements is true? (Choose one.) | transient variables are not serialized.
Which of the statements below are true? (Choose one.) | unicode characters are all 16 bits.
Which of the statements below are true? (Choose one.) | none of the above
Which of the statements below are true? (Choose one.) | none of the above.
Which one line in the following code will not compile?1. byte b = 5;2. char c = ‘5’;3. short s = 55;4. int i = 555;5. float f = 555.5f;6. b = s;7. i = c;8. if (f > b)9. f = i; | line 6
Which one statement is always true about the following application?1. class HiPri extends Thread {2. HiPri() {3. setPriority(10);4. }5.6. public void run() {7. System.out.println(8. "Another thread starting up.");9. while (true) { }10. }11.12. public static void main(String args[]) {13. HiPri hp1 = new HiPri();14. HiPri hp2 = new HiPri();15. HiPri hp3 = new HiPri();16. hp1.start();17. hp2.start();18. hp3.start();19. }20. } | none of the above scenarios can be guaranteed to happen in all cases.
Which one statement is true about the following code fragment? (choose 1)1. import java.lang.Math;2. Math myMath = new Math();3. System.out.println("cosine of 0.123 = " + myMath.cos(0.123)); | compilation fails at line 2.
Which one statement is true about the following code fragment?1. String s = "FPT";2. StringBuffer s1 = new StringBuffer("FPT");3. if (s.equals(s1))4. s1 = null;5. if (s1.equals(s))6. s = null; | compilation succeeds. no exception is thrown during execution.
Which one statement is true about the following code?1. String s1 = "abc" + "def";2. String s2 = new String(s1);3. if (s1 == s2)4. System.out.println("== succeeded");5. if (s1.equals(s2))6. System.out.println(".equals() succeeded"); | line 6 executes and line 4 does not.
Which one statement is true concerning the following code?1. class Greebo extends java.util.Vector implements Runnable {2.3. public void run(String message) {4. System.out.println("in run() method: " + message);5.6. }7. }8.9. class GreeboTest {10. public static void main(String args[]) {12. Greebo g = new Greebo();13. Thread t = new Thread(g);14. t.start();15. }16. } | there will be a compiler error, because class greebo does not correctly implement the runnable interface.
Which statement is true about the following code fragment? (Choose one.)1. int j = 2;2. switch (j) {3. case 2:4. System.out.println("value is two");5. case 2 + 1:6. System.out.println("value is three");7. break;8. default:9. System.out.println("value is " + j);10. break;11. } | the output would be the text value is two followed by the text value is three.
Which statement is true about the following method?int selfXor(int i) { return i ^ i;} | it always returns 0.
Which statement is true about this application? (Choose one.)1. class StaticStuff2 {3. static int x = 10;4.5. static { x += 5; }6.7. public static void main(String args[])8. {9. System.out.println("x = " + x);10. }11.12. static {x /= 5; }13. } | the code compiles and execution produces the output x = 3.
Which statement is true about this code? (Choose one.)1. class HasStatic2. {3. private static int x = 100;4.5. public static void main(String args[])6. {7. HasStatic hs1 = new HasStatic();8. hs1.x++;9. HasStatic hs2 = new HasStatic();10. hs2.x++;11. hs1 = new HasStatic();12. hs1.x++;13. HasStatic.x++;14. System.out.println("x = " + x);15. }16. } | the program compiles and the output is x = 104.
Which statements about JDBC are NOT true? (choose 2) | jdbc is a java database system.,jdbc is a java api for connecting to any kind of dbms
Which two code fragments correctly create and initialize a static array of int elements? (Choose two.) | static final int[] a = { 100,200 };static final int[] a; static { a=new int[2]; a[0]=100; a[1]=200; }
Which two of the following interfaces are at the top of the hierarchies in the Java Collections Framework? (Choose two.) | map+collection
You execute the following code in an empty directory. What is the result? (Choose one.)1. File f1 = new File("dirname");2. File f2 = new File(f1, "filename"); | no directory is created, and no file is created.
You have been given a design document for a veterinary registration system for implementation in Java. It states:"A pet has an owner, a registration date, and a vaccination-due date. A cat is a pet that has a flag indicating if it has been neutered, and a textual description of its markings."Given that the Pet class has already been defined and you expect the Cat class to be used freely throughout the application, how would you make the opening declaration of the Cat class, upto but not including the first opening brace? Use only these words and spaces: boolean, Cat, class, Date, extends, Object, Owner, Pet, private, protected, public, String.(Choose one.) | public class cat extends pet
You have been given a design document for a veterinary registration system for implementation in Java. It states:"A pet has an owner, a registration date, and a vaccination-due date. A cat is a pet that has a flag indicating whether it has been neutered, and a textual description of its markings."Given that the Pet class has already been defined, which of the following fields would be appropriate for inclusion in the Cat class as members? (Choose two.) | boolean neutered;string markings;
The defauft type of the Result et object | type_forward_only
Suppose the declared type of x is a class, and the declared type of y is an interface. When is the assignment x =y, legal? | when the type of x is object
In RMI implementations, all methods, declared in the remote interface, must throw the ...exception | remoteexception
Suppose salaries is an array containning floats. Which of the following are vaild loop control statements for processing each element of salaries? | for(int i:salaries)
How can you force garbage collection of an object | garbage collection cannot be forced
Which of the followings satement is true | flowlayout is the default layout manager for every jframe
static boolean b1=false; static int i = -1; static double d = 10.1; | b=m; d=i;
public class Abs extends Base { public static void main(String argv[]){ Abs a = new Abs(); a.amethod();} | the code will compile and run, printinh out the words
Which of the following statements is true about two base protocols used for networking TCP and UDP | tcp and udp are connection-based protocols
class in the primary class that has the driver information | drivermanager
Which of the following methods of the java.io.File can be used to create a newfile | creaenewfile()
Which of the following statements is INCORRECT about a non-static synchronized method | it cannot call to a static synchronized method of the current class
The Swing component classes can be found in the ________________ package. | javax.swing
This question concerns the following class definition:1. package abcde; 2. 3. public class Bird { 4. protected static int referenceCount = 0; 5. public Bird() { referenceCount++; } 6. protected void fly() { /* Flap wings, etc. */ } 7. static int getRefCount() { return referenceCount; } 8. } Which statement is true about class Bird and the following class Parrot? (Choose one.) 1. package abcde; 2. 3. class Parrot extends abcde.Bird { 4. public void fly() { 5. /* Parrot-specific flight code. */ 6. } 7. public int getRefCount() { 8. return referenceCount; 9. } 10. } | compilation of parrot.java fails at line 7 because method getrefcount()
This question concerns the following class definition: 1. package abcde; 2. 3. public class Bird { 4. protected static int referenceCount = 0; 5. public Bird() { referenceCount++; } 6. protected void fly() { /* Flap wings, etc. */ } 7. static int getRefCount() { return referenceCount; } 8. } Which statement is true about class Bird and the following class Nightingale? (Choose one.) 1. package singers; 2. 3. class Nightingale extends abcde.Bird { 4. Nightingale() { referenceCount++; } 5. 6. public static void main(String args[]) { 7. System.out.print("Before: " + referenceCount); 8. Nightingale florence = new Nightingale(); 9. System.out.println(" After: " + referenceCount); 10. florence.fly(); 11. } 12. } | before: 0 after: 2.
This question involves IOException, AWTException, and EOFException. They are all checked exception types. IOException and AWTException extend Exception, and EOFException extends OException. uppose class X contains the following method: void doSomething() throws IOException{ … } Which of the following methods may appear in class Y, which extends X? (Choose three.) | void dosomething() { … }
This question involves IOException, AWTException, and EOFException. They are all checked exception types. IOException and AWTException extend Exception, and EOFException extends OException. uppose class X contains the following method: void doSomething() throws IOException{ … } Which of the following methods may appear in class Y, which extends X? (Choose three.) | void dosomething() throws eofexception { … }
This question involves IOException, AWTException, and EOFException. They are all checked exception types. IOException and AWTException extend Exception, and EOFException extends OException. uppose class X contains the following method: void doSomething() throws IOException{ … } Which of the following methods may appear in class Y, which extends X? (Choose three.) | void dosomething() throws ioexception, eofexception { … }
What are the legal types for whatsMyType? (Choose one.) short s = 10; whatsMyType = !s; | there are no possible legal types.
What does the following code do? Integer i = null; if (i != null & i.intValue() == 5) System.out.println("Value is 5"); | throws an exception.
What does the following code fragment print out at line 9? (Choose one.) 1. FileOutputStream fos = new FileOutputStream("xx"); 2. for (byte b=10; b<50; b++) 3. fos.write(b); 4. fos.close(); 5. RandomAccessFile raf = new RandomAccessFile("xx", "r"); 6. raf.seek(10); 7. int i = raf.read(); 8. raf.close() 9. System.out.println(“i = “ + i); | the output is i = 20.
What does the following code print? public class A { static int x; public static void main(String[] args) { A that1 = new A(); A that2 = new A(); that1.x = 5; that2.x = 1000; x = -1; System.out.println(x); } } | -1
What happens when you try to compile and run the following application? (Choose one.) 1. import java.io.*; 2. 3. public class Xxx { 4. public static void main(String[] args) { 5. try { 6. File f = new File("xxx.ser"); 7. FileOutputStream fos = new FileOutputStream(f); 8. ObjectOutputStream oos = new ObjectOutputStream(fos); 9. oos.writeObject(new Object()); 10. oos.close(); 11. fos.close(); 12. } 13. catch (Exception x) { } 14. } 15. } | an exception is thrown at line 9.
What happens when you try to compile and run the following code? public class Q { static String s; public static void main(String[] args) { System.out.println(">>" + s + "<<"); } } | the code compiles, and prints out >>null<<
What happens when you try to compile and run this application? (Choose one.) 1. import java.util.*; 2. 3. public class Apple { 4. public static void main(String[] a) { 5. Set<Apple> set = new TreeSet<Apple>(); 6. set.add(new Apple()); 7. set.add(new Apple()); 8. set.add(new Apple()); 9. } 10. } | an exception is thrown at line 7.
What is the difference between the rules for method-call conversion and the rules for assignment conversion? (Choose one.) | there is no difference; the rules are the same.
What is the minimal modification that will make this code compile correctly? (Choose one.) 1. final class Aaa 2. { 3. int xxx; 4. void yyy() { xxx = 1; } 5. } 6. 7. 8. class Bbb extends Aaa 9. { 10. final Aaa finalref = new Aaa(); 11. 12. final void yyy() 13. { 14. System.out.println("In method yyy()"); 15. final ref.xxx = 12345; 16. } 17. } | on line 1, remove the final modifier.
What is the range of values that can be assigned to a variable of type byte? (Choose one.) | -2^7 through 2^7 - 1
What is the range of values that can be assigned to a variable of type short? (Choose one.) | -2^15 through 2^15 - 1
What is the result of attempting to compile and execute the following code fragment? Assume that the code fragment is part of an application that has write permission in the current working directory. Also assume that before execution, the current working directory does not contain a file called datafile. (Choose one.) 1. try { 2. RandomAccessFile raf = new 3. RandomAccessFile("datafile" ,"rw"); 4. BufferedOutputStream bos = new BufferedOutputStream(raf); 5. 6. DataOutputStream dos = new DataOutputStream(bos); 7. 8. dos.writeDouble(Math.PI); 9. dos.close(); 10. bos.close(); 11. raf.close(); 12. } 13. catch (IOException e) { } | the code fails to compile.
What is the return type of the instanceof operator? | a boolean
What method of the java.io.File class can create a file on the hard drive? (Choose one.) | createnewfile()
What results from attempting to compile and run the following code? 1. public class Conditional { 2. public static void main(String args[]) { 3. int x = 4; 4. System.out.println("value is " + ((x > 4) ? 99.99 : 9)); 5. } 6. } | the output: value is 9.0
What results from running the following code? 1. public class Xor { 2. public static void main(String args[]) { 3. byte b = 10; // 00001010 binary 4. byte c = 15; // 00001111 binary 5. b = (byte)(b ^ c); 6. System.out.println("b contains " + b); 7. } 8. } | the output: b contains 5
What would be the output from this code fragment? 1. int x = 0, y = 4, z = 5; 2. if (x > 2) { 3. if (y < 5) { 4. System.out.println("message one"); 5. } 6. else { 7. System.out.println("message two"); 8. } 9. } 10. else if (z > 5) { 11. System.out.println("message three"); 12. } 13. else { 14. System.out.println("message four"); 15. } | message four
When comparing java.io.BufferedWriter to java.io.FileWriter, which capability exists as a method in only one of the two? (Choose one.) | writing a line separator to the stream
When does an exception's stack trace get recorded in the exception object? (Choose one.) | when the exception is constructed
When is it appropriate to pass a cause to an exception's constructor? (Choose one.) | when the exception is being thrown in response to catching of a different exception type
When is it appropriate to write code that constructs and throws an error? (Choose one.) | never
When is x & y an int? (Choose one) | sometimes
When the user attempts to close the frame window, _______ event in generated. | window closing
When the user selects a menu item, _______ event is generated. | action event
When you compile a program written in the Java programming language, the compiler converts the human-readable source file into platform-independent code that a Java Virtual Machine can understand. What is this platform-independent code called? | bytecode
Whenever a method does not want to handle exceptions using the try block, the ________ is used. | throws
Which are the correct statements used for getting connection object to connect to SQL Server database? | string url ="jdbc:odbc:data_source_name";
Which class and static method can you use to convert an array to a List? (Choose one.) | arrays.aslist
Which is four-step approach to help you organize your GUI thinking. (Choose one.) | identify needed components isolate regions of behavior.
Which is the four steps are used in working with JDBC? | 1)connect to the database