PRJ311 - Part 1 - AI searching
which of these is incorrect string literal?
"Hello
# select a correct pattern that can be used to validate email input
"^\w+@\w+[.]\w+$"
# which of the following collection cannot be used with iterator class to traverse through elements?
Array
#if the following code is executed. what is the output? int[] a= {1,2,3,4};
ArrayIndexOutOfBoundsException
what happens when you try to compile the following code and run the zebra application?what interfaces can be implemented in order to create a class that can be serialized
2.dai nhat, ngan nhat
what interfaces can be implemented in order to create a class that can be serialized
2.dai nhat, ngan nhat
int x = 6; if (!(x > 3))
2.dai nhat, x = ~x
stringbuffer sbuf = new stringbuffer();
After line 2 executes, the StringBuffer object is eligible for garbage collection.
the strategy fails because you cannot subclass java.lang.math.the string created on line 2 does not become eligible for garbage collection in this code
After line 3
the string created on line 2 does not become eligible for garbage collection in this code
After line 3
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
what code at line 3 produces the following output?what code at line 3 produces the following output
String delim = "\\d+"
aeiou aeiou
String delim = "\\d+";
string scanme = "aeiou9876543210aeiou";
String delim = "\\d+";
#the default type of the resultset object is ____.
TYPE_FORWARD_ONLY
the defauft type of the result et object
TYPE_FORWARD_ONLY
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
int x = 9; byte b = x
False
it throws nullpointerexceptioniterator<string> iter = names.iterator(); for (string s:names)java arrays always start at index 1
False
java arrays always start at index 1
False
object ob2= new object();object ob2= new object()
Have a nice day
#a java source code will be compiled to ____
Java bytecode.
string s1 = "abc" + "def";
Line 6 executes and line 4 does not.
# which method do you use to enable or disable components such as jbuttons?
None of the others
# which of the following is true? (choose one.)
None of the others
how do you generate a string representing the value of a float f in a format appropriate for a locale loc
NumberFormat.getInstance(loc)
ch11: a subclass does not have access to these superclass members.
private
indicates that a variable or method can only be used in the class in which it appears
private
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
#select correct statement. in rmi implementations, _____
The remote class must implement the remote inteface.
# race condition may happen if
There is more than one threads access the shared data of the application
difference between the rules for method-call conversion and the rules for assignment conversion
There is no difference
how can you ensure that multithreaded code does not deadlock
There is no single
greebo g = new greebo();
There will be a compiler error, because class Greebo does not correctly implement the Runnable interface.
stringbuffer class. after execution of line 2, sbuf still references the same instance.stringbuffer class. after execution of line 2, sbuf still references the same instance.stringbuffer is slower than a stringbuilder, but a stringbuffer
True
i = 1 j = 0if (i != null & i.intvalue() == 5) system.out.println("value is 5");
Throws an exception.
w.x = 10; bump(n, w);w.x++;ways:we can access a static variable through the class name?
True
the jvm runs until there is only one non-daemon thread
are no non-daemon
tests the truth of a condition that the programmer believes is true
assert
class sploo
b - d - fff()
the output: b contains 250
b contains 5
(85) which of the following may appear on the right-hand side of an instanceofoperator? (choose two.)
b. A classc. An interface
(312) when the user selects a menu item, event is generated.
b. Action event
(1878) which of the following classes implements a fifo queue? (choose one.)
b. LinkedList
(1873) which two of the following interfaces are at the top of the hierarchies inthe java collections framework? (choose two.)
b. Mape. Collection
#68.database meta data are retrieved through ___________
a Connection object
ch13: the setpreferredsize method accepts this as its argument(s).
a Dimension object
#54.the data in defaulttablemodel are stored in
a Vector
#the next() method of the java.sql.resultset class return ...
a boolean value.
# which of the following options is a method that you need to override when implementing the actionlistener interface?
actionPerformed()
ch13: to display a scroll bar with a jlist component, you must _________.
add the JList component to a JScrollPane component
(65) which of the following are true? (choose two.)
b. Primitives are passed by value.d. References are passed by value.
(1874) which of the following interfaces does not allow duplicate objects?(choose one.)
b. Set
(58) which of the following may be statically imported? (choose two.)
b. Static method namesc. Static field names
(59) 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 + "<<");}}
b. The code compiles, and prints out >><<
(238) 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);
b. The output is i = 20.
(200) which of the following statements about threads is true? (choose one.)
b. Threads inherit their priority from their parent thread.
(75) what does the following code do? integer i = null;if (i != null & i.intvalue() == 5) system.out.println("value is 5");
b. Throws an exception.
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
which of these operators is used to allocate memory to array variable in java?
c) new
short s = 10;whatsmytype = !s;
c. There are no possible legal types.
(78) when a byte is added to a char, what is the type of the result?
c. int
(61) which of the following are legal? (choose two.)
c. int c = 0xabcd;d. int d = 0XABCD;
(149) which of the following are legal loop constructions? (choose one.)
c. int j = 0;for (int k=0, j+k != 10; j++,k++) { System.out.println("j=" + j + ", k=" + k);}
(229) which line of code tells a scanner called sc to use a single digit as adelimiter? (choose one.)
c. sc.useDelimiter("\\d");
#43.which of the following code is correct to obtain hour from a calendar object cal?
cal.get(Calendar.HOUR);
ch12: this is an internal list of all the methods that are currently executing.
call stack
ch14: this sorting algorithm makes several passes through an array and causes the larger values to gradually move toward the end of the array with each pass.
bubble sort
# randomaccessfile(file file, string mode) if the mode is declared as "rwd", what does it mean?
but not its metadata, will take place immediately.
indicates a value is an 8 bit whole number
byte
which of the following is method of wrapper integer for converting the value of an object into byte?
byte bytevalue()
java programming language, the compiler converts the human-readable source file into platform-independent code that a java virtual machine can understand
bytecode
#an abstract class __
can contain all concrete methods.
return this.a == that.a;rmi applications often often comprise two separate programs, a server and a client and they
can run in two separate machine
15.} and:16 bit unicode character
char
a reserved word in java that is not currently used (other languages use this for declaring constants)
const
the "new" operator is used with a _____ to create an object
constructor
(82) which of the following operations might throw an arithmeticexception? (choose one.)
d. /
introduces a path of execution to take when no case is a match in a switch statement
default
accesses members (variables and methods) of an object, eg. len = str1.length();
dot notation
indicates that a value is a 64 bit number with 1 or more digits after the decimal point
double
#select the incorrect declaration.
double f = d32;
(252) which of the following are valid mode strings for the randomaccessfile constructor? (choose one.)
e. All the above
ch11: this key word indicates that a class inherits from another class.
extends
creates a subclass
extends
to create a subclass, use the ____ keyword.
extends
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 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 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 salaries is an array containing floats. which of the following aresuppose 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)
valid loop control statements for processing each element of salaries? (choose one.)
for (float f:salaries)
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
#87.which component method is used to access a component's immediate container?
getParent()
#99.which method returns the preferred size of a component?
getPreferredSize( )
#14.which of these method of thread class is used to find out the priority given to a thread?
getPriority()
ch13: this jlist method returns -1 if no item in the list is selected.
getSelectedIndex
the keyword extends refers to what type of relationship
is a
#an interface
is a reference type, similar to a class, that can contain only constants, method signatures, default methods, static methods, and nested types
#an inheritance
is a relationship where objects share a common structure: the structure of one object is a sub-structure of another object.
#deserialization
is to convert a serialized representation into a replica of the original object
#8.which of these method is used to find out that a thread is still running or not?
isAlive()
which of these method is used to find out that a thread is still running or not?
isAlive()
select incorrect statement about remote class
it must extend java.rmi.server.unicastremoteObject
given the following variables which of the following lines will compile without error?string s = "hello";long l = 99;double d = 1.11;int i = 1;int j = 0;1) j= i <<s;2) j= i<<j;3) j=i<<d;4)j=i<<l;
j= i<<j;j=i<<l;
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 superdupergiven 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?
line 3: private; line 8: protected
byte b = 5; 2. char c = '5';
line 6
ch13: the listselectionlistener interface is in this package.
javax.swing.event
#71.a database url for a mysql database named test on host panda.armstrong.edu is
jdbc:mysql://panda.armstrong.edu/test
#67.a database url for an access database source test is
jdbc:odbc:test
#3.which of these method waits for the thread to treminate?
join()
which of these can not be used for a variable name in java?
keyword
# a component that displays an icon, but that doesn't react to user clicks
label
#98.which method is method to set the layout of a container?
layout of a container
# which of the following methods of the file class can be used to get the size of a given file?
length()
allow you to use prewritten code/classes/toolkits/packages
library classes
public class main
line 17 is never executed
after line 3 executes, the stringbuffer object is eligible for garbage collection
line 2 executes..collection
9.9. }9. }9. }9. }9. }9. }9. }
line 3: private; line 8: protected
object ob = new object();
line 6
ch13: a jlist component generates this type of event when the user selects an item.
list selection event
indicates a value is a 64 bit whole number
long
# in _____ binary streams, a read/write data unit is _______.
low-level, general-format data
#catch statements must be used to contain statements that
may cause checked exceptions.
a final class may not contain non-final data fields
may not be extended
the class is used to implement a pull-down menu that provides a number of items to select from.
menu
int x = 0, y = 4, z = 5;
message four
void callme(string... names)
method, names is an array
actions that an object can take (behaviors)
methods
a reserved word in java that is not currently used (other languages use this for altering the execution order of instructions)
goto
#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 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)
the best way to test whether x and y refer to the same constant? (choose one.)
if (x == y)
public class eqtest{ public static void main(string argv[]}{ eqtest e = new eqtest(); }
if(s.equalsIgnoreCase(s2))
an anonymous inner class that implements several interfaces may extend a parent class other than object
implement at most, class may extend
interfaces cannot be instantiated—they can only be ________ by classes or ______ by interfaces.
implemented, extended
reuses the functionality in an existing interface
implements
enables a programmer to abbreviate the names of classes defined in a package
import
acaccess modifier allows you to access method calls in libraries not created in java
native
access modifier allows you to access method calls in libraries not created in java
native
enables a program to use code that was written in another language
native
creates an object from an existing class
new
the keyword ______ is placed before a class name in order to create an object.
new
new class foo { public int bar() { return 1; } }
new Foo()
public int fubar( foo foo) { return foo.bar(); }
new Foo() { public int bar(){return 1; } }
#44.how do you create a locale for the united states?
new Locale("en", "US"); + Locale.US;
# which of the following options is not a method of the scanner class?
nextValue()
void dosomething() throws ioexception, eofexception
ngan-dai nhat, throws EOFException
#the term "instance variable" is another name for
non-static field, static field
#which of the following statements is not a reason for using nested classes?
none
#with respect to rules and conventions for naming variables in java, select an incorrect statement.
none
the string?
none of the above
given a string constructed by calling s = new string("xyzzy")
none of the other
swing is part of the java foundation classes and provides a rich set of gui components
none of the others
#select a wrong declaration:
none, True are(long[]a...)
#the java program can ....
not directly access data in a database file that is managed by a database management system.
method call is used to tell a thread that it has the opportunity
notify()
indicates that a reference does not refer to any object
null
#76.what information may be obtained from a resultsetmetadata object?
number of columns in the result set
object ob2= ob1
ob1 equals ob2, ob1==ob2
how do you call an instance method
object.methodname(arguments)
# suppose that we have a combobox that contains a list of data. the combobox can only display to the user one item at a time. in term of model-view-controller, which of the following statement is correct?
of the Model.
given the following code:given the following code:given the following main method in a class called cycle and a command line ofjava cycle one twowhat will be output?public static void main(string bicycle[]){ system.out.println(bicycle[0]);}
one
12. }12. }12. }12. }12. }12. classb classb = new classb();12. collections.reverse(list);12. count(++i);12. greebo g = new greebo();12. hs1.x++;12. int bootch;12. int x;12. object obj =new int[] { 1,2,3 };12. public class assertstuff {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.
statements about the wait() and notify() methods is true
pool of waiting threads
suppose prim is an int and wrapped is an integer. which of the following are legal java statements? (choose all that apply.)
prim = wrapped; - wrapped = prim; - prim = new Integer(9); - wrapped = 9;
#78.where is com.mysql.jdbc.driver located?
in a JAR file mysqljdbc.jar
it also has a method called chopwoodandcarrywater(), which just calls the other two methods
inappropriate cohesion, inappropriate coupling
#object-oriented programming allows classes to
inherit, extends
the ability to extend an existing type of objects, by adding new fields and methods, and/or overriding some of the methods
inheritance
restrictions apply to anonymous inner classes
inside a code block
tests to see whether a certain object comes from a certain class
instanceOf
ch11: this operator can be used to determine whether a reference variable references an object of a particular class.
instanceof
integer 32 bit, big enough for most operations (2million) - default choice
int
ch12: this method may be called from any exception object, and it shows the chain of methods that were called when the exception was thrown.
printStackTrace
#12.class newthread extends thread
runtime error
#unlike other members, constructor cannot be inherited
t
#use java.io.objectinputstream to deserialize an object
t
#use java.io.objectoutputstream to serialize an object
t
# we can replace a card layout of a container with ..........
tabbed pane
a # b; a == c
true
a for statement can loop infinitely, for example: for(;;);
true
a stringbuffer is slower than a stringbuilder, but a stringbuffer is threadsafe
true
access the variables only via synchronized methods
true
base(){} base (intj,int k){}
true
boderlayout is the default layout manager
true
cannot call to a static synchonized method
true
creatnewfile()
true
double d = 1.2d
true
for (float f:salaries)
true
if(ob1.equals(ob2)) system.out.println("ob1 equals ob2");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!");if(ob1==ob2) system.out.println("ob1==ob2"); system.out.println("have a nice day!");if(s.equalignorecase(s2))
true
if(s.equalsignorecase(s2))
true
setlayout(new flowlayout());
true
string x = *hello*. int y = 9;x= x+ y
true
the compiler will compalin that the base class is not declared as abstract
true
the gridbaglayout managet is the default manager for jfame
true
the swing's list + the swing's label
true
to check whether the file denoted by the abstract
true
introduces statements that are watched during runtime for things that can go wrong
try
ch12: these are exceptions that inherit from the error class or the runtimeexception class.
unchected exceptions
#63.which of the following statements are true?
you may load multiple JDBC...+B+C+D
public class ombersley{ public static void main(string argv[]){boolean b1 = true;if((b1 ==true)
| place(true)){System.out.println("Hello Crowle");}}public static boolean place(boolean location){if(location==true){System.out.println("Borcetshire");}System.out.println("Powick");return true;}} What will happen when you attempt to compile and run it?|Output of "Hello Crowle"
#an abstract class must contain abstract methods only.
|F
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()?
private
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 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 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
man has the best friend who is a dog
private Dog bestFriend
# as soon as a java thread is created, it enters the ........ state
ready
which of these method is used to change an element in a linkedlist object?
redo()
may appear on the left-hand side of an instanceof operator
reference
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
a swing container that groups some common components in a complex gui.
• JPanel
suppose you are building an application that connects to the database to store and retreive data. your application is built based on model-view-controller pattern. which of the following components is responsible for connecting to the database?
• Model.
ttt.start();
yes
can legally be placed before amethod() on line 3 and be placed before amethod() on line 8
3: private; 8: protected
how many labels appear on gui when the following program is run?
4
#two streams in a java socket are ...
Binary streams
# select correct priority values of a thread (integer values only):
From 1 to 10
public class food
Fruit - Citrus - Pomelo
#a java source code is a file with the file extension is
.java
#a java source code will be compiled to the file with file extension is
.class
#files containing java bytecode have the extension as:
.class
#what is not a unary operator?
/ va >>
assuming any exception handling has been set up, which of the following will create an instance of the randomaccessfile class?
("myfile.txt","rw")
# suppose that obj1 and obj2 are objects and they belong to the same class. study the semantics of following statements: (1) if (obj1==obj2) { } (2) if (obj1.equals( obj2 )) { }
(1) and (2) are different
# suppose that you want reading some records stored in a text file, classes in the java.io package can be used:
(1), (4), (5)
suppose that you want reading some records stored in a text file, classes in the java.io package can be used: (1) file, (2) fileinputstream, (3) randomaccessfile, (4) filereader (5) bufferedreader, (6) printwriter
(1), (4), (5)
1000
-1
is it possible to write code that can execute only if the current thread owns multiple locks?
. Yes.
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?
. You cannot specify which thread will get notified.
ch14: if an array is sorted in this order, the values are stored from highest to lowest.
...
ch14: if an array is sorted in this order, values are stored from lowest to highest.
...
#study the following java code: int n= 256; byte x= (byte) n; suppose that the above code is executed, the value of the variable x is
0
#select the output of the following java code system.out.print(1>>10);
0-1
# study the following java statements: string s1= "hello"; string s2= "hello"; there is only one string is stored in memory of the program.# study the following java statements: string s= "william, bill is ill."; int index1= s.indexof("ill"); int index2= s.lastindexof("ill"); the value of index1 is ..... and index2 is ......
1, 17
study the following java statements: string s= "william, bill is ill."; int index1= s.indexof("ill"); int index2= s.lastindexof("ill"); the value of index1 is ..... and index2 is ......
1, 17
# select correct statement(s).(1) all byte stream classes are descended from the inputstream and outputstream classes .
1, 2
# select correct statement(s).(1) swing is part of the java foundation classes and provides a rich set of gui components.
1, 2
in java network programming using sockets, five steps are usually used:
1, 2, 3, 4, 5
an enum definition should declare that it extends java.lang.enum
2.contain public, private
7. 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?
1. class SuperDuper3. void aMethod() { }6. class Sub extends SuperDuper8. void aMethod() { } | D. line 3: private; line 8: protected
7. what results from running the following code?
1. public class Xor {2. public static void main(String args[]) {3. byte b = 10; // 00001010 binary1. byte c = 15; // 00001111 binary5. b = (byte)(b ^ c);6. System.out.println("b contains " + b);| B. The output: b contains 5
# if we use math.random() method to random a number, which of the following numbers will never be appeared?
1.0
if variable only one word, use lowercase, if multiple, capitalize subsequent words. ex: bigpinkbearif variable only one word, use lowercase, if multiple, capitalize subsequent words. ex: bigpinkbearif we use math.random() method to random a number, which of the following numbers will never be appeared?
1.0
arithmeticexception
1.None of these 2./
may be statically imported
1.Static method names 2.Static field names
1. class greebo extends java.util.vector1. class hasstatic1. class hipri extends thread {1. class q6 {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
6. xyz(float f) {6. consider the following application: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);10. class holder {11. public int held;12. public void bump(holder theholder) {13. theholder.held++; }
101
class man { private dog bestfriend; }class q6
101
double d = 1.2d5
2.double d = 1.2d, 1.2D
10. }
7
10.10. }10. }
7
#which of the following operators will shift all bit values to the right and fill the empty bits on the left end with 0s?
>>>
class a {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
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
compilation fails because of an error in line: public void process() throws runtimeexception
A Exception
the code fails to compile.
A boolean
select incorrect statement about rmi server
A client accesses
select incorrect statement about rmi server.(choose 1)
A client accesses a remote object by specifying only the server name.
# select an incorrect statement. a combobox can contain strings only.
A combobox can contain strings only.
# one of the difference about lists and sets:
A list can contain duplicate items but a set can not.
which of the following is incorrect statement about packages?
A package can be renamed without renaming the directory in which the classes are stored.
string s = "aaa";
A. After line 3
7. consider the following class definition:1. public class test extends base {2. public test(int j) {4. public test(int j, int k) {5. super(j, k);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 all that apply.)
A. Base() { }C. Base(int j, int k) { }
19. when does an exception's stack trace get recorded in the exception object?
A. When the exception is constructed
suppose x and y are of type trafficlightstate, which is an enum. what issuppose 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
A. if (x == y)
d.wrapped = 9;
ABCD
#32.to connect to a server running on the same machine with the client, which of the following can be used for the hostname?
All of the above
may legally appear as the new type (between the parentheses) in a cast operation
All of the above
negative long is cast to a byte
All of the above
which of these data tupe can be used for a method having a return statement in it?
All of the mentioned
# an i/o stream represents an input source or an output destination. a stream can represent ____.
All of the others
#select a correct statement about encapsulation implementation in oop:
All of the others
# a stream can represent ....
All of the others.
# select a correct statement.
All of the others.
# which of the following are true?
All of the others.
passed an assertionexception is thrown without the word "stuff" added to the stack trace
An AssertionError...with the
select the correct statement:
An object reference can be cast to an interface reference when the object implements the referenced interface.
#which of the following statements is not true in terms of overriding methods?
An overriding method (in sub-class) can throw any checked exception (or subclasses of those exceptions) that are not declared in the overridden method (in supper-class).
can only have two values - true/false
Boolean
public class wrapper { public int x;public class xor
B. The output: b contains 5
2. which of the following expressions are legal? (choose all that apply.)
B. int x = 6; if (!(x > 3)) {}C. int x = 6; x = ~x;
#79.analyze the following code:resultset resultset = statement.executequery("select firstname, mi, lastname from student where lastname "+ " = 'smith'");system.out.println(resultset.getstring(1));
BD
try {
Bad URL - Doing finally part - Carrying on
given the following class definition which of the following can be legally placed after the comment line//here ?class base{public base(int i){}}public class myover extends base{public static void main(string arg[]){ myover m = new myover(10); } myover(int i){ super(i); } myover(string s, int i){ this(i); //here }}
Base b = new Base(10);
public class test extends base
Base() { } - Base(int j, int k) { }
#which of the following statements is correct?
Basically, RMI technology uses traditional sockets but socket classes are created invisibly to developers.
# you are required to build a gui application. the application has a main window which displays:
BorderLayout
# the container has one component that should take up as much space as possible. which layouts that easily deal with this situation should be selected?
BorderLayout or GridLayout
f. sc.usedelimiter("\\d+");
C
5. how many bytes does the following code write to file dest?2. fileoutputstream fos = newfileoutputstream("dest");3. dataoutputstream dos = new dataoutputstream(fos);5. dos.writedouble(0.0001);7. fos.close();9. catch (ioexception e) { }
C. 12
7. hasstatic hs1 = new hasstatic();7. int i = raf.read();7. private void xxx() {7. public static void main(string args[])7. return "b";7. set.add(new apple());7. set.add(new apple());7. set.add(new apple());7. system.out.println(7. this.f = f;7. 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);10. class decrementer { 11. public void decrement(double decme) {12. decme = decme - 1.0;what value is printed out at line 6?
C. 12.3
consider the following code: stringbuffer sbuf = new stringbuffer(); sbuf = null system.gc();
C. After line 2 executes, the StringBuffer object is eligible for garbage collection.
9. this question concerns the following class definition:package abcde; 2.4. protected static int referencecount = 0;6. protected void fly() { /* flap wings, etc. */ }7. static int getrefcount() { return referencecount; }which statement is true about class bird and the following class parrot?3. class parrot extends abcde.bird {4. public void fly() {5. /* parrot-specific flight code. */7. public int getrefcount() {8. return referencecount;
C. 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.
protected int size;protected void swim() { }public class bird
C. 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.
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
C. Create a FileReader instance. Pass it into the constructor of LineNumberReader. Use LineNumberReader's readLine() method.
public class threadtest { public void newthread() {public class wrapper
C. n is 10, w.x is 11
17. which line of code tells a scanner called sc to use a single digit as a delimiter?
C. sc.useDelimiter("\\d");
1. 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++;
C. x = 13, a = 7, b = 8
# which of the following statement is correct about card layout?
Card layout arranges components in time rather than in space.
# the container can display three completely different components at different times, depending perhaps on user input or program state. even if the components' sizes differ, switching from one component to the next shouldn't change the amount of space devoted to the component.
CardLayout
# the border layout resizes the ______ components to fill the remaining centre space.
Center
which of these is wrapper for simple data type char?
Character
how do the imports affect the time required to load the class?
Class loading takes no additional time
public class someexception
Compilation of class B will fail. Compilation of class A will succeed
the act of joining two strings together to form a single string is called _______.
Concatenation
#25.how do you create a condition on a lock?
Condition condition = lock.newCondition();
helps manage the connection between a java program and a database
Connection
#an interface can contain
Constants
fileoutputstream fos = new fileoutputstream("datafile");
Construct a FileInputStream - Construct a RandomAccessFile,
the job of a _____ is to initialize instance variables at the time an object is created.
Constructor
suppose you want to read a file that was not created by a java program. 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. which strategy reads the file and produces java strings?
Create a FileReader instance. Pass it into the constructor of LineNumberReader. UseLineNumberReader's readLine() method.
# to create a thread in java, we can:
Create a subclass of the java.lang.Thread class and override the method run()
public class test
D. The code does not compile.
public static void main(string [] a) { int [] b = [1,2,3,4,5,6,7,8,9,0]; system.out.println("a[2]=" + a[2]);
D. The code does not compile.
5. try {5. which statement is true about this application?1. classstaticstuff2 {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. }
E. The code compiles and execution produces theoutput x = 3.
26. this.bootch = bootch;26. what will be the output of the following code?public class stringtest {public static void main(string [] a) { string s1 = "test string";string s2 = "test string"; if (s1 == s2) {system.out.println("same");} else { system.out.println("different");
D. "same" will be printed out to the console.
public class stringtest
D. "same" will be printed out to the console.
9. what is the range of values that can be assigned to a variable of type short?
D. -215 through 215 - 1
12. which of the following may legally appear as the new type (between the parentheses) in a cast operation?
D. All of the above
17. when a negative long is cast to a byte, what are the possible values of the result?
D. All of the above
2. which of the statements below are true? (choose all that apply.)
D. None of the above.
28. };28. }catch (exception e) {28. integer limit) {28. system.out.print("third ");29. }29. java.util.array.sort(myobjects);29. system.out.print("an error occurred");29. this.cardld = cardld;29. how do you change the value that is encapsulated by a wrapper class after you have instan- tiated it?
D. None of the above.
1. which of the statements below are true? (choose all that apply.)
D. Unicode characters are all 16 bits.
16. which of the following are true?
D. The JVM runs until there are no non-daemon threads.
int j = 2;
D. The output would be the text value is two followed by the text value is three.
7. 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? class superduper { void amethod() { } } class sub extends superduper { void amethod() { } }
D. line 3: private; line 8: protected
class superduper
D. line 3: private; line 8: protected
the declaration of the java.util.collection interface isthe declaration of the java.util.collection interface is interface collection <e>
D. public boolean addAll(Collection<? extends E> c)
#42.which of the following are in the java.text package?
DateFormat+SimpleDateFormat+Date
#106.how do you indicate where a component will be positioned using flowlayout?
Do nothing, the FlowLayout will position the component
how do you indicate where a component will be positioned using flowlayout?
Do nothing, the FlowLayout will position the component
11. which of the following may legally appear as the new type (between the parentheses) in a cast operation?
E. All of the above
5. which one statement is true about the following code fragment?2. stringbuffer s1 = new stringbuffer("abcde");3. if (s.equals(s1))4. s1 = null;5. if (s1.equals(s))6. s = null;
E. Compilation succeeds. No exception is thrown during execution.
20. when is it appropriate to write code that constructs and throws an error?
E. Never
file f1 = new file("dirname");
E. No directory is created, and no file is created.
class staticstuff
E. The code compiles and execution produces the output x = 3.
class hasstatic
E. The program compiles and the output is x = 104.
a signed data type has an equal number of non-zero positive and negative values
False
abstract class minebase
Error mine must be declared abstract
#an abstract class can not contain a concrete method.
F
#an interface can contain only one method implementation.
F
#in a java soure code, the first code line must be a class declaration.
F
#no data field can be declared in an abstract class.
F
#a software object stores its state in ..... and exposes its behaviors through ......
Fields, methods
an object that's no longer accessible through any object variable is said to be _______.
Garbage
#how can you force garbage collection of an object?
Garbage collection cannot be forced.
how can you force garbage collection of an object? (choose one.)
Garbage collection cannot be forced.
# which of the following layout managers subdivides its territory into a matrix of rows and columns?
Grid Layout
see picture:
GridBagLayout
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!
system.out.println("b="+b);system.out.println("have a nice day!");
Have a nice day!
ch12: filenotfoundexception inherits from ________.
IOException
# which is four-step approach to help you organize your gui thinking. (choose one.)
Identify needed components.Isolate regions of behavior.Sketch the GUI.Choose layout managers
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 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? - d. if the jvm doesn't crash and the code does not execute a system.exit() call, the finally block will always execute.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?
If the JVM doesn't crash and the code does not execute a System.exit() call, the finally block will always execute.
under which of the following conditions can you have local variables with identical names?
If their scopes do not overlap.
appropriate way to handle invalid arguments in a public method
IllegalArgumentException
#select an incorrect statement.
In a Java soure code, the first code line must be a class declaration.
#select a correct statement about interfaces.
In its most common form, an interface is a group of related methods with empty bodies.
#select correct statement about interfaces.
In its most common form, an interface is a group of related methods with empty bodies.
what code at line 3 produces the following output
String delim = "\\d+"
#with respect to processing models for database access, ____
In the two-tier model, a Java application talks directly to the data source.
# which of the following options is not a thread state?
Indelayed
#110.which of these class is used to encapsulate ip addres and dns?
InetAddress
mouseevent is subclass of which of these classes?
InputEvent
# the objectinputstream is a subclass of the _____ class.
InputStream
the behavior of an object is represented by ______ ______
Instance methods
#in a class, non static fields are called as ........, and static fileds are called as .......
Instance variables, class variables
on line 1, remove the final modifier.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
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
this.weight = weight;thread priority in java is?
Integer
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.
#72.in a relational data model, _________ imposes constraints on the data.
Integrity
# a characteristic of generic technique is .....
It adds stability to the code by making more of bugs detectable at compile time
return i ^ i;return i ^ i;
It always returns 0.
#which of the following statements is correct regarding type 4 jdbc driver (native protocol)?
It helps the Java applications communicate directly with the database using Java sockets.
#19.what will happen if two thread of same priority are called to be processed simultaneously?
It is dependent on the operating system.
# in swing, what is the role of the component's model?
It is responsible for the data that the component presents to the users.
consider the following declaration: randomaccessfile(file file, string mode) if the mode is declared as "rws", what does it mean?
It means the file can be opened for both reading and writing, and any changes to the file's content or metadata will take place immediately.
#what does the default modifier mean?
It provides access to any class in the same package.
#114.what is the name of the swing class that is used for frames?
Jframe
literals in java must be preceded by which of these?
L and I
#80.in a relational data model, ________ provides the means for accessing and manipulating data.
Language+SQL
# which of the following statements is not correct about jtree control?
Leaf nodes are those that can have children.
consider the following code. which line will not compile?object ob = new object();string[] stringarr = new string[50];float floater = new float(3.14f);ob = stringarr;ob = stringarr[5];floater = ob;ob = floater;
Line 6
1. public class a {1. public class a {1. public class a {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.
public class a
Line 26 prints "a" to System.out.
system.out.println("waking up");system.out.println(a.doit(4, 5))
Line 26 prints a to System.out
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
raccoon rocky;
Line 7 will not compile; an explicit cast is required to convert a Washer to a SwampThing
consider the following code: raccoon rocky;swampthing pogo;washer w;rocky = new raccoon();w = rocky;pogo = w;
Line 7 will not compile; an explicit cast is required to convert a Washer to a SwampThing.
the point class cannot be instatiated at line 15
Line.Point p = new Line.Point()
integer 64 bit, (9 million)
Long
class is used to implement a pull-down menu that provides a
Menu
class is used to implement a pull-down menu that provides a number of items to select from
Menu
#is applied in a class. is applied in a class hierarchy.
Method overloading, method overriding.
# a _____ dialog prevents user input to other windows in the application unitl the dialog is closed.
Modal
a dialog prevents user input to other windows in the application umtl the dialog is closed
Modal
dialog prevents user input to other windows in the application unitl the dialog is closed.
Modal
mutator methods exhibit which of the following types of side effect?
Modification of the implicit parameter.
# race condition may happen when
More than one threads access the shared data of the application
#you are trying to look up obj1 object on the server 192.168.12.1 using rmi technology with default port.
Naming.lookup("rmi://192.168.12.1/obj1") ;
#which of the following options is a valid method that is used to bind a name to an object in rmi model?
Naming.rebind(name, object);
public enum direction { north, south, east, west }
Nav.Direction d = Nav.Direction.NORTH;
nav.direction d = nav.direction.north
Nav.Direction.NORTH
can interfaces be instantiated?
No
# the _____ class is the ultimate ancestor of all java classes
Object
ch11: all classes directly or indirectly inherit from this class.
Object
in java, every class declared without an extends clause automatically extends which class?
Object
none of the above scenarios can be guaranteed to happen in all cases.notserializableexception extends objectstreamexception. awtexception does not extend any of these. all are checked exceptions. the callme() method throws notserializableexception
Object Stream - Finally
# which of the following classes can be used for writing and reading objects (serializing/de-serializing) from and to a file?
ObjectInputStream/ObjectOutputStream
# which of the following classes can be used to serialize an object into a file?
ObjectOutputStream
the code will compile as is. no modification is needed
On line 1, remove
how many locks does an object have
One
a static method can have which of the following types of parameters?
Only explicit parameters.
2 _ 3 42 {2)a final class may not have any abstract methods.
Only statement 2
an abstract class may not have any final methods
Only statement 2
#which statement is correct about protected modifier?
Only variables and methods may be declared as protected members.
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"
ch11: a method in a subclass having the same name as a method ina superclass but a different signature is an example of _______.
Overloading
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 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()
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().
ch11: a method in a subclass that has the same signature as a method in the superclass is an example of _______.
Overriding
#if you want execute a sql statement many times, the ____ object should be used.
PreparedStatement
#suppose that you will insert a lot of rows into a database table row-by-row. which of the following interfaces should be used?
PreparedStatement
#the ... object contains not just an sql statement, but an sql statement that has been precompiled
PreparedStatement
#17.which of these are types of multitasking?
Process and Thread based
which of these are types of multitasking?
Process and Thread based
ch11: these superclass members are accessible to subclasses and classes in the package.
Protected
#which of the following statement is not correct about protected access modifier?
Protected variables of a class can only be accessed by its sub-class in the same package
#in rmi architecture, which of the following components is reponsible for storing a mapping between a specific name and a remote object?
RMI registry
# which of the following features is not supported by java.io.randomaccessfile class?
Reading and writing data from and to a socket
an object variable doesn't actually store an object. instead, it stores a ______ to an object.
Reference
#111.which of these exception is throw by remote method?
Remote Exception
statement objects return sql query results as
ResultSet
if variable is constant, use capitals. ex: bigpinkbear
Rules for Naming
when does exceptions in java arises in code sequence?
Run Time
there will be a compiler error, because class greebo does not correctly implement the runnable interface
Runnable interface
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();
# if we want to store a group of different elements in ascending order, the java.util.... class should be used
SortedSet
how do you specify what the program should do when the user clicks a button?
Specify the actions to take in a class that implements the ActionListener interface.
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;
given the following code, which of the following will compile? 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)object;
an instance of the stringbuffer class. after execution of line 2, sbuf still references the same instance.an instance of the stringbuffer class. after execution of line 2, sbuf still references the same instance.an object is used to submit a query to a database
Statement
ob1==ob2object is used to submit a query to a database
Statement
object is used to submit a query to a database
Statement
#65.to create a statement on a connection object conn, use
Statement statement = conn.createStatement();
#61.which of the following are interfaces?
Statement+ResultSet+Connection
#which of the following is not a primitive data type in java language?
String
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");
#high - level
StringReader and StringWriter , BufferedReader and BufferedWriter,InputStreamReader and OutputStreamWriter,LineNumberReader,PrintWriter
standard output variable 'out' is defined in which class?
System
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)
given the following class definition, which of the following statements would be legal after the comment //here class inout{string s= new string("between"); public void amethod(final int iargs){ int iam; class bicycle{ public void sayhello(){ //here } }//end of bicycle class }//end of amethod public void another(){ int iother; }}
System.out.println(s);System.out.println(iArgs);
# a thread must obtain the lock of the object it is trying to invoke a synchronized method
T
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);
consider the following class definition:1. public class test extends base {2. public test(int j) { public test(int j, int k) { super(j, k);which of the following are legitimate calls to construct instances of the test class? (select two)
Test t = new Test(1); Test t = new Test(1, 2);
how can you change the current working directory using an instance of the file class called filename?
The File class does not support directly changing the current directory
# when is a thread started running?
The Scheduler decides when a thread is started running
public class assertification
The application must be - The args array must have one or more elements.
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.
#consider the following piece of code: import javax.swing.jtextfield; class counter {
The bove code is an example of ...... tight coupling
grapefruit g = new grapefruit();
The cast in line 2 is not necessary. - The cast in line 2 is not necessary.
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.
class a extends java.util.vector
The compiler does not create a default constructor.
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.
#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
# with respect to threads in java, select a correct statement.
The main method (entry point of a Java program) is a default thread
the java.util.arrays class has a binarysearch(int[] arr, int key) method. which statements are true regarding this method? (choose all that apply.)
The method is static.,The return value is the index in the array of key.,The elements of the array must be sorted when the method is called.
what does the following code fragment print out at line 9?
The output is i = 11.
16. );16. }16. } finally {16. }
The program compiles and the output is x = 104.
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
public class bird
The program will compile and execute. The output will be Before: 0 After: 2.
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.
# two sub-threads of a program may not need synchronized if ......
They do not access any common resource
#6.class newthread implements runnable
Thread[New Thread,10,main]
ch12: all exception classes inherit from this class.
Throwable
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
#which of the following statement is not correct about default access modifier?
To declare a variable that have default access modifier, we use the default keyword. For example: default String myString;
#which of the following statement is correct about object serialization?
Transient fields are not serialized
# which of the following java lists that allows data is stored in sorted order, and also, no duplicate data is allowed?
TreeSet
if you need a set implementation that provides value-ordered iteration, which class should you use
TreeSet
if you need a set implementation that provides value-ordered iteration, which class should you use? (choose one.)
TreeSet
2. sbuf.insert(3, "-university");
True
#with respect to processing models for database access, in the ... model, a java application talks directly to the data source
Two-tier
#112.what does url stand for?
Uniform Resource Locator
what does url stands for?
Uniform Resource Locator
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
#107.how do you change the current layout manager for a container?
Use the setLayout method
how do you change the current layout manager for a container
Use the setLayout method
output results when the main method of the class sub is run
Value 5 This value 6
public class base
Value is 5This value is 6
select incorrect statement about serialization
When an Object Output
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.
#consider the following operands and result:
XOR
is it possible to define a class called thing so that the following method can return true under certain circumstances
Y
test t = new test(1); test t = new test(1, 2);test t = new test(1,2); static method names static field namestestthread3 ttt = new testthread3
Y
testthread3 ttt = new testthread3
Y
13. }
Yes
can classes be instantiated?
Yes
if you attempt to compile and execute the following application, will it print out the message inside foo?
Yes
#41.which of the following statements are true?
You can create an instance of NumberFormat using the static factory methods in NumberFormat.
(1879) which class and static method can you use t convert an array to a list? (choose one.)
a. Arrays.asList
(120) which of the following may be declared final? (choose two.)
a. Classesc. Methods
# suppose that obj1 and obj2 are reference variables. the expression obj1==obj2 will execute ......
a swallow comparison.
decrement operator, -, decreases value of variable by what number?
a) 1
#75.suppose that your program accesses mysql or oracle database. which of the following statements are true?
a+c
consider the following definition:1. public class outer {2. public int a = 1;3. private int b = 2;4. public void omethod() {int c = 3; final int d = 4;. class inner {private void imethod(int e) {}} which line contain only variables, which can be referenced at line 8?
a, b, d, e
public class outer
a- b - c -e
(145) which of the following operators can perform promotion on theiroperands? (choose three.)
a. +b. -e. ~
int selfxor(int i) {int selfxor(int i) {return i ^ i;}
a. It always returns 0.
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
a method that has no implementation is called a/an ____ method.
abstract
indicates that the details of a class, a method, or an interface are given elsewhere in the code
abstract
32.32. }32. bootchy b = new bootchy();32. system.out.print(" ");33. }33. }33. public string getvalue() {33. system.out.print(b.snootch +" " + b.bootch);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
try { callme();try { sleep(5000);try {
ac
______ method is used to wait for a client to initiate communications.
accept()
which of these method of hashset class is used to add elements to its object?
add()
# when reading objects from an object stream, we usually use _____.
an explicit class casting
#69.what is the return value from stmt.executeupdate("insert into t values (100, 'smith')")
an int value indicating how many rows are effected from the invocation
ch11: in a subclass constructor, a call to the superclass constructor must__________
appear on the very first statement
(206) which of the following are true? (choose three.)
b. When an application begins running, there is one non-daemon thread,whose job is to execute main().c. A thread created by a daemon thread is initially also a daemon thread.d. A thread created by a non-daemon thread is initially also a non-daemon thread.
(68) which of the following expressions are legal? (choose two.)
b. int x = 6; if (!(x > 3)) {}c. int x = 6; x = ~x;
(189) which methods return an enum constant's name? (choose two.)
b. name()c. toString()
(47) which of the following signatures are valid for the main() method entrypoint of an application? (choose two.)
b. public static void main(String arg[])d. public static void main(String[] args)
statements? (choose all that apply.)statements? (choose all that apply.)static boolean b1=false; static int i = -1; static double d = 10.1;
b=m; d=i;
used when an object is created
class description
collie
collie harrier
public class pass
doStuff x = 5 main x = 5
creates a newly defined data type
enum
(227) which of the following are methods of the java.util.sortedset interface?
f. All the above
#18.which of these packages contain all the java's built in exceptions?
java.io
#which of the following statements are true? 1)an abstract class can not have any final methods. 2)a final class may not have any abstract methods.
only 2
# randomaccessfile(file file, string mode) if the mode is declared as "rws", what does it mean?
or metadata will take place immediately.
the code compiles and execution produces the output x = 3.the code compiles, and prints out >>null<<the code compiles, and prints out >>null<<
out >>null<<
the code compiles, and prints out >>null<<
out >>null<<
outer: for (int i = 0; i < 2; i++)
outer: for (int i = 0; i < 2; i++)
there is no output because the code throws an exception at line 1
output is i = 20
protected class cat extends owner
public class Cat extends Pet
given the following class definition public class upton{ public static void main(string argv[]){ public void amethod(int i){}//here}which of the following would be illegal to place after the comment //here ?
public int amethod(int z){}
void dosomething(int a, float b) { ... }
public void doSomething(int a, float b) { ... }
ends execution of a method and possibly returns a value
return
the program compiles and the output is x = 104.the program compiles and the output is x = 104.the program will compile and execute. the output will be before: 0 after: 2.the readline() method of the randomaccessfile class return false when it has reached the end of a file the readline() method of the randomaccessfile class return null when it has reached the end of a file the readline() method of the randomaccessfile class return true when it has reached the end of a file
return false
the returned value varies depending on the argument
returns 0
#static fields are not written
t
given the following variables char c = 'c';int i = 10;double d = 10;long l = 1;string s = "hello";which of the following will compile without error?
s+=i;
#31.you can invoke _on a socket object, say socket, to obtain an inetaddress object.
socket.getInetAddress();
limits the computer's ability to represent extra large or extra small floating point numbers during intermediate calculations
strictfp
accurately describes how variables are passed to methods
that are primitive type are passed by value
finally { system.out.println("finally");first second first third snootchy 420
third second first snootchy 420
identity, state, behavior
three main characteristics of objects
ch12: you use this statement to throw an exception manually.
throw
bigollongstringwithmeaninglessname
tick all
the output: b contains 5the output: value is 99.99
value is 9.0
transient methods may not be overridden
variables are not
suppose the declared type of x is a class
when the type of x is object
repeats some statements as long as a condition remains true
while
int[] x = new int[25]
x[24] is 0 and x.length is 25
# method is implemented in a super class can not be overridden in derived classes.
final
#which of the following access modifiers makes a class cannot be inherited?
final
#which of the following modifiers can assure that a class is not inherited by other classes?
final
#which of the following modifiers does not allow a method to be overridden?
final
#which of the following modifiers is not an access modifier?
final
indicates that a variable's value cannot be changed
final
the ____ reserved word in a method definition ensures that subclasses cannot override this
final
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 xxx
heights is initialized to a reference to an array with zero elements
public class xyz implements java.io.serializable
iAmPublic - iAmPrivate - iAmVolatile
3. which of the following expressions results in a positive value in x?
int x = -1; x = x >>> 5;
#which of the following commands is valid to execute a java byte-code file?
java myPackage.MyClassFile
ch13: this is a key that activates a component just as if the user clicked it with the mouse.
mnemonic
arrays in java are implemented as?
object
line 13 will not compile because it is a static reference to a private variable
output is x = 104
lines 5 and 12 will not compile because the method names and return types are missing
output x = 3
line 12 will not compile, because no version of crunch() takes a char argument
output: int version
ch11: abstract methods must be ________.
overridden
puts the code into a collection of logically related definitions
package
suppose class a has a method called dosomething(), with default access. suppose class b extends a and overrides dosomething()
private
suppose you are writing a class that will provide custom serialization. what access mode should the writeobject() method have
private
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()
which one statement is true concerning the following code?"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."
public class Cat extends Pet
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; }
1. public class c {1. public class someexception {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) {...}
consider these classes, defined in separate source files:1. public class test1 {public float amethod(float a, float b) throws ioexception {.. }1. public class test2 extends test1 {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) {...}
public class test1
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) { }
private static void bump(int n, wrapper w) { n++;protected abstract double getsalesamount();
public;protected
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()?
public;protected;Default
are valid mode strings for the randomaccessfile constructor
r, rw, rws, rwd
which of these method of filereader class is used to read characters from a file?
read()
#4.which of these statement is incorrect?
run() method is used to begin execution of a thread before start() method in special
#2.which of these interface is implemented by thread class?
runnable
#13.which of these class is used to make a thread?
runnalble
catch (interruptedexception e)
running some time
ch11: in an inheritance relationship, this is the specialized class.
subclass
compilation fails at line 1 because the string constructor must be called explicitly
succeeds. No exception
#a low-level input stream reads bytes from an input device and returns bytes to its caller
t
#a try block may optionally have a finally block associated with it
t
ch12: when an exception is generated, it is said to have been ________.
thrown
an exception is thrown at line 6
thrown at line 7
what happens when you try to compile and run the following application
thrown at line 9
#109.which of these methods is used to know the full url of an url object
toExternalForm()
the program cause errors when it is compiled
true
udp is a protocol that sends independent packets of data, called datagrams, from one computer to another with no guarantee about arrival.under no circumstances + adding more classes
true
# a thread's run() method includes the following lines
try { sleep(100) catch (InterruptedException e) { } | At line 2, the thread will stop running. It will resume running some time after 100 milliseconds have elapsed
#which jdbc processing model that requires a jdbc driver that can communicate with the particular data source being accessed?
two-tier
#the jdbc api supports processing models for database access.
two-tier and three-tier models
the muti-threaded programming is used .......
when a task must be performed at un-predictable time.
capability exists as a method in only one of the two? (choose one.
writing a line separator to the stream
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
int x, a = 6, b = 7; x = a++ + b++;
x = 13, a = 7, b = 8
after execution of the following code fragment, what are the values of the variables x, a, and b
x13, a7, b8
int[] x = new int[25];int[] x = new int[25];
x[24] is 0,x.length is 25
#select an incorrect identifier in java
&x
suppose mythread extends java.lang.thread, and myrunnable implements java.lang.runnable (but does not extend thread). both classes have no-args constructors. which of the following cause a thread in the jvm to begin execution? (choose all correct options.)
(new MyThread()).start(); - (new Thread(new MyRunnable()))
operators can perform promotion on their operands
+ - ~(nga)
what does the following code print?what does the following code print?
-1
what is -50 >> 2
-13
range of values that can be assigned to a variable of type short
-215 through 215 - 1
what is -50 >> 1
-25
range of values that can be assigned to a variable of type byte
-27 through 27 - 1
what is -8 % 5
-3
what is -15 % -10
-5
ch14: in this sorting algorthm, the smallest value in the array is located and moved to position 0. then the next smallest value is located and moved to position 1. this process continues until all of the elements have been placed in their proper order.
...
ch14: this search algorithm repeatedly divides the portion of an array being searched in half.
...
ch14: this search algorithm requires that the array's contents be sorted.
...
ch14: this search algorithm will search half the array on average.
...
ch14: this sorting algorithm begins by sorting the initial portion of the array consisting of two elements. at that point, the first three elements are in sorted order. this process continues with the fourth and subsequent elements until the entire array is sorted.
...
ch14: this sorting algorithm recursively divides an array into sublists.
...
1. fileoutputstream fos = new fileoutputstream("xx");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
#study the following java code: byte x= 5; byte y= 5<<1; suppose that the above code is executed, the variable y will store a binary value as
00001010
#the first in the most common objects are used in a database java program: (1) java.sql.connection (2) java.sql.statement (3) java.sql.resultset (4) java.sql.resultsetmetadata
1
99 100 102
1
a thread's run() method includes the following lines:a variable declared within the opening and closing parenthesis of a methoda variable declared within the opening and closing parenthesis of a methoda#b, a==c
1
compile time error
1
foo(count);
1
select the valid primitive data type
1.boolean 2.char 3.float
legal import statements
1.import java.util.Vector 2.import static java.util.Vector
#94.suppose a panel is added to a frame and a button is added to the panel. if the frame's font is set to 12-point timesroman, the panel's font is set to 10-point timesroman, and the button's font is not set, what font will be used to display the button's label?
10-point TimesRoman
int y = 9; x += y; and int y = 9; x = x + y;
2 dap an
passed by value and passed by value
2 dap an
char c = 0x1234
2.0x.., '\u1234'
base(int j, int k, int l)
2.Base(), Base(int j, int k)
what is 7 % -4
3
assuming the class does not perform custom serialization, which fields are written when an instance of xyz is serialized
3.Public, Private, Volatile
nutmeg, cinnamon, coriander, rosemary
3.Spice sp, Spice, String
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
lemon lem = new lemon(); citrus cit = new citrus()
3.cit = lem, cit=(Citrus), lem=(lemon)
int my_value = 10
3.final, static, public
public float amethod(float a, float b, int c) throws exception
3.int a,b. float a,b-int c. private
how many bits are in a single ip address?
32
how many bits does a float contain
32
#int x=2; //1 long z=3; //2 double t=5.4;//3 which statement causes an error?
4,5
dog extends mammaldos.writefloat(0.0001f);
8
how many bytes does the following code write to file dest?how many bytes does the following code write to file dest?
8
if (s1 == s2) system.out.println("line 4"); if (s1.equals(s2)) system.out.println("line 6");if (s1 == s2) system.out.println("line 4"); if (s1.equals(s2)) system.out.println("line 6");if (true) throw new runtimeexception(); system.out.print("b");if (true) throw new runtimeexception(); system.out.print("b");
A Exception
what is a listener in context to event handling?
A listener is a object that is notified when an event occurs.
#77. is an attribute or a set of attributes that uniquely identifies the relation.
A superkey
#20.which of these statements is incorrect?
A thread can exist only in two states, running and blocked.
select the most correct statement
A thread is in the ready state after it has been created and started
14. which of the following code snippets compile?
A. Integer i = 7;B. Integer i = new Integer(5); int j = i;C. byte b = 7;
14. system.out.println("x = " + x);14. t.start();14. ttt.start();14. which statement is true about the following method?int selfxor(int i) { return i ^ i;}
A. It always returns 0.
14. which statement is true about the following method?int selfxor(int i) { return i ^ i;}
A. It always returns 0.
12. public int fubar( foo foo) { return foo.bar(); }12. public static void main(string args[]) {12. public void bump(holder theholder) {12. static {x /= 5; }12. string[] tokens = test.split("\s");12. testthread3 ttt = new testthread3();12. try {12. try {12. which of the following statements are true?f. none of the above.12. which of the following statements are true?f. none of the above.12. given the following,map<string> names = new hashmap<string>();which of the following are legal? (choose all that apply.)
A. Iterator<String> iter = names.iterator();B. for (String s:names)
3. what is the minimal modification that will make this code compile correctly?1. final class aaa3. int xxx;8. class bbb extends aaa10. final aaa finalref = new aaa(); 11.14. system.out.println("in method yyy()");15. finalref.xxx = 12345;
A. On line 1, remove the final modifier.
final class aaa
A. On line 1, remove the final modifier.
13. how many locks does an object have?
A. One
14. 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?
A. Sometimes
suppose the type of xarr is an array of xxx, and the type of yarr is ansuppose 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?
A. Sometimes
16. given the following code, which of the following will compile?enum spice { nutmeg, cinnamon, coriander, rosemary; }
A. Spice sp = Spice.NUTMEG; Object ob = sp;B. Spice sp = Spice.NUTMEG; Object ob = (Object)sp;D. Object ob = new Object(); Spice sp = (Spice)object;
4. which of the following expressions are legal? (choose all that apply.)
A. String x = "Hello"; int y = 9; x += y;C. String x = "Hello"; int y = 9; x = x + y;
20. which of the following statements are true?
A. StringBuilder is generally faster than StringBuffer.D. StringBuffer is threadsafe; StringBuilder is not.
4. how do you use the file class to list the contents of a directory?
A. String[] contents = myFile.list();
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.
A. The code fails to compile
17. which of the following are legal? (choose all that apply.)
A. double d = 1.2d;B. double d = 1.2D;
15. which of the following are methods of the java.util.sortedset interface?
A. firstB. lastC. headSetD. tailSetE. subSet
12. suppose salaries is an array containing floats. which of the following are valid loop control statements for processing each element of salaries?
A. for (float f:salaries)
8. which of the following methods in the thread class are deprecated?
A. suspend() and resume()
#57._________ are the properties in jtable
ABCDE
10. } 11.10. }
An exception is thrown at line 7.
public class classa
An exception is thrown at runtime
the robotic car example shows an interface being used as an industry standard _______
Application Programming Interface
which of these classes is not included in java.lang?
Array
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
package ocean; public class fish {package ocean; public class fish
B. public void swim() { } - size = 12;
#comparison operators in java language return
Boolean value.
e. submap
CDE
a new object that's been created by copying an existing object is said to be a _______.
Clone
# the top interface of the java collection framework is.......
Collection
the value of all four objects prints in natural order
Compilation fails...line 29
interface ... helps manage the connection between a java program and a database.
Connection
20. what is -50 >> 1?
D. -25
5. 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.)
D. The code will compile and produce the following output: int version.
list of primitives ordered in smallest to largest bit size representation
D. char, int, float, long
#89.which of the following are direct or indirect subclasses of container?
Frame+FileDialog+Applet
an object whose instance variables cannot be changed is said to be _______.
Immutable
#which of the following features java does not support
Insecure
system.out.println(a.doit(4, 5))
Line 26 prints a to System.out
public static class point { }
Line.Point p = new Line.Point();
ob1 == ob2
No
#which of the following options is not a java characteristic?
Platform dependent
public void process() { system.out.print("a "); }public void process() throws runtimeexception {public void setanchor(int x, int y) {
Shape s = new Circle(); s.setAnchor(10,10); s.draw();
illegalargumentexception
StackOverflowError
# when some tasks must be performed concurrently
T
consider the following code
The code will compile and run.
case 2 + 1:
The output would be the text value is two followed by the text value is three.
# when invoking math.random(), which of the following options might be the result?
The result is less than 1.0
an abstract class can contain methods with declared bodies.
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
one way to approach the daunting number of swing components is to divide them into three categories:container components ordinary components menu components
True
sbuf.insert("-university");
True
dbc supports ... and ... models.
Two-tier and three-tier
byte, short, into, long, float, double, boolean, char
What are the 8 primitive data types?
5.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
5.}5.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
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
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
# .
[Modifier] {Return type] Identifier (Parameters) throws TypeOfException
#45.a resource bundle is __
a Java class file or a text file that provides locale-specific information.
(49)(4928) which is the four steps are used in working with jdbc?
a. 1)Connect to the database 2)Create a statement and execute the query3)Look at the result set4)Close connection
n=143 there are two classes in java to enable communication using datagrams(310) namely.
a. DataPacket and DataSocket
(107) which of the following declarations are illegal? (choose three.)
a. default String s;d. abstract double d;e. abstract final double hyperbolicCosine();
(69) which of the following expressions results in a positive value in x?(choose one.)
a. int x = -1; x = x >>> 5;QN=216
method declarationsmethod declarationsmethod is used to wait for a client to initiate communications
accept()
ch13: a jcombobox component generates this type of even when the user selects an item.
action event
no output because of compile error at line: system.out.println("b="+b)
b = b * b1
(223) which of the following are legal? (choose two.)
b. List<String> theList = new Vector<String>();d. Vector <String> theVec = new Vector<String>();
ch11: abstract classes cannot _______.
be instantiated
which of these is a method of class date which is used to search weather object contains a date before the specified date?
before()
# when a thread begins waiting an io operation, it enters the ..... state
blocked
<insert code>
break
(253) which of the following are valid arguments to the datainputstreamconstructor? (choose one.)
c. FileInputStream
(144) when a negative byte is cast to a long, what are the possible values of the result? (choose one.)
c. Negative
(74) 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. }
c. The output: value is 9.0
(201) which of the following statements about the wait() and notify() methods is true? (choose one.)
c. The thread that calls wait() goes into the monitor's pool of waiting threads.
16 bit unicode character
char
indicates that a value is a character stored in 16 bits of memory
char
select the list of primitives ordered in smallest bit size representation.
char,int,float,long
system.out.print("collie ");
collie harrier
# a component that lets the user pick a color.
color chooser
# in a complex gui containing a lot of components and user must be select some data in a group of specific data, the component should be used is .......
combo box
object references can be converted in both method calls and assignments, but the rules governing these conversions are very different
conversions are identical
(202) which of the following may not be synchronized? (choose one.)
d. Classes
(150) 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. }
d. message four
(250) which of the following are true? (choose one.)
e. All the above
(166) when is it appropriate to write code that constructs and throws an error? (choose one.)
e. Never
introduces statements that are executed when the condition of an if state is not true
else
hiding information from unwanted outside access and attaching that information only to methods that need access to it
encapsulation
public class mod
error at compilation: native method cannot be static
transient variables are not serialized.transient variables are not serialized.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
# we have the constructor of the java.io.randomaccessfile class as follows: randomaccessfile(string file, string mode) which of the following options is not a valid value for the mode option?
"w"
4. t = t.substring(0);4. which of the following expressions are legal?
(Choose all that apply.)A. String x = "Hello"; int y = 9; x += y;C. String x = "Hello"; int y = 9; x = x + y;
4. which of the following expressions are legal?
(Choose all that apply.)A. String x = "Hello"; int y = 9; x += y;C. String x = "Hello"; int y = 9; x = x + y;
public class apublic class a
-1
public class a{static int x;public static void main(string[] args) { a that1 = new a();public class a{static int x;public static void main(string[] args) { a that1 = new a();public class a
-1
that1.x = 5; that2.x = 1000; x = -1;that2.x= 1000;
-1
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
11. public static void main(string args[]) {11. public static void main(string[] args) {11. public static void main(string[] args) {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
compilation fails at line 2.compilation fails because of an error in line 12
1 2 3
compilation fails because of an error in line 12
1 2 3
for (int i: somearray) system.out.print(i +" ");
1 2 3
select correct statement(s): (choose one option) (1) a thread can be an instance of the java.lang.thread class. d a (2) a thread can be an instance of a subclass of the java.lang.thread class. d b (3) an instance of a class which implements the java.lang.runnable can supply the executable code for a thread object.
1 2 3
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
#study the following java code: int[] a= {1,2,3,4};
1 3 3 4
char c = '\u1234'
1 dap an
int turn(direction direction,int turn(direction direction,int turn(direction direction,int turn(direction direction,int x = -1; x = x >>> 5
1 dap an
int x = -1; x = x >>> 5
1 dap an
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
how many locks does an object have? (choose one.)
1
no such file found. doing finally.-1
1
public float amethod(float x. float y) {}
1
public interface b inheritsfrom a {}
1
rmic.exe, rmiregistry.exerows and columns in a gridbaglayout can have different sizes.runnable interface.runtime exception
1
the code on line 29 will be executed
1
#9.what is the default value of priority variable min_priority and max_priority?
1 & 10
select correct statement(s).(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.
3
given the following code, which of the following will compile? (choose three.)enum spice { nutmeg, cinnamon, coriander, rosemary; }
3 cai dai nhat
default string s ,, abstract double d ,, double hyperbolic
3 dap an
#which of the following java operations cause compile-time errors? int m=5, n=7; float x = m; //1
3,4
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
class q7
12.3
consider the following application: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
decrementer dec = new decrementer()
12.3
# select correct statement(s) (1) a process has a self-contained execution environment (2) a sub-thread has a self-contained execution environment (3) programmers can schedule sub-threads of a program
1A process has a self-contained
#suppose that the folowing java code executes. what is the value of the result of variable.#suppose that the folowing java code executes. what is the value of the result of variable. int x= -7, y=3; int result= x%y;
2
how many strings, specified by the above code, are stored in the memory of the program?
2
public class q {public class q { public static void main(string argv[]){ int anar[]=new int[]{1,2,3}; system.out.println(anar[1]);
2
select the correct result of the expression: 5 >>> 1
2
study the following java statements:string sl= "hetlo";string s2= "hello";string s3= "hello";string s4= new stnng("hello");how many strings, specified by the above code, are stored in the memory of the program
2
1 2 3
2 3
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
double d = 1.2d and double d = 1.2d
2 dap an
int c = 0xabcd and int d = 0xabcd
2 dap an
int x = 6; if (!(x > 3)) and int x = 6; x = ~x
2 dap an
suppose interface inty defines five methods. suppose class classy declares that it implementssuppose 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
string s = "123456789"; s = (s-"123").replace(1,3,"24") - "89"
2.delete(4,6), delete(2,5).insert( 1, "24")
for example, imagine a futuristic society where computer-controlled robotic cars transport passengers through city streets without a human operator. automobile manufacturers write software (java, of course) that operates the automobile—stop, start, accelerate, turn left, and so forth. another industrial group, electronic guidance instrument manufacturers, make computer systems that receive gps (global positioning system) position data and wireless transmission of traffic conditions and use that information to drive the car.for example, imagine a futuristic society where computer-controlled robotic cars transport passengers through city streets without a human operator. automobile manufacturers write software (java, of course) that operates the automobile—stop, start, accelerate, turn left, and so forth. another industrial group, electronic guidance instrument manufacturers, make computer systems that receive gps (global positioning system) position data and wireless transmission of traffic conditions and use that information to drive the car.for example, imagine a futuristic society where computer-controlled robotic cars transport passengers through city streets without a human operator. automobile manufacturers write software (java, of course) that operates the automobile—stop, start, accelerate, turn left, and so forth. another industrial group, electronic guidance instrument manufacturers, make computer systems that receive gps (global positioning system) position data and wireless transmission of traffic conditions and use that information to drive the car.for example, imagine a futuristic society where computer-controlled robotic cars transport passengers through city streets without a human operator. automobile manufacturers write software (java, of course) that operates the automobile—stop, start, accelerate, turn left, and so forth. another industrial group, electronic guidance instrument manufacturers, make computer systems that receive gps (global positioning system) position data and wireless transmission of traffic conditions and use that information to drive the car.for( int i=0; i< x.length; i++ ) system.out.println(x[i])
2.for(int z : x), dai nhat
for( int i=0; i< x.length; i++ ) system.out.println(x[i])
2.for(int z : x), dai nhat
int[] ages = { 9, 41, 49 }; int sum = 0
2.i<ages.length, for (int i:ages)
int[] ages = { 9, 41, 49 }; int sum = 0;int[] ages = { 9, 41, 49 }; int sum = 0
2.i<ages.length, for (int i:ages)
line 46 will compile if enclosed in a try block, where testexception is caught
2.if the enclosing, is caught
int d = 0xabcd
2.int c = 0xabcd, dai nhat
java -ea test file1 file2
2.java -ea test, dai nhat
command line on a windows system
2.must contain the statement, the file
test t = (new base()).new test(1)
2.new Test(1), new Test(1, 2)
string x = "have good time"; int y = 7; x += y; string x = "have good time"; int y = 7; x = x + y;string x = "hello"; int y = 9; if (x == y)
2.ngan nhat, x=x+y
string x = "hello"; int y = 9; if (x == y)
2.ngan nhat, x=x+y
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
protected double getsalesamount() { return 1230.45; }
2.public, protected
suppose class supe, in package packagea, has a method called dosomething(). suppose class subby, in package packageb, overrides dosomething()
2.public, protected
# select correct statement(s).(1) the swing's list component (jlist) can display text only.
3
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.
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.
5. dos.writedouble(0.0001);5. dos.writefloat(0.0001f);5. h.bump(h);5. if (s1.equals(s))5. if (s1.equals(s))5. message);5. public static void main(string args[])5. randomaccessfile raf = new randomaccessfile("xx", "r");5. set<apple> set = new treeset<apple>();5. set<apple> set = new treeset<apple>();5. set<apple> set = new treeset<apple>();5. static { x += 5; }5. t = null;
After line 3
ch11: with this type of "binding", the java virtual machine determines at runtime which method to call, depending on the type of the object that a variable refences.
Dynamic
4. // in is an objectinputstream5. object o = in.readobject();8. catch (malformedurlexception e) {9. system.out.println("bad url");11. catch (streamcorruptedexception e) {12. system.out.println("bad file contents");15. system.out.println("general exception");18. system.out.println("doing finally part");what lines are output if the method at line 5 throws an outofmemoryerror? (choose all that apply.)
E. Doing finally part
#in oop, which of the following statements is correct in terms of cohesion?
Each method should perform one specific task only.
# in multi-processing system,
Each process usually accesses its own data
# which of the following layout classes is in java.awt package?
All of the others.
#in java, __
All of the others.
#select correct statement about rmi. (choose 1)
All of the others.
#select correct statements about remote interface. (choose 1)
All of the others.
datainputstream, dataoutputstream are binary streams, printwriter, bufferedreader are not binary streams ,objectinputstream, objectoutputstream are not text streams.
All of the others.
select a correct statement.datainputstream, dataoutputstream are binary streams. printwriter, bufferedreader are text streams. objectinputstream, objectoutputstream are binary streams.
All of the others.
an enum definition may contain the main() method of an application
All the above
select correct statement about rmi
All the above
suppose prim is an int and wrapped is an integer. which of the following are legal java statements
All the above
system.out has a println() method
All the above
select correct statement(s) about remote class
All the others choices
select correct statements about remote interface
All the others choices
# suppose prim is an int and wrapped is an integer. which of the following are legal java statements? (choose one.)
All the others.
suppose prim is an int and wrapped is an integer. which of the following are legal java statements? (choose one.) prim = wrapped; wrapped = prim;prim = new integer( 9 ); wrapped = 9;
All the others.
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
31. public static void main(string[] args) {31. public string value;31. system.out.print(myobjects[i].tostring());31. this.limit = limit;32 bit decimal value - do not use for precise values
Float
32 bit decimal value - do not use for precise values
Float
public class myar{ public static void main(string argv[]){ int[] i = new int[5]; system.out.println(i[5]); } }
An error at run time
what is an event in delegation event model used by java programming language?
An event is an object that describes a state change in a source.
an exception is thrown at runtime
An exception
what happens when you try to compile and run this application? (choose one.)
An exception is thrown at line 7.
a given arrays a1and a2, which call returns trueif a1and a2have the same length, anda given arrays a1and a2, which call returns trueif a1and a2have the same length, anda in the following code fragment, after execution of line 1, sbufreferences an instance of thea in the following code fragment, after execution of line 1, sbufreferences an instance of thea in the following code fragment, after execution of line 1, sbufreferences an instance of thea in the following code fragment, after execution of line 1, sbufreferences an instance of thea in the following code fragment, line 4 is executed.a in the following code fragment, line 4 is executed.a java monitor must either extend thread or implement runnable
F
a java monitor must either extend thread or implement runnable
F
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
F
the element method alters the contents of a queue
F
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
F
5. float f = 555.5f; 6. b = s; 7. i = c;
F. Line 6
1. given a string constructed by calling s = new string("xyzzy"), which of the calls modifies the string?
F. None of the above
12. which of the following statements are true?
F. None of the above.
15. which of the following are legal loop definitions? (choose all that apply.)
F. None of them are legal.
# which of the following layout managers arranges components in horizontal rows (left to right in the order they were added to their container), starting new rows if necessary?
Flow Layout
the default layout manager for every jpane is
FlowLayout
the default layout manager used by jpanel is:
FlowLayout
# the container has a row of components that should all be displayed at the same size, filling the container's entire area. which layout is the best choice for this purpose?
GridLayout
the developer can force garbage collection by call system.gc()
False
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 layout managers will make all its components the same size?
GridLayout
# to read data from a text file using the line-by-line accessing. the right order of object creations is:
File - FileReader - BufferedReader
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.
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 thread's run() method includes the following lines 1 try{ 2 sleep(ioo);3.} catch (interruptedexception e) {}
At line 2. the thread will stop running It will resume running some time after 100 milliseconds have elapsed
# (1) the java.io.... class makes it easier to write platform-independent code that examines and manipulates files.
File, File
#100.which layout should you use to organize the components of a container in a tabular form?
GridLayout
#21.which of the following layout managers honours the preferred size of a component:
GridLayout
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.
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.
plainvec; vector<string> fancyvec;
Attempting to add anything other than a string to fancyVec results in a compiler error.
compilation of class a will fail. compilation of class b will succeed
B fail, A succeed
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
10. 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.)
B. Line 7 will not compile; an explicit cast is required to convert a Washer to a SwampThing.
10. public static void main(string args[]) {10. consider the following code: 2. swampthing pogo;5. rocky = new raccoon();6. w = rocky;7. pogo = w;which of the following statements is true? (choose one.)
B. Line 7 will not compile; an explicit cast is required to convert a Washer to a SwampThing.
11. which of the following are legal? (choose all that apply.)
B. List<String> theList = new Vector<String>();D. Vector <String> theVec = new Vector<String>();
11. suppose ob1 and ob2 are references to instances of java.lang.object. if (ob1 == ob2) is false, can ob1.equals(ob2) ever be true?
B. No
6.suppose ob1 and ob2 are references to instances of java.lang.object. if (ob1 == ob2) isfalse, can ob1.equals(ob2) ever be true?
B. No
suppose ob1 and ob2 are references to instances of java.lang.object. if (ob1 == ob2) is false, can ob1.equals(ob2) ever be true?
B. No
20. 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?
B. Override run().
9. which of the following are appropriate situations for assertions?
B. Postconditions of a public methodC. Preconditions of a private methodD. Postconditions of a private method
20. which of the following are true? (choose all that apply.)
B. Primitives are passed by value.D. References are passed by value.
15. when is x & y an int? (choose one).
B. Sometimes
14. which of the following may be statically imported? (choose all that apply.)
B. Static method namesC. Static field names
6. consider the following class definition:1. public class test extends base {2. public test(int j) {4. public test(int j, int k) {5. super(j, k);which of the following are legitimate calls to construct instances of the test class? (choose all that apply.)
B. Test t = new Test(1);C. Test t = new Test(1, 2);
9. which of the following statements about threads is true?
B. Threads inherit their priority from their parent thread.
11. which of the following is the most appropriate way to handle invalid arguments in a public method?
B. Throw java.lang.IllegalArgumentException.
9. what does the following code do?integer i = null;if (i != null & i.intvalue() == 5) system.out.println("value is 5");
B. Throws an exception.
what does the following code do? integer i = null; if (i != null & i.intvalue() == 5) system.out.println("value is 5");
B. Throws an exception.
15. which of the following are true? (choose all that apply.)
B. When an application begins running, there is one non-daemon thread, whose job is to execute main().C. A thread created by a daemon thread is initially also a daemon thread.D. A thread created by a non-daemon thread is initially also a non-daemon thread.
17. when is it appropriate to pass a cause to an exception's constructor?
B. When the exception is being thrown in response to catching of a different exception type
1. consider the following code:1. for (int i = 0; i < 2; i++) {2. for (int j = 0; j < 3; j++) {3. if (i == j) {4. continue;6. system.out.println("i = " + i + " j = " + j);which lines would be part of the output? (choose all that apply.)
B. i = 0 j = 1C. i = 0 j = 2D. i = 1 j = 0F. i = 1 j = 2
18. which methods return an enum constant's name?
B. name()C. toString()
13. which of the following are legal clone() methods in a class called q13 that extends object?
B. public Object clone()throws CloneNotSupportedException { return super.clone(); }D. public Q13 clone()throws CloneNotSupportedException { return (Q13)super.clone(); }
2. consider these classes, defined in separate source files:2. public float amethod(float a, float b)3. throws ioexception {...public class test2 extends test1 { 2.which of the following methods would be legal (individually) at line 2 in class test2? (choose all that apply.)
B. public int aMethod(int a, int b) throws Exception {...} D. public float aMethod(float p, float q) {...}
#66.sql ________ statements may change the contents of a database.
INSERT+DELETE+UPDATE
which of these exception is thrown by close() and read() methods?
IOException
stringbufferclass. after execution of line 2, sbufstill references the same instance.stringbufferclass. after execution of line 2, sbufstill references the same instance.stringbufferclass. after execution of line 2, sbufstill references the same instance.stringbufferclass. after execution of line 2, sbufstill references the same instance.super.process();suppose a method called finallytest() consists of a try block
If the JVM doesn't crash and
suppose a method called finallytest() consists of a try block
If the JVM doesn't crash and
#suppose a method called finallytest() method consisting 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?
If the JVM doesn't crash and the code does not execute a System.exit() call, the finally block will always execute.
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 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?
If the JVM doesn't crash and the code does not execute a System.exit() call,the finally block will always execute.
ch13: you can pass an instance of this class to the jlabel constructor if you want to display an image in the label.
ImageIcon
#java compiler allows
Implicit widening conversions.
3. which of the following signatures are valid for the main() method entry point of an application?(choose all that apply.)
B. public static void main(String arg[])D.public static void main(String[] args)
1. string s = "aaa";1. string s = "abcde";1. string s = "fpt";1. string s1 = "xyz";1. string s1 = "xyz";1. string s1 = "xyz";1. string s1 = "xyz";1. string s1 = "xyz";1. string s1 = "xyz";1. string scanme = "aeiou9876543210aeiou";1. stringbuffer sbuf = new stringbuffer("abcde");1. stringbuffer sbuf = new stringbuffer("abcde");1. stringbuffer sbuf = new stringbuffer("abcde");1. stringbuffer sbuf = new stringbuffer("abcde");1. stringbuffer sbuf = new stringbuffer("abcde");1. stringbuffer sbuf = new stringbuffer("abcde");1. stringbuffer sbuf = new stringbuffer("fpt");1. stringbuffer sbuf = new stringbuffer("fpt");1. try {1. try {1. try {1. try {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. 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) { }
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) { }
consider the following class definition: . public class test extends base { public test(int j, int k) { super(j, k);}which of the following form of constructor must exist explicitly in the definition of the base class? assume test and base are in the same package.
Base(int j, int k) { }
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.
objects have two properties. one is state. what is the other?
Behavior
choose the valid identifiers from those listed here.
BigOlLongString,$int,bytes,$1,finalist
choose the valid identifiers from those listed here. (choose all that apply
BigOlLongStringWithMeaninglessName - $int - bytes - $1 - finalist
#suppose that a, and b are single dimensional arrays of integers, index1 and index2 are valid indexes. study the following statements:
Both
1.tcp is a connection-based protocol that provides a reliable flow of data between two computers.2.tcp provides point-to-point channel for applications that require reliable communications:
Both 1 and 2 are true
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
modifier: staticmodifier: staticmodulus operator, %, can be applied to which of these?
Both Integers and floating - point numbers.
answer select correct statement: e]
Both String and StringBuffer objects are not constants.
#101.an application has a frame that uses a border layout manager. why is it probably not a good idea to put a vertical scroll bar at north in the frame?
Both a and b.
only object references are converted automatically; to change the type of a primitive, you have to do a cast
Both primitives
#in which layer of the jdbc architecture does the jdbc-odbc bridge reside?
It resides in the JDBC layer.
in the java programming language, an interface is a reference type, similar to a class, that can contain only c____, m________, and n______in the java programming language, an interface is a reference type, similar to a class, that can contain only c____, m________, and n______in which layer of the jdbc architecture does the jdbc-odbc bridge reside?
It resides in the JDBC layer.
consider the following code developed in netbeans. what does the thread t do?
It will show a clock in the jLabel1
#16.what is multithreaded programming?
It's a process in which two or more parts of same process run simultaneously.
# to traverse elements in a set, one after one element, the java.util........interface must be use.
Iterator
map<string> names = new hashmap<string>();
Iterator<String> iter = names.iterator(); - for (String s:names)
list<string> names = new arraylist<string>(); which of the following are legal? (choose two.)
Iterator<String> iter = names.iterator(); for (String s:names)
map<string> names = new hashmap<string>();map<string> names = new hashmap<string>();map<string> names = new hashmap<string>(); which of the following are legal? (choose all that apply.)
Iterator<String> iter = names.iterator();, for (String s:names)
ch13: to display a dialog box that allows the user to select a color, you use this class.
JColorChooser
is a set of java api for executing sql statements.
JDBC
#which of the following is not a benefit of using jdbc?
JDBC programs are tightly integrated with the server operating system.
ch13: to display an open file or save file dialog box, you use this class.
JFileChooser
# which component can display an image, but cannot get focus?
JLabel
ch13: you use this class to create a menu bar.
JMenuItem
ch13: you use this class to create a radio button menu item.
JRadioButtonMenuItem
ch13: components of this class are multi-line text fields.
JTextArea
which of these class is used to read characters and strings in java from console?
BufferedReader
#88.which of the following are direct or indirect subclasses of component?
Button+Label+Frame
# which of the following statements is true about object class?
By default, the equals() method simply performs the == operator
integer i = null;integer with min value of -128 and max value of +127(inclusive) 8 bit (for memory saving)
Byte
integer with min value of -128 and max value of +127(inclusive) 8 bit (for memory saving)
Byte
f given a string constructed by calling s = new string("xyzzy"), which of the calls modifiesf given a string constructed by calling s = new string("xyzzy"), which of the calls modifiesf. sc.usedelimiter("\\d+");
C
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
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
(1) the java.io.... class makes it easier to write platform-independent code that examines and manipulates files. (2) the java.io..... class makes it easier to write platform-independent code that examines and manipulates folders.
File, File
fill the blanks: (1) the java.io. class makes it easier to write platform-independent code that examines and manipulates files. d a (2) the java.io. class makes it easier to write platform-independent code that examines and manipulates folders.
File, File
are valid arguments to the datainputstream constructor
FileInputStream
which of these class contains the methods used to write in a file?
FileInputStream
which of these class is used to read from a file?
FileInputStream
#low-level input streams
FileInputStream , ByteArrayInputStream
#low-level output streams
FileOutputStream , ByteArrayOutputStream
# to write objects to an object file. the right order of object creations is:
FileOutputStream- ObjectOutputStream
which of these class is used to read characters in a file?
FileReader
#low-level
FileReader and FileWriter , CharArrayReader and CharArrayWriter,PipedReader and PipedWriter
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
# which of the following classes are exclusively designed for writing and reading unicode characters?
FileReader/ FileWriter
ch12: this is one or more statements that are always executed after the try block has executed and after any catch blocks have executed if an exception was thrown.
Finally block
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.
10. bos.close();10. class holder {10. class line {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();
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 options we try to achieve while designing object oriented software?
Low coupling
# suppose you are building an application that connects to the database to store and retreive data. your application is built based on model-view-controller pattern.
Model.
# select correct statement(s) (1) a thread can be an instance of the java.lang.thread class (2) a thread can be an instance of a subclass of the java.lang.thread class
Monitor, wait-notify, specific period of time
(1) an object having synchronized methods is called a( an ) ..........(2) the ......... technique can be applied with a hope that a deadlock situation may not occur in a program .(3) the sleep(... ) method of the java.lang.thread class accepts a argument that specifies a( an ) .............
Monitor, wait-notify, specific period of time.
#checked exception
Must be handled by either the try-catch mechanism or the throws-declaration mechanism
and these command line invocations:answer rmi applications often comprise two separate programs. a server and a client and they
Must run in two separate computers
to override a superclass method in a subclass, the subclass method ____.
Must use the same method name and the same parameter types.
an instance method that stores its parameter into an instance variable is said to be an ________.
Mutator/Setter
#5. class newthread implements runnable
My thread
#consider the following class: class myclass { void myfunction(){} int myfunction() {return 0;}
MyClass has a compile error.
#if we have a java class name as follows: public class myclass {}when the above class is compiled successfully, which of the following files contains the java bytecode?
MyClass.class
10. class nav{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;
negative byte is cast to a long
Negative
#when a negative byte is cast to a long, what are the possible values of the result?
Negative value.
when is it appropriate to write code that constructs and throws an error?
Never
is the following code valid? 1. public class test1 {final void amethod() {.. }public class test2 extends test1 {void amethod() {.. }
No
is the following code valid? public class test1 {public static void main(string[] args) {final int a = 5; a = 10; }
No
is the following code valid?1. public abstract class test1 {2. abstract void amethod();4. public class test2 extends test1 { }
No
#97.which of the following components allow multiple selections?
Non-exclusive Checkboxes+List
an abstract class must declare that it implements an interface
None
to change the current working directory, call the changeworkingdirectory() method of the file class
None
#the java language supports
None of choice
calls modifies the string? (choose one.)
None of the above
given a string constructed by calling s = new string("xyzzy"), which of the calls modifies the string
None of the above
given a string constructed by calling s = new string("xyzzy"), which of thegiven a string constructed by calling s = new string("xyzzy"), which of the calls modifies the string
None of the above
readers have methods that can read and return floats and doubles
None of the above
change the value that is encapsulated by a wrapper class after you have instan
None of the above.
# the java collection framework is implemented in the ...package
None of the others
# which of the following options is not a method of java.lang.math class?
None of the others
#one of the benefits of type 1 driver (jdbc - odbc bridge) is that it can provide connection to a database when java driver is not available for that database. which of the following options is another advantage of the type 1 driver?
None of the others
#when handling exceptions, how many catch{} blocks can be used for one try{} block?
None of the others
# multithreaded execution is an essential feature of the java platform. every application has at least ... thread(s)
None of the others ( 2 3 4)
# which of the following classes is the ultimate ancestor of all java classes?
None of the others (Class Concept Thing
# string s= "hello"; string s2= new string("java program"); the string class describes an immutable chain of unicode characters
None of the others (S="Innovation"...)
# if an object is visible to more than one thread, all reads or writes to that object's variables should be done through ... methods
None of the others (public private protected)
# given a string constructed by calling s = new string( "xyzzy" ), which of the calls modifies the string? (choose one.)
None of the others (s.concat(s), s.replace('z', 'a')... )
# select correct statement(s).(1) 12 buttons can not be added to a container which is assigned to a grid layout 2x5.
None of the others.
# suppose that the layout of the frame f is borderlayout. study the following statement:
None of the others.
# which of the following classes is not an abstract class?
None of the others.
#the default access modifier in java is
None of the others.
#with respect to java, select a correct statement about interfaces.
None of the others.
select correct statement(s). (1) 12 buttons can not be added to a container which is assigned to a grid layout 2x5.(2) if 2 components are added to the center region of a border-layout container, they will be seen by user as side-by-side components.
None of the others.
string s= "hello"; string s2= new string("java program"); the string class describes an immutable chain of unicode characters. select a statement that causes an error.
None of the others.
suppose that the layout of the frame f is borderlayout. study the following statement:g.getcontentpane().add ( new jbutton("b")); the button b will be let at the .... region of the frame.
None of the others.
the gridlayout manager is the default manager for jpanel gridlayout simply makes a bunch of components equal in size and displays them in the requested number of rows and columns.the java collection framework is implemented in the ...package.
None of the others.
# string s= "hello"; string s2= new string("hello"); the string class describes an immutable chain of unicode characters. select a statement that causes an error.
None of the others. (S=S + " Chan"; , S= S.toUpperCase();...)
ch12: the numeric wrapper classes' "parse" methods all throw an exception of this type.
NumberFormatException
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.
consider the following application: class q6 { public static void main(string args[]) { holder h = new holder(); h.held = 100; h.bump(h); system.out.println(h.held); } } class holder { public int held; public void bump(holder theholder) { theholder.held++; }consider the following application: class q7 { public static void main(string args[]) { double d = 12.3; decrementer dec = new decrementer(); dec.decrement(d); system.out.println(d); } } class decrementer { public void decrement(double decme) { decme = decme - 1.0;
C. 12.3
19. consider the following code:1. stringbuffer sbuf = new stringbuffer();2. sbuf = null;3. system.gc();choose all true statements:
C. After line 2 executes, the StringBuffer object is eligible for garbage collection.
12. which of the following are true? (choose all that apply.)
C. An enum may contain public method definitions.D. An enum may contain private data.
18. what happens when you try to compile and run this application?1. import java.util.*; 2.4. public static void main(string[] a) {5. set<apple> set = new treeset<apple>();6. set.add(new apple());7. set.add(new apple());
C. An exception is thrown at line 7.
public class apple
C. An exception is thrown at line 7.
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. C must have a no-args constructor.
assertions are used to enforce all but which of the following?
C. Exceptions
7. 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);5. ob = stringarr[5];7. ob = floater;
C. Line 6
consider the following code. which line will not compile?
C. Line 6
2. which one statement is true about the following code?
C. Line 6 executes and line 4 does not.
18. when a negative byte is cast to a long, what are the possible values of the result?
C. Negative
13. 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 is/are true?
C. The class will compile if it is declared abstract. D. The class may not be instantiated.
inty but does not provide implementations for any of the five interface methods. which is/are true?
C. The class will compile if it is declared abstract.D. The class may not be instantiated.
15. what happens when you try to compile and run the following code?public class q15 { static string s;public static void main(string[] args) {system.out.println(">>" + s + "<<");
C. The code compiles, and prints out >>null<<
public class q15
C. The code compiles, and prints out >>null<<
what happens when you try to compile and run the following code? public class q15 { static string s; public static void main(string[] args) { system.out.println(">>" + s + "<<");
C. The code compiles, and prints out >>null<<
public class funcs extends java.lang.math
C. The code does not compile.
public static void main(string [] a) { funcs f = new funcs(); system.out.println("" + f.add(1, 2));
C. The code does not compile.
8. 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 " +5. ((x > 4) ? 99.99 : 9));
C. The output: value is 9.0
public boolean equals(object x) { xyzzy that = (xyzzy)x;public class conditional
C. The output: value is 9.0
10. which of the following statements about the wait() and notify() methods is true?
C. The thread that calls wait() goes into the monitor's pool of waiting threads.
thread t = new thread() { public void run() { system.out.println("going to sleep");threads inherit their priority from their parent thread.
C. The thread that calls wait() goes into the monitor's pool of waiting threads.
what are the legal types for whatsmytype? short s = 10; whatsmytype = !s;
C. There are no possible legal types
16. what are the legal types for whatsmytype? short s = 10; whatsmytype = !s;
C. There are no possible legal types.
to perform an operation on an object, we _______ one of the instance methods associated with the object.
Call
#in jdbc api, which of the following statements can be used to call a stored procedure?
CallableStatement
#in jdbc, which of the following class/interface should be used to call a store procedure?
CallableStatement
21. }21. }21. }21. a.count(3);21. parse("invalid");21. public classc classc;21. this(420, "snootchy");21. void dostuff(int x) {22.22. }22. }22. private string cardld;22. system.out.print("dostuff x = "+ x++);22. system.out.print("second ");22. select the list of primitives ordered in smallest to largest bit size representation.
D. char, int, float, long
select the list of primitives ordered in smallest to largest bit size representation.
D. char, int, float, long
#high-level streams
DataInputStream , DataOutputStream ,BufferedInputStream ,BufferedOutputStream
# which of the following classes do not directly read from/write to input/output devices such as disk files or sockets; rather, they read from/write to other streams?
DataInputStream/ DataOutputStream
there are two classes in java to enable communication using datagrams
DataPacket and DataSocket
there are two classes in java to enable communication using datagrams namely
DataPacket and DataSocket
java assertstuff java -ea assertstuffjava -classpath somewhere;elsewhere aaa.bbb.myapplication
Class MyApplication must contain the statement package aaa.bbb;. - D. The file MyApplication.class must be found either in somewhere\aaa\bbb or in elsewhere\aaa\bbb. (Substitute forward slashes for backslashes on a Unix system
#statement objects return sql query results as ___ objects.
DataSet
# select a correct statement deadlock describes a situation where two or more threads are blocked forever, waiting for each other
Deadlock describes a situation where two or more threads are blocked forever, waiting for each other
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.
#64.which of the following statements loads the jdbc-odbc driver?
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
#59.invoking class.forname method may throw
ClassNotFoundException
select the best choice.
Deadlock describes a situation where two or more threads are blocked forever, waiting for each other.
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.
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.
class b extends a {class b: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
public class arg{ string[] myarg; public static void main(string argv[]){ myarg=argv; } public void amethod(){ system.out.println(argv[1]); } }
Compile time error
suppose you want to write a class that offers static methods to compute hyperbolic trigonometricsuppose you want to write a class that offers static methods to compute hyperbolic trigonometricsuppose 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
D. The strategy fails because you cannot subclass java.lang.Math
3. 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?
D. The strategy fails because you cannot subclass java.lang.Math.
20. what does the following code print?public class astatic int x;public static void main(string[] args) { a that1 = new a that2 = new a(); that1.x = 5; x = -1; system.out.println(x);
D. -1
20. public static void main(string[] args) {20. system.out.print("harrier ");20. what is -50 >> 1?
D. -25
16. switch (mydog) {16. this("snootchy");16. this.x = x;16. which of the following operations might throw an arithmeticexception?
D. /
16. which of the following operations might throw an arithmeticexception?
D. /
18. which of the following statements are true?
D. A final class may not be extended.
19. which of the following statements are true?
D. A final class may not be extended.
18. how can you ensure that multithreaded code does not deadlock?
D. A, B, and C do not ensure that multithreaded code does not deadlock.
17. what is the return type of the instanceof operator?
D. Aboolean
17. how do you prevent shared data from being corrupted in a multithreaded environment?
D. Access the variables only via synchronized methods.
4. a thread's run() method includes the following lines:1. try {2. sleep(100);catch (interruptedexception e) { }assuming the thread is not interrupted, which one of the following statements is correct?
D. At line 2, the thread will stop running. It will resume running some time after 100 milliseconds have elapsed.
1. which of the following statements is correct? (choose one.)
D. Both primitives and object references can be both converted and cast.
11. which of the following may not be synchronized?
D. Classes
14. 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?
D. If the JVM doesn't crash and the code does not execute a System.exit() call, the finally block will always execute.
3. which of the statements below are true? (choose all that apply.)
D. None of the above.
how do you change the value that is encapsulated by a wrapper class after you have instan- tiated it?
D. None of the above.
15. which of the following operations might throw an arithmeticexception?
D. None of these
6. which of the following statements is true? (choose one.)
D. Object references can be converted in both method calls and assignments, and the rules governing these conversions are identical.
4. if all three top-level elements occur in a source file, they must appear in which order?
D. Package declaration, imports, class/interface/enum definitions.
given the following code, what is the expected outcome?public class test {public static void main(string [] a) { int [] b = [1,2,3,4,5,6,7,8,9,0]; system.out.println("a[2]=" + a[2]);
D. The code does not compile.
class cruncher
D. The code will compile and produce the following output: int version
5 25 55.5.5. // more code here5. // more code here5. }5. } 6.5. anim = rover;5. bufferedoutputstream(raf);5. 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.)
D. The code will compile and produce the following output: int version.
5. consider the following class:1. class cruncher {2. void crunch(int i) {3. system.out.println("int version");6. system.out.println("string version");10. cruncher crun = new cruncher();11. char ch = 'p';12. crun.crunch(ch);
D. The code will compile and produce the following output: int version.
8. consider the following code: 1. dog rover, fido;2. animal anim; 3.4. rover = new dog();6. fido = (dog)anim;which of the following statements is true? (choose one.)
D. The code will compile and run.
5. which statement is true about the following code fragment?1. int j = 2;2. switch (j) {4. system.out.println("value is two");5. case 2 + 1:6. system.out.println("value is three");8. default:9. system.out.println("value is " + j);
D. The output would be the text value is two followed by the text value is three.
2. choose the valid identifiers from those listed here. (choose all that apply.)
A. BigOlLongStringWithMeaninglessName_ B. $int_C. bytes_D.$1E. finalist
2.you can determine all the keys in a map in which of the following ways?
A. By getting a Set object from the Map and iterating through it.
12. 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?
A. Class loading takes no additional time.
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?
A. Class loading takes no additional time.
14. which of the following may be declared final? (choose all that apply.)
A. Classes B. Data C. Methods
4. which one statement is true about the following code fragment?1. import java.lang.math;3. system.out.println("cosine of 0.123 = " +4. mymath.cos(0.123));
A. Compilation fails at line 2.
8. how can you force garbage collection of an object?
A. Garbage collection cannot be forced.
9. which of the following statements are true? (choose all that apply.)
A. 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()
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);
A. Yes
14. is it possible to write code that can execute only if the current thread owns multiple locks?
A. Yes.
8. consider the following definition:1. public class outer {3. private int b = 2;4. public void method(final int c) {5. int d = 3;7. private void imethod(int e) { 8.which variables can be referenced at line 8? (choose all that apply.)
A. a B. b C. c E. e
select the valid primitive data types. (select all that apply.)
A. boolean_ C. charD. float
16. which of the following are legal argument types for a switch statement?
A. byteB. intE. char
1. which of the following declarations are illegal? (choose all that apply.)
A. default String s;D. abstract double d;E. abstract final double hyperbolicCosine();
13. which of the following are legal? (choose all that apply.)
A. for (int i=0, j=1; i<10; i++, j++) B. for (int i=0, j=1;; i++, j++)D. for (String s = ""; s.length()<10; s += '!')
14. 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?
A. if (x == y)
13. which of the following are legal import statements?
A. import java.util.Vector;C. import static java.util.Vector.*;
14. which of the following classes implement java.util.list?
A. java.util.ArrayListD. java.util.Stack
19. 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?
A. java.util.Arrays.equals(a1, a2);
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?
A. java.util.Arrays.equals(a1, a2);
10. suppose prim is an int and wrapped is an integer. which of the following are legal java statements? (choose all that apply.)
A. prim = wrapped;B. wrapped = prim;C. prim = new Integer(9);D. wrapped = 9;
# which of the following options is not a valid declaration of the randomaccessfile class?
AccessFile("file.txt", "w");
#select an operation which may cause an unchecked exception.
Accessing an element of an array.
#select the correct syntax for throwing an exception when declaring a method.
Accessing an element of an array.
an instance method that returns the value of an instance variable is said to be an _______.
Accessor/Getter
# deadlock describes a situation where two or more threads are blocked forever, waiting for each other
T
# values stored in treeset are not allowed duplication
T
# when a task must be performed at un-predictable time
T
# when the run() method terminates
T
#each parent class method may be overridden once at most in any one subclass.
T
#final keyword in a method declaration to indicate that the method cannot be overridden by subclasses
T
#in a java source code, package declarations, if they are needed, must be put at the beginning of a program.
T
#overloading methods are implemented in the same class
T
#the entry point of a java program must be declared that it accepts an array of strings as parameters.
T
#the entry point of a java program must be put in a class declaration.
T
after execution of line 1, sbuf references an instance of the stringbuffer class. after execution of line 2, sbuf still references the same instance
T
swing components cannot be combined with awt components
T
#a value variable contains data's value , a reference variable contains the address of data
T T
#which of the following protocols is a reliable protocol?
TCP
#select a correct statement about tcp and udp protocol:
TCP (Transmission Control Protocol) is a connection-based protocol that provides a reliable flow of data between two computers.
which of these are integer constants of textevent class?
TEXT_FORMAT_CHANGED
leaf nodes are those that can have children.
Textfield.requestFocus()
#in a jdbc application, suppose that the connection, named con, was created.study the following code:string sql= "select * from students";statement stmt = con.createstatement();resultset rs= stmt.executequery(sql);// code for data accessing in the result set.con.close(); rs.close();
The above code will throw an exception.
in a jdbc application, suppose that the connection, named con, was created. study the following code:
The above code will throw an exception.
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
given the following code, what will be the outcome? public class funcs extends java.lang.math{public int add(int x, int y){return x + y;}public int sub(int x, int y){return x - y;}public static void main(string[]a){funcs f = new funcs();system.out.println("" + f.add(1, 2));}}
The code does not compile
public class test {public static void main(string [] a){int [] b = [1,2,3,4,5,6,7,8,9,0]; system.out.println("a[2]=" + a[2]);}}
The code does not compile
reference variables are known as _______ variables in other programming languages
Pointer
# an application that creates an instance of thread must provide the code that will run in that thread. select a correct way to do this
Provide a Runnable object. The Runnable object is passed to the Thread constructor
the class will compile if it is declared abstract. the class may not be instantiated.the code compiles and executes; afterward, the current working directory contains a file called datafile
The code fails to compile
the code compiles and executes; afterward, the current working directory contains a file called datafile
The code fails to compile
13. args=null;13. catch (exception x) { }13. catch (ioexception e) { }
The code fails to compile.
there will be a compiler error, because class greebo does not correctly implement the runnable interface.there will be a compiler error, because class greebo does not correctly implement the runnable interface
Runnable interface
class base
Runtime exception
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
10. public class classa {10. public class classa {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
class xyzzy { int a, b;class zebra extends animal {classa a = new classa();classa a = new classa();
StackOverflowError
give the following code, which of the following will not compile? enum spice{ nutmeg, cinnamon, coriander, rosemary; }
String ob = new String(); Spice sp = ob;
given the following code, which of the following will not compile? enum spice { nutmeg, cinnamon, coriander, rosemary; }
String ob = new String(); Spice sp = ob;
# suppose that: your application has to read and write a string a lot of times. your application does not need to have multi threaded supports. performance is important. which of the following classes will you choose to deal with string data type to achieve the above requirements
StringBuilder
# how do you use the file class to list the contents of a directory? (choose one.)
String[] contents = myFile.list();
how do you use the file class to list the contents of a directory
String[] contents = myFile.list();
#62.in a relational data model, ____defines the representation of the data.
Structure
public abstract class abby
SubAbby generates a compiler error. - If SubAbby were declared abstract, it would compile without error. - Abby is a legal type for variables.
an expression involving byte, int, and literal numbers is promoted to which of these?
int
the java primitive keyword that indicates a value is a 32 bit whole number
int
#select a correct java declaration:
int $myInt;
public float amethod(float a, float b) throws exception
int a,b float p,q
which of these is an incorrect array declaration?
int arr[] = int [5] new
event class is defined in which of these libraries?
java.util
# in java collection framework, which of the following pre-defined classes allow an element can be accessed through its index?
java.util.ArrayList
# suppose that a homogenous collection of objects, that belong the same type, are managed. which of the following delarations is the best choice?
java.util.ArrayList 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)
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);
#which of the following commands is used to compile java source code into java bytecode?
javac
# the swing component classes can be found in the ________________ package.
javax.swing
have a nice day!he swing component classes can be found in the package.
javax.swing
the swing component classes can be found in the
javax.swing
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
10. interface foo { int bar(); }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; } }
#92.which of the following creates a list with 5 visible items and multiple selection enabled?
new List(5, true)
#91.which constructor creates a textarea with 10 rows and 20 columns?
new TextArea(10, 20)
#83.you want to construct a text area that is 80 character-widths wide and 10 character-heights tall. what code do you use?
new TextArea(10, 80)
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.
consider the following code: cat sunflower;washer wawa;swampthing pogo;sunflower = new cat();wawa = sunflower;pogo = (swampthing)wawa;
The code will compile but will throw an exception at line 7, because the runtime class of wawa cannot be converted to type SwamThing.
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.
case sensitive. always begin variable with a letter with no spaces. cannot be reserved word.case sensitive. always begin variable with a letter with no spaces. cannot be reserved word.cat sunflower
The code will compile but will throw an exception at line 7, because the runtime class of wawa cannot be converted to type SwampThing.
cat sunflower;
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. 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.
what happens when you try to compile and run the following program? a d a import java.util.*; b public class main{ public static void main(string argv[]){ d c vector<lnteger> t = new vector<lnteger>(); t.add(12r; d d t.add(2); t.add(6); t.add(2.4); lterator<lnteger> i = t.iterator(); int sum=0; next while(i.hasnext()) sum += i.next(); system.out.println(sum);
The program has a compile error
if you attempt to compile and execute the following application, will it ever print out the message in xxx?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
what are the legal types for whatsmytype
There are no possible legal types
what are the legal types for whatsmytype? (choose one.) short s = 10; whatsmytype = !s;
There are no possible legal types.
how can you ensure that multithreaded code does not deadlock ? (choose one)
There is no single technique that can guarantee non-deadlocking code.
# you use java.io.randomaccessfile to manipulate a file name myfile.txt. which of the following statements is valid if you want to open the file myfile.txt in a writing-only mode?
There is no writing-only mode in java.io.RandomAccessFile class.
study the following java statements: string s1= "hello"; string s2= "hello"; string s3= "hello";
There is only one string is stored in memory of the program.
16. }
There will be a compiler error, because class Greebo does not correctly implement the
class greebo extends java.util.vector
There will be a compiler error, because class Greebo does not correctly implement the Runnable interface.
class greebo extends java.util.vector implements runnable
There will be a compiler error, because class Greebo does not correctly implement the Runnable interface.
# thread synchronization should be implemented if ....
Threads access common resources
# which of the following statements about threads is true? (choose one.)
Threads inherit their priority from their parent thread.
# .. exist within a ... every ... has at least one..
Threads, process, process, thread
what does the following code do
Throws an exception
what does the following code do?what does the following code do?
Throws an exception.
select incorrect statement about serversocket class
To make the new object
#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
if you need a set implementation that provides value-ordered iteration,if you need a set implementation that provides value-ordered iteration, which class should you use
TreeSet
in the following code fragment, after execution of line 1, sbuf referencesin the following code fragment, after execution of line 1, sbuf referencesin the following code fragment, after execution of line 1, sbuf references an instance of thein the following code fragment, after execution of line 1, sbuf references an instance of thein 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
sbuf.insert(3, "-university");
True
stringbuffer is slower than a stringbuilder, but a stringbuffer
True
unicode characters are all 16 bits.unicode characters are all 16 bits.
True
#with respect to the java socket. (1) a socket contains two binary streams for sending and receiving data. (2) a socket contains two text streams for sending and receiving data. (3) developers must implement background operations for sending and receiving data. the statement (1) is ..., (2) is ..., and (3) is ...
True, false, false
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
#you are required to build an application that connects to database to store and retrieve data. your application must be independent with the underlying database. which driver types should you use?
Type 3-driver
double endspeed);double endspeed);double endspeed);double endspeed);double radius,double radius,double radius,double radius,double startspeed,double startspeed,double startspeed,double startspeed,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 are pure java and implement the network protocol for a specific data source. the client connects directly to the data source.
Type 4
# study the following code was implemented in the hello class: static void print(integer obj){ system.out.println(obj); integer obj= new integer(5); int n= obj; //(1) hello.print( n ); //(2)
Unboxing, boxing
boolean neutered;boolean neutered; string markings;boolean weird(thing s) { integer x = new integer(5); return s.equals(x);
Yes
# 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
study the following code was implemented in the hello class:static void print(integer obj){ system.out.println(obj); } and it is used as:integer obj= new integer(5); int n= obj; //(1) hello.print( n ); //(2) a ..... operation is carried out at the code line (1)a ..... operation is carried out at the code line (2)
Unboxing, boxing
bytecode characters are all 16 bits
Unicode characters
1. public class b {1. public class b extends a {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
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
1.which of the following are valid declarations? assume java.util.* is imported.
Vector<Map> v;Set<String> s; Map<String, String> m;
which of these class have only one field 'type'?
Void
public enum wallpaper
Wallpaper wp = Wallpaper.BLUE; - void aMethod(Wallpaper wp) { System.out.println(wp);} - int hcode = Wallpaper.BLUE.hashCode();
#a method in a super class is implemented using the default modifier, this method can not be overridden in subclasses using the ..... modifier.
private
#which of the following modifiers is valid for a constructor?
private
suppose threads athread and bthread are both accessing a shared object named sharedob, and athread has just executed: sharedob.wait();
aThread.interrupt(); - sharedOb.notifyAll();
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)
#55.defaulttablemodel contains the methods for
adding a column + inserting a new row + adding a new row
keyword: final (used to indicate that the variable (number) will never change)
What modifier and keyword are used to declare a class variable.
20.20. }20. }20. }20. }
When the application is run, all three threads (hp1, hp2, and hp3) will execute concurrently, taking time-sliced turns in the CPU.
when does an exception's stack trace get recorded in the exception object?
When the exception is constructed
# which of the following statement is correct about thread?
When the run() method of a thread returns, that thread is put into ready state
# when is a thread considered as a dead thread? when the run() method terminates
When the run() method terminates
interface. when is the assignment x = y; legal? (choose one.)
When the type of x is Object
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
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
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
sql keyword is followed by the selection criteria that specify the rows to select in a query
Where
e. subset
all
shorty is a short and wrapped is a short
all
#we can ___
all ma chon
select correct statement(s) about remote class.(choose one)
all of
when a negative long is cast to a byte, what are the possible values of the result? (choose one.)
all of
list<string> t = new vector<string>(); vector <string> h = new vector<string>();literal can be of which of these data types?
all of the mentioned
suppose you are writing a class that will provide custom deserialization. what access mode should the readobject() method have
private
the output would be the text value is two followed by the text value is threethe output would be the text value is two followed by the text value is three.the output would be the text value is two followed by the text value is three.the output: b contains 250
b contains 5
on applying left shift operator, <<, on an integer bits are lost one they are shifted past which position bit?
b) 32
(121) which of the following may follow the static keyword? (choose three.)
b. Datac. Methodsd. Code blocks enclosed in curly brackets
(108) which of the following statements are true?1)an abstract class may not have any final methods.2)a finalclass may not have any abstract methods.
b. Only statement 2
(73) what results from running the following code?1. public class xor {2. public static void main(string args[]) {3. byte b = 10; // 00001010 binary4. byte c = 15; // 00001111 binary5. b = (byte)(b ^ c);6. system.out.println("b contains " + b);7. }8. }
b. The output: b contains 5
study the statements: 1) when a jdbc connection is created, it is in auto-commit mode 2) 0nce auto-commit mode is disabled, no sql statements will be committed until you call the method commit explicitly
both 1 and 2 are true
ch11: fields in an interface are ________.
both final and static
jumps out of a loop or switch
break
(86) what is -50 >> 2
c. -13
(5695) which of the following is nota valid comment:
c. /* comment
(185) which of the following are true? (choose two.)m.
c. An enum may contain public method definitions.d. An enum may contain private data.
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. }
c. An exception is thrown at line 7.
(228) which of the following are methods of the java.util.sortedmap interface?(choose three.)
c. headMap d. tailMape. subMap
#rmi applications often comprise two separate programs, a server and a client and they
can run in two separate virtual machines
#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#with respect to the java rmi, a server and a client program .......
can run in two separate virtual machines.
the container can display three completely different components at different times, depending perhaps on user input
cardlayout
introduces one of several possible paths of execution in a switch statement
case
introduces statements that are executed when something interrupts the flow of execution in a try clause
catch
ch12: all exceptions that do not inherit from the error class or the runtimeexception class are ________.
checked exceptions
suppose class home has methods chopwood() and carrywater(); it also has a method called chopwoodandcarrywater(), which just calls the other two methods. which statements are true? (choose all that apply.)
chopWoodAndCarryWater() is an example of inappropriate cohesion. - chopWoodAndCarryWater() is an example of inappropriate coupling.
#the private and protected modifiers are not applied on
class
#the protected modifier can not be applied to
class
a description of a possible object
class
string in java is a?
class
the keyword used to create a blueprint of an object
class
no compiler error and no exception
class A
object references can be converted in both method calls and assignments, and the rules governing these conversions are identicalobject references can be converted in both method calls and assignments, and the rules governing these conversions are identical.object references can be converted in both method calls and assignments, but the rules governing these conversions are very different
conversions are identical
method of the java.io.file class can create a file on the hard drive
createNewFile()
a that2 = new a();a that2 = new a();that1.x = 5; that2.x = 1000; x = -1;system.out.println(x);}}
d. -1
a that2 = new a();that1.x = 5; that2.x = 1000; x = -1;system.out.println(x);}}
d. -1
(53) what is the range of values that can be assigned to a variable of type short?(choose one.)
d. -2^15 through 2^15 - 1
(54) what is the range of values that can be assigned to a variable of type byte? (choose one.)
d. -2^7 through 2^7 - 1
what is the return type of the instanceof operator?
d. A boolean
(125) which of the following statements are true? (choose one.
d. A final class may not be extended.
(143) when a negative long is cast to a byte, what are the possible values of the result? (choose one.)
d. All the above
(126) what does the following code print?(126) what does the following code print?(127) which of the following statements is correct? (choose one.)
d. Both primitives and object references can be both converted and cast.
(127) which of the following statements is correct? (choose one.)
d. Both primitives and object references can be both converted and cast.
(235) which of the statements below are true? (choose one.)
d. None of the above
(193) 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. }
d. None of the above scenarios can be guaranteed to happen in all cases.
(234) which of the statements below are true? (choose one.)
d. None of the above.
(80) which statement is true about the following method?(80) which statement is true about the following method?(81) which of the following operations might throw an arithmeticexception?(choose one.)
d. None of these
(81) which of the following operations might throw an arithmeticexception?(choose one.)
d. None of these
(132) which of the following statements is true? (choose one.)
d. Object references can be converted in both method calls and assignments,
(207) which of the following are true? (choose one.)
d. The JVM runs until there are no non-daemon threads.
#which of the following access modifiers does not allow a class to be accessed outsite its package?
default
ch12: if your code does not handle an exception when it is thrown, it is dealth with by this.
default exception handler
indicates the beginning of a looping structure, usually used when you want a loop to execute at least once.
do
13. classb.getvalue();13. float f= float.parsefloat(str);13. hasstatic.x++;13. hipri hp1 = new hipri();13. int y;13. int[] somearray = (int[])obj;13. public class pass {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
system.out.print("dostuff x = "+ x++);
doStuff x = 5 main x = 5
dostuff x = 6 main x = 6
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
class a extends java.util.vector { private a(int x)
does not create a default
class a extends java.util.vector { private a(int x) { super(x); }class a extends java.util.vector { private a(int x)
does not create a default
the class is primary clas that has the driver information
drivermanager
(137) which of the following may legally appear as the new type (between theparentheses) in a cast operation?(choose one.)
e. All of the others
(184) which of the following is(are) true? (choose one.)a. an enum definition may contain the main() method of an application.
e. All the above
(203) which of the following calls may be made from a non-static synchronizedmethod? (choose one.)
e. All the above
(216) 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
e. Compilation succeeds. No exception is thrown during execution.
(4929) which statements about jdbc are not true? (choose 2)
e. JDBC is a Java database system.f. JDBC is a Java API for connecting to any kind of DBMS
(241) 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");
e. No directory is created, and no file is created.
(240) which of the following is true? (choose one.)
e. None of the above
(249) what method of the java.io.file class can create a file on the hard drive?
e. createNewFile()
(1531) when comparing java.io.bufferedwriter to java.io.filewriter, whichcapability exists as a method in only one of the two? (choose one.)
e. writing a line separator to the stream
compilation fails because of an error in line 15
error in line 19
at line 2, the thread will stop running. it will resume running some time after 100 milliseconds have elapsed.at line 2. the thread will stop running it will resume running some time after 100 miliseconds have elapsedattempting to add anything other than a string to fancyvec results in a compiler error.attributes/variables that define the object's state; can hold numbers, characters, strings, other objects
field
(128) 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;
f. Line 6
(118) which of the following statements are true? (choose one.)
f. None of the above
(161) which of the following are legal loop definitions? (choose one.)
f. None of the above.
compilation succeeds, although the import on line 1 is not necessary. during execution, an exception is thrown at line 3
fails at line 2
#103.if a frame uses its default layout manager and does not contain any panels, then all the components within the frame are the same width and height.
false
#104.with a border layout manager, the component at center gets all the space that is left over, after the components at north and south have been considered.
false
#108.when using the gridbaglayout manager, each new component requires a new instance of the gridbagconstraints class. is this statement true or false?
false
#34.the server can create a server socket regardless of whether the port is in use or not.
false
#36.you cannot get instances of inputstream or outputstream because inputstream and outputstream are abstract classes.
false
#39.the url constructor throws malformedurlexception if the url is syntactically incorrect.
false
#47.you can find all the available locales from a swing object.
false
#50.you can get hour, minute and second from the date class.
false
#85.the checkboxgroup class is a subclass of the component class.
false
#suppose that the current position of a resultset, named rs, is at the last record, the statement rs.next() will return ......
false
indicates a statement is not accurate
false
is the following statement true or false? when using the gridbaglayout manager, each new component requires a new instance of the gridbagconstraints class.
false
string s1 = "xyz"; string s2 = new string(s1);
false
attributes/variables that define the object's state; can hold numbers, characters, strings, other objects
field
#real-world objects share two characteristics: they all have state and behavior.
field , menthod
datainputstream
fileinputstream
11. public class sprite {11. public enum direction { north, south, east, west }11. public int held;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
public interface operatecar {public interface operatecar {public interface operatecar {public interface operatecar {public interface status {
final;static;public
introduces the statements that will be executed after a try-catch block has finished executing
finally
which of these clause will be executed even if no exceptions are found?
finally
a single try block must be followed by which of these?
finally & catch
indicates that a value is a 32 bit number with 1 or more digits after the decimal point
float
begins a loop that declares the control variable, condition, and terminating value on one line
for
suppose salaries is an array containing floats
for (float f:salaries)
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)
10. oos.close();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]);
static string s;static void foo(int...x) {
for(int z : x) System.out.println(z);for( int i=0; i< x.length; i++ ) System.out.println(x[i]);
#the .... method of the ...... class helps loading a jdbc driver.
forName(...), java.lang.Class
#113.in java,what do you call an area on the screen that has nice bolders and various button along the top bolder?
frame
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
fill the blank with a method signature of function1.
function1
#consider the following url address:http://192.168.2.2:12/users/index.html select a correct statement:
http is protocol, 192.168.2.2:12 is socket.
consider the following line of code:consider the following url address:
http is protocol, 192.168.2.2:12 is socket.
for (int i = 0; i < 2; i++)
i = 0 j = 1 - i = 0 j = 2 - i = 1 j = 0 - i = 1 j = 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
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
creating an object with the "new" operator, eg. str1 = new string("hello");
instantiation
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){}
given the following class definition, which of the following methods could be legally placed after the comment//here public class rid{ public void amethod(int i, string s){} //here}
public void amethod(String s, int i){} + public void Amethod(int i, String s) {}
#suppose class x contains the following method: void dosomething(int a, float b) { ... }
public void doSomething(int a, float b) { ... }
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 class x contains the following method: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) { ... }
suppose class x contains the following method: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 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){ ... }
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)
suppose you are writing a class that will provide custom deserialization.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 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?
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
the class implements java.io.serializable (not java.io.externalizable). what access mode should the readobject() method have? (choose one.)
private
mammal extends animalman has the best friend who is a dog
private Dog bestFriend
#which of the following declarations is not valid?
private int[] ar3 = new int[2]{1, 2};
a class member declared protected becomes member of subclass of which type?
private member
can be called only from constructors or methods of the same class
private methods
the class implements java.io.serializable (and not java.io.externalizable)
private readObject
#with respect to access modifier overridden, the right order is:
private, protected, default, public
#select a characteristic that is not supported by the java language?
procedure-oriented.
#which of the following modifiers cannot be applied for a class?
protected
#which of the following modifiers cannot be applied for interface and abstract classes?
protected
indicates that a variable or method can be used by subclasses from another package
protected
url referring to databases use the form
protocol:subprotocol:datasoursename
ch11: when a class implements an interface, it must ________.
provide all of the methods that are listed in the interface, with the exact signatures and return types specified.
indicates that a variable, class, or method can be used by any other java code
public
suppose class aaa.aaa has a method called callme(). suppose class bbb.bbb, which extends aaa.aaa, wants to override callme(). which access modes for callme() in aaa.aaa will allow this?
public - protected
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 - protected
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 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.)
public - protected - Default
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) { }
class xyzzy
public int hashCode() { return a; } - public int hashCode() { return (int)Math.random();}
1. public interface a {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 { }
a programmer wants to create an interface called b that has a as its parent. which interface declaration is correct?
public interface B extends A { }
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 { }
string default_greeting = "hello world";
public interface B extends A { }
make a public interface called hello:
public interface Hello {}
can be called from constructors or methods of any class
public methods
#which of the following declarations is not correct?
public protected String myString;
functions. you decide to subclass java.lang.math and provide the new functionality as a set offunctions. you decide to subclass java.lang.math and provide the new functionality as a set ofgeneral java variable naming conventions would suggest that a variable named nickel_value would most probably be declared using which of the following combinations of modifiers?
public static final double
signatures are valid for the main() method entry point of an application
public static void main(String[] args)
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");
public void logIt(String... msgs)
public class setf extends frame
s.setbackground(color.pink)
line of code tells a scanner called sc to use a single digit as a delimiter
sc.useDelimiter("\\d")
ch14: this search algorithm steps sequentially through an array, comparing each item with the search value.
sequential search
#in a client-server application model, which side will wait for a connection?
server
select incorrect statement about socket class
server through UDP
ch13: you can use this method to make a text field read-only.
setEditable
# which method do you use to enable and disable components such as jbutton s?
setEnable
ch13: this method is inherited from jcomponent and changes the appearance of a component's text.
setFont
ch13: this method can be used to store an image in a jlabel or a jbutton component.
setIcon
ch13: you use this method to place a menu bar on a jframe.
setJMenuBar
select the correct statement which set the layout manager of a given frame to flowlayoutmanager
setLayout(new Flowlayout());
#105.an applet has its layout manager set to the default of flowlayout. what code would be the correct to change to another layout manager?
setLayout(new GridLayout(2,2));
ch13: this method sets the intervals at which major tick marks are displayed on a jslider component.
setMajorTickSpacing
to make the background color of a label different with the color of its container, we need to use the ..... method of the jlabel class first.
setOpaque(true)
#10.which of these method is used to explicitly set the priority of a thread?
setPriority()
#90.which method is used to set the text of a label object?
setText( )
indicates a value is a 16 bit whole number
short
suppose shorty is a short and wrapped is a short. which of the following are legal java state- ments? (choose all correct options.)
shorty = wrapped; - wrapped = shorty; - shorty = new Short((short)9); - shorty = 9;
#96.which method will cause a frame to be displayed?
show() + setVisible()
#15.which of these method of thread class is used to suspend a thread for a period of time?
sleep()
#7.which of these method can be used to make the main thread to be executed last among all the threads?
sleep()
#a(an) ....... is one endpoint of a two-way communication link between two programs running on the network.
socket
#a/an ...... is bound to a port number so that the tcp layer can identify the application having network comunication
socket
a.firsta.firsta.firsta.firsta.methoda();a.prim = wrapped;a.prim = wrapped;a.sc.usedelimiter("d");a.sc.usedelimiter("d");a/an ...... is bound to a port number so that the tcp layer can identify the application having network comunication
socket
#30.to obtain an objectinputstream from a socket, use
socket.getObjectStream()
array of yyy. when is the assignment xarr = yarr; legal? (choose one.)
sometime
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
ch11: this key word refers to an object's superclass.
super
keywords is used to invoke a method in the parent class
super
refers to the superclass of the code in which the word super appears
super
the ____reserved word is used to deactivate polymorphism and invoke a method of the superclass.
super
#which of the following methods can be used to call a constructor of a father class from the sub-class?
super()
ch11: the following is an explicit call to the superclass's default constructor.
super();
class xyz
super(); - this(1.23f);
what code at line 4 results in a class that compiles?
super();vsthis(1.23f);
ch11: in an inheritance relationship, this is the general class.
superclass
#all checked exception types thrown from a method must be represented in the method's "throws" list
t
#assertions provide a convenient mechanism for verifying that a class's methods are called correctly.
t
#checked exceptions should extend java.lang.exception or one of its subclasses
t
#circumstances of this type are called exception conditions in java and are represented using objects (all exceptions descend from the java.lang.throwable).
t
#constructing an instance of file does not create a file on the local file system
t
#do not read/write from input/output devices such as files or sockets; rather, they read/write from other streams
t
#file class represents the name of a file or directory that might exist on the host machine's file system
t
#if a class does not have any superclass, then it is implicitly derived from object class
t
#if an exception arises, the first matching catch block, if any, is executed, and the rest are skipped
t
#if no exceptions are thrown in the try block, all catch blocks are bypassed
t
#inheritance combined with overriding facilitates polymorphism
t
#interfaces cannot be instantiated
t
#java's input/output (i/o) structure is substantially based on the concept of streams, which are classes that help you read and write files and networks
t
#object streams go one step beyond data streams by allowing you to read and write entire objects
t
#readers and writers are exclusively oriented to unicode characters
t
#runtime exceptions should extend java.lang.runtimeexception or one of its subclasses
t
#the intention is that assertions typically will be enabled during development and disabled in the field
t
#the low-level varieties communicate with i/o devices, and the high-level varieties communicate with low-level varieties
t
#the most common of these extend from the superclasses filterinputstream and filteroutputstream
t
#the only access modifier permitted to non-nested classes is public
t
#the process of writing an object is called serialization
t
#the randomaccessfile class provides methods that support seeking, reading, and writing
t
#the try block executes to completion without throwing any exceptions whatsoever
t
#the try block throws an exception that is handled by one of the catch blocks
t
#the try block throws an exception that is not handled by any of the catch blocks
t
#transient fields are also not serialized
t
#utf stands for ucs transformation format, and ucs in turn stands for universal character set
t
#with a random-access file, you can seek to a desired position within a file and then read or write a desired amount of data
t
#11.what is synchronization in reference to a thread?
t's a process of handling situations when two or more threads need access to a shared resource.
#102.what is the default layouts for a applet, a frame and a panel?ans : for an applet and a panel, flow layout is the default layout, whereas border layout is default layout for a frame.if a frame uses a grid layout manager and does not contain any panels, then all the components within the frame are the same width and height.
true
#22.you should always invoke the unlock method in the finally clause.
true
#26.the runnable interface is more general than the thread class. you can convert any class that extends thread to a class that implements runnable.
true
#27. an exception occurs if the resume() method is invoked by a finished thread object.
true
#28.you should not directly invoke the run() method of a thread object.
true
#35.the client can connect to the server regardless of whether the port is in use or not.
true
#37.an applet cannot connect to a server program on a web server where the applet was loaded.
true
#38.you can transmit objects over the socket.
true
#40.getinputstream() and getoutputstream() are used to produce inputstream and outputstream on the socket.
true
#46.to display number in desired format, you have to use the numberformat class or its subclasses.
true
#48.the locale property is in the component class, thus, every java swing component has the locale property.
true
#49.you can get year, month, day, hour, minute, and second from an instance of gregoriancalendar.
true
#51.the timezone class has a static method for obtaining all the available time zone ids.
true
#52.you can get all the available locales from an instance of calendar, collator, dateformat, or numberformat.
true
a final class may not have any abstract methods
true
a final class may not have any abstract methods.a final class may not have any abstract methods
true
a method in an interface can access class level
true
a protected method may only be accessed by classes of the same
true
a protected method may only be accessed by classes or interfaces of the same package or bysubclasses of the class in which it is declared.a runtime error indicating that no run method
true
indicates a statement is accurate
true
int x = 6; x =~x
true
line.point p = new line.point();
true
output one one two two
true
public int function1(int intiger1){public int function1(int intiger1){public int turn(int intiger1){public int turn(int intiger1){public interface b instanceof a {}
true
string s1 = "xyz"; string s2 = "xyz";
true
stringbuffer sbuf = new stringbuffer("abcde");
true
system.out.println(x);t.join();t.start(); try {tcp is a connection-based protocol
true
vector does not allow duplicate elements
true
we don't need any method because elements in vector are automatically sorted
true
which of these statement is correct?
true and false are non numeric values
# an instance of the java.util.scanner class can read data from the keyboard (1), a file (2), a string of characters (3). (1) is ......., (2) is ......., and (3) is ..........
true, true, true
#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 jdbc,(1) in the two-tier model, a java application talks directly to the data source.(2) in the three-tier model, a "middle tier" of services is let between a java program and the data source.(3) the jdbc api supports two-tier processing model for database access only.
true,true,false
ch12: you can think of this code as being "protected" because the application will not halt if it throws an exception.
try block
#23.given the following code, which set of code can be used to replace the comment so that the program displays time to the console every second?
try { Thread.sleep(1000); } catch(InterruptedException e) { }
indicates that a method doesn't return a value
void
what is the return type of a method that does not returns any value
void
void callme() throws objectstreamexception
void callMe() - void callMe() throws NotSerializableException
when the user attempts to close the frame window, event in generated.
window closing
class testthread3 extends thread
yes
is it possible to define a dass called thing so that the following method can return true under certain drcumstances? boolean weirdfthing s) {integer x = new lnteger(5); return s.equals(x);}
yes
public class app
4
the number of bytes depends on the underlying system
8
19. which of the following operators can perform promotion on their operands? (choose all that apply.)
A. +B. -E. ~
12. which of the following calls may be made from a non-static synchronized method?
A. A call to the same method of the current object.B. A call to the same method of a different instance of the current class.C. A call to a different synchronized method of the current object.D. A call to a static synchronized method of the current class.
18. which of the following may appear on the left-hand side of an instanceof operator?
A. A reference
18. }18. }18. }18. }18. }catch (nullpointerexception npe) {18. assert (x > y): "stuff";18. for (object obj: reverse(list))18. hp3.start();18. system.out.print(" main x = "+ x);18. system.out.print("collie ");18. which of the following may appear on the left-hand side of an instanceof operator?
A. A reference
17. which of the following are true?
A. An anonymous inner class may implement at most one interface.C. An anonymous inner class may extend a parent class other than Object.
13. which of the following are true? (choose all that apply.)
A. An enum definition may contain the main() method of an application.B. You can call an enum's toString() method.C. You can call an enum's wait() method.D. You can call an enum's notify() method.
# which of the following options is not a valid thread priority property?
AVERAGE_PRIORITY
what does awt stands for?
Abstract Window Toolkit
a class that cannot be instantiated is called a/an ____.
Abstract class.
the words public and private are _____ _____
Access modifiers
how do you prevent shared data from being corrupted in a multithreaded environment
Access the variables
how do you prevent shared data from being corrupted in a multithreaded environment? (choose one.)
Access the variables only via synchronized methods.
how do you prevent shared data from being corrupted in a
Access the variables only via synchronized mothods
try { ((a)new b()).process(); }try {
At line 2, the thread will stop running. It will resume running some time after 100 milliseconds have elapsed
# you are required to build a java application. your application uses vector to store data. each time elements, taken from the vector, should be displayed to users in a random order. which of the following methods can be used to achieve the above task?
Collections.shuffle()
#95.a frame's background color is set to color. yellow, and a button's background color is to color.blue. suppose the button is added to a panel, which is added to the frame. what background color will be used with the panel?
Colr.Yellow
string s = "abcde";
Compilation succeeds. No exception is thrown during execution.
string s = "fpt";
Compilation succeeds. No exception is thrown during execution.
stringbuffer s1 = new stringbuffer("fpt");
Compilation succeeds. No exception is thrown during execution.
how do the imports affect the time required to compile the source file
Compilation takes slightly more time
which of these statement is incorrect?
Every class must contain a main() method.
#errors beyond the control of a program are called
Exceptions
assertions are used to enforce all but which
Exceptions
#33.the server listens for a connection request from a client using the following statement:
Socket s = serverSocket.accept()
select the valid primitive data types.
boolean,char,float
given the following classes:given the following code class base{}public class mycast extends base{ static boolean b1=false; static int i = -1; static double d = 10.1; public static void main(string argv[]){ mycast m = new mycast(); base b = new base(); //here }}which of the following, if inserted at the comment //here will allow the code to compile and run without error
1) b=m;3) d =i;
select correct statement(s). (1) all byte stream classes are descended from the inputstream andoutputstream classes . (2) all character stream classes are descended from the reader and writer classes . (3) all byte stream classes are descended from the reader and writer classes .(4) all character stream classes are descended from the inputstream andoutputstream classes .
1, 2
select correct statement(s). (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
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
#in java network programming using sockets, five steps are usually used: 1) open a socket. 2) open an input stream and output stream to the socket. 3) read from and write to the stream according to the server's protocol. 4) close the streams. 5) close the socket.
1, 2, 3, 4, 5
#to implement rmi, classes need to be implemented: (1) remote interface, (2)server object, (3) server program, (4) client program, (5) stub object, (6) transport object, (7) remote reference object
1, 2, 3, 4, 5
#select correct statements.
1, 3
#select incorrect java program entry point declarations.
1, 4, 5
select correct statement(s). (select one option) (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
given the following code what will be the output?class valhold{ public int i = 10;}public class obparm{public static void main(string argv[]){ obparm o = new obparm(); o.amethod(); } public void amethod(){ int i = 99; valhold v = new valhold(); v.i=30; another(v,i); system.out.print( v.i ); }//end of amethod public void another(valhold v, int i){ i=0; v.i = 20; valhold vh = new valhold(); v = vh; system.out.print(v.i); system.out.print(i); }//end of another}
10020
class q6
101
holder h = new holder()
101
how many ports of tcp/ip are reserved for specific protocols?
1024
9. catch (ioexception e) { }
12
fileoutputstream fos = new fileoutputstream("dest")
12
how many bytes does the following code write to file dest?
12
how many bytes does the following code write to file dest? (choose one.)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
list<string> names = new arraylist<string>()
2.Iterator, for
vector <string> thevec = new vector<string>()
2.List...<String>(), dai nhat
sharedob.wait()
2.aThread.interrupt, sharedOb.notifyAll
date vaccinationdue
2.boolean, String
primitives are passed by reference
2.by value
how is illegalargumentexception used
2.certain methods, public methods
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
the code on line 33 executes successfully
3.33 throws, 35 throws, 33 executes
line 16 creates a directory named "d" and a file 'f' within it in the file system
3.An exception, Line 13, line 14
5. while (scanner.hasnext())5. 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?
5. 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?
select the correct statement about jdbc two-tier processing model
A user's commands
#what is an identifier?
A word used by a developer to name a variable, a method, a class, or a label.
#93.which are true about the container class?
A+B+D
14 }14.14. // insert code here14. }14. }14. }14. } and:14. } catch (numberformatexception nfe) {14. args[0] = "test";14. class triangle {14. for (int i: somearray) system.out.print(i +" ");14. fubar(14. hipri hp2 = new hipri();14. public abstract void draw();14. public static void main(string [] args) {14. public static void main(string [] args) {14. public static void main(string [] args) {14. 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?
A. Sometimes
2. // assume s is previously defined4. // in is an objectinputstream6. system.out.println("success");11. catch (streamcorruptedexception e) {15. system.out.println("general exception");18. system.out.println("doing finally part");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 all that apply.)
A. Success E. Doing finally partF. Carrying on
7. consider the following class hierarchy and code fragment:3. url u = new url(s); 5. object o = in.readobject();8. catch (malformedurlexception e) {12. system.out.println("bad file contents");14. catch (exception e) {15. system.out.println("general exception");18. system.out.println("doing finally part");what lines are output if the methods at lines 3 and 5 complete successfully without throwing any exceptions? (choose all that apply.)
A. SuccessE. Doing finally partF. Carrying on
given the following code, which of the results that follow would you expect? package mail; interface box { protected void open(); void close(); public void empty();
A. The code will not compile because of line 4.
given the following code, which of the results that follow would you expect?. package mail; 2.3. interface box {4. protected void open();5. void close();6. public void empty();
A. The code will not compile because of line 4.
interface box
A. The code will not compile because of line 4.
class nightingale extends abcde.bird
A. The program will compile and execute. The output will be Before: 0 After: 2.
there will be a compiler error, because class hallo does not correctly implement the runnable interface.this question concerns the following class definition: 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; }which statement is true about class bird and the following class nightingale? 3. class nightingale extends abcde.bird {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();
A. The program will compile and execute. The output will be Before: 0 After: 2.
10. consider the following code:1. public class assertification {2. public static void main(string[] args) {3. assert args.length == 0;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 all that apply.)
A. The source code must be compiled with the -source 1.5 flag.B. The application must be run with the -enableassertions flag or another assertion- enabling flag.D. The args array must have one or more elements.
20. what is the difference between the rules for method-call conversion and the rules for assignment conversion?
A. There is no difference; the rules are the same.
1. which one statement is true concerning the following code?1. class greebo extends java.util.vector4. system.out.println("in run() method: " +10. public static void main(string args[]) {13. thread t = new thread(g);14. t.start();
A. There will be a compiler error, because class Greebo does not correctly implement the Runnable interface.
15. which of the following restrictions apply to anonymous inner classes?
A. They must be defined inside a code block.
6. in the following code fragment, after execution of line 1, sbuf references an instance of thestringbuffer class. after execution of line 2, sbuf still references the same instance.1. stringbuffer sbuf = new stringbuffer("abcde");2. sbuf.insert(3, "xyz");
A. True
8. in the following code fragment, line 4 is executed.1. string s1 = "xyz";2. string s2 = "xyz";3. if (s1 == s2)4. system.out.println("line 4");
A. True
stringbuffer is slower than a stringbuilder, but a stringbuffer is threadsafe.
A. True
13. 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?
A. When the type of x is Object
suppose the declared type of x is a class, and the declared type of y is ansuppose the declared type of x is a class, and the declared type of y is an interface. when is the assignment x = y; legal?
A. When the type of x is Object
19. which of the following are true? (choose all that apply.)
A. When you declare a method to be synchronized, the method always synchronizes on the lock of the current objectD. 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.
10. 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);
A. Yes
6. if you attempt to compile and execute the following application, will it ever print out the message in xxx?1. class testthread3 extends thread {3. system.out.println("running");4. system.out.println("done");8. system.out.println("in xxx");12. testthread3 ttt = new testthread3();14. ttt.start();
A. Yes
# when accessing objects in an object stream, we must .......
Access them using a suitable program.
30.30. }30. class classc {30. for( int i=0; i<myobjects.length; i++) {30. this.ownername = ownername;30. suppose you are writing a class that provides custom deserialization. the class implements java.io.serializable (and not java.io.externalizable). what method should imple- ment the custom deserialization, and what is its access mode?
A. private readObject
suppose you are writing a class that provides custom deserialization. the class implements java.io.serializable (and not java.io.externalizable). what method should imple- ment the custom deserialization, and what is its access mode?
A. private readObject
1. consider this class:1. public class test1 {2. public float amethod(float a, float b) {3. } 4.which of the following methods would be legal if added (individually) at line 4? (choose all that apply.)
A. public int aMethod(int a, int b) { }C. public float aMethod(float a, float b, int c) throws Exception { }E. private float aMethod(int a, int b, int c) { }
19. 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?
A. public void doSomething(int a, float b) { ... }
11. 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.)
A. publicB. protected
16. 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.)
A. publicC. protectedD. Default
16. }catch (exception ex) {16. hp1.start();16. int y= 7;16. list list = new arraylist();16. pass p = new pass();16. 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.)
A. publicC. protectedD. Default
20. this question involves ioexception, awtexception, and eofexception. they are all checked exception types. ioexception and awtexception extend exception, and eofexception extends ioexception. suppose class x contains the following method:void dosomething() throws ioexception{ ... }which of the following methods may appear in class y, which extends x?
A. void doSomething() { ... }C. void doSomething() throws EOFException { ... }D. void doSomething() throws IOException, EOFException { ... }
11. which of the following may override a method whose signature is void xyz(float f)?
A. void xyz(float f)B. public void xyz(float f)
5. consider the following line of code: int[] x = new int[25];
A. x[24] is 0 E. x.length is 25
consider the following line of code: int[] x = new int[25]; after execution, which statements are true? (choose all that apply.)
A. x[24] is 0 E. x.length is 25
ad which of the following statements are true?
A.StringBuilderis generally faster than StringBuffer. D.StringBufferis threadsafe;StringBuilderis not.
2. sbuf.append("xyz");
A.True
2. sbuf.insert(3, "xyz");
A.True
4. public static void main(string[] a) {4. public static void main(string[] a) {4. public static void main(string[] a) {4. public static void main(string[] args) {4. rover = new dog();4. s1 = null;4. s1 = null;4. scanner.usedelimiter(delim);4. system.out.println("done");4. system.out.println("in run() method: " +4. system.out.println("line 4");
A.True
4. system.out.println("line 4");
A.True
a1[i].equals(a2[i])for every legal index i?
A.java.util.Arrays.equals(a1, a2);
#53.you can create a jtable using
ABCD
#60.what information may be obtained from a databasemetadata object?
ABCD
d.sc.usedelimiter("d+");d.sc.usedelimiter("d+");d.tailmapd.tailmapd.tailsetd.tailsetd.wrapped = 9;
ABCD
#56.the autoresizemode property specifies how columns are resized (you can resize table columns but not rows).
ABCDE
#58.the autoresizemode property specifies how columns are resized (you can resize table columns but not rows). possible values are:
ABCDE
what happens when you try to compile and run this application?what happens when you try to compile and run this application?what happens when you try to compile and run this application? (choose one.)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.
15. // insert code here15. // insert code here15. }15. }15. }15. }15. }15. }15. }
An exception is thrown at line 9.
public class xxx
An exception is thrown at line 9.
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 application?what happens when you try to compile and run the following application? (choose one.)
An exception is thrown at line 9.
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.
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.'
file file = new file(directory,"f");
An exception is thrown at runtime;File object named "d.";Line 14 creates a File object named "f.'
#select an incorrect statement about inner classes:
An inner class cannot be declared inside a method of the outer class.
objectstreamexception extends ioexception. notserializableexception extends objectstreamexception. awtexception does not extend any of these. all are checked exceptions. the callme() method throws notserializableexception.what does the following code print out? choose all lines that are printed.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.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.
19. which of the following may appear on the right-hand side of an instanceof operator? (choose all that apply.)
B. A classC. An interface
19.19. }19. }19. }19. }19. case harrier:19. system.out.print(obj + ",");19. system.out.println("nullpointerexception");19. system.out.println("passed");19. which of the following may appear on the right-hand side of an instanceof operator? (choose all that apply.)
B. A classC. An interface
2. scanner scanner = new scanner(scanme);2. sleep(100);2. string default_greeting = "hello world";2. string s2 = "xyz";2. string s2 = "xyz";2. string s2 = "xyz";2. string s2 = new string(s1);2. string s2 = new string(s1);2. string s2 = new string(s1);2. string t = new string(s);2. stringbuffer s1 = new stringbuffer("abcde");2. stringbuffer s1 = new stringbuffer("fpt");2. which of the following statements is true?
B. A final class may not have any abstract methods.
2. which of the following statements is true?
B. A final class may not have any abstract methods.
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. B must have a no-args constructor.
6. consider the following class hierarchy and code fragment:3. url u = new url(s);4. // in is an objectinputstream6. system.out.println("success");9. system.out.println("bad url");11. catch (streamcorruptedexception e) {12. system.out.println("bad file contents");18. system.out.println("doing finally part");what lines are output if the constructor at line 3 throws a malformedurlexception? (choose all that apply.)
B. Bad URLE. Doing finally partF. Carrying on
18. which of the following should always be caught?
B. Checked exceptions
class a:class animal { float weight; animal(float weight) {class animal
B. Class Zebra generates a compiler error
suppose a source file contains a large number of import statements. how do the imports affect the time required to compile the source file?
B. Compilation takes slightly more time
11. suppose a source file contains a large number of import statements. how do the imports affect the time required to compile the source file?
B. Compilation takes slightly more time.
15. dogs mydog = dogs.collie;15. f = 0;15. hipri hp3 = new hipri();15. int x = 5;15. int x= 5;15. public bootchy() {15. public static void main(string[] args) {15. public void setanchor(int x, int y) {15. system.out.println(args[0]);15. which of the following may follow the static keyword? (choose all that apply.)
B. DataC. MethodsD. Code blocks enclosed in curly brackets
15. which of the following may follow the static keyword? (choose all that apply.)
B. DataC. MethodsD. Code blocks enclosed in curly brackets
1. a signed data type has an equal number of non-zero positive and negative values available.
B. False
17. 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.
B. False
17. }17. case collie:17. hp2.start();17. list.add(" 1"); list.add("2"); list.add("3");17. p.dostuff(x);17. system.out.print("first ");17. system.out.println("exception");17. system.out.println(f);17. this.y = y;17. 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.
B. False
24.24. }24. new integer(12),24. public string ownername;24. return classc.getvalue();24. the following line of code is valid.int x = 9; byte b = x;
B. False
26.} and:27. a.method1();27. new boolean(true)27. string ownername,27. this.snootch = snootch;27. java arrays always start at index 1.
B. False
3. xyz() {3. 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.
B. False
9. in the following code fragment, line 4 is executed.1. string s1 = "xyz";2. string s2 = new string(s1);3. if (s1 == s2)4. system.out.println("line 4");
B. False
a signed data type has an equal number of non-zero positive and negative values available.
B. False
force garbage collection by calling system.gc().
B. False
the developer can force garbage collection by calling system.gc().
B. False
the following line of code is valid. int x = 9; byte b = x;
B. False
5. consider the following classes, declared in separate source files1. public class base 2. public void method(int i) {3. system.out.print("value is " + i);2. public void method(int j) {6. system.out.print("i was passed " + s);8. public static void main(string args[]) {9. base b1 = new base();11. b1.method(5);12. b2.method(6);what output results when the main method of the class sub is run?
C. Value is 5This value is 6
2. which one statement is always true about the following application?1. class hipri extends thread {3. setpriority(10);7. system.out.println(8. "another thread starting up.");9. while (true) { }13. hipri hp1 = new hipri();14. hipri hp2 = new hipri();16. hp1.start();18. hp3.start();
C. When the application is run, all three threads (hp1, hp2, and hp3) will execute concurrently, taking time-sliced turns in the CPU.
class hipri extends thread
C. When the application is run, all three threads (hp1, hp2, and hp3) will execute concurrently, taking time-sliced turns in the CPU.
given the following code, what keyword must be used at line 4 in order to stop execution of the for loop?
C. break
given the following code, what keyword must be used at line 4 in order to stop execution of the for loop? 1. boolean b = true;2. for (;;) {3. if (b) {4. <insert code>6. // do something
C. break
given the following code, what keyword must be used at line 4 in order to stop execution of the for loop? boolean b = true; for (;;) { if (b) {
C. break
18. which of the following are legal?
C. char c = '\u1234';
10. what is the range of values that can be assigned to a variable of type byte? \ d. -27 through 27 - 110. which of the following are legal enums?
C. enum Animals {LION, TIGER, BEAR; int weight;}E. enum Animals {LION(450), TIGER(450), BEAR; int weight;Animals() { } Animals(int w) {weight = w;}
13. public class sprite{13. public enum dogs {collie, harrier};13. public void testfoo() {13. return list.iterator();13. string snootch;13. suppose interface inty defines five methods. suppose class classy declares that it implements13. suppose interface inty defines five methods. suppose class classy declares that it implements13. system.out.println(tokens.length);13. ttt.xxx();13. theholder.held++;13. thread t = new thread(g);13. when a short is added to a float, what is the type of the result?
C. float
13. when a short is added to a float, what is the type of the result?
C. float
16. which of the following are methods of the java.util.sortedmap interface?
C. headMapD. tailMapE. subMap
12. when a byte is added to a char, what is the type of the result?
C. int
16. which of the following are legal? (choose all that apply.)
C. int c = 0xabcd;D. int d = 0XABCD;
3. which of the following are legal loop constructions? (choose all that apply.)
C. int j = 0;for (int k=0, j+k != 10; j++,k++) { System.out.println("j=" + j + ", k=" + k);}
4. 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 markingsgiven 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, up to 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
C. public class Cat extends Pet
after execution of the following code fragment, what are the values of the variables x, a, and b? int x, a = 6, b = 7; x = a++ + b++;
C. x = 13, a = 7, b = 8
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
e. sc.usedelimiter("\d+");e. sc.usedelimiter("\d+");e. submap
CDE
which of these class can be used to implement input stream that uses a character array as the source?
CharArrayReader
java.lang.string
Character String class is represented by?
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
#in a client-server application model, which sides will initiate a connection?
Client
in a class is the this method:in a class is the this method:in a class is the this method:in a class is the this method:in a client-server application model, which side will initialize a connection?
Client
in networking with client-server model, the client knows the hostname of the machine on which the server is running and the port number on which the server is listening.in networking with client-server model, the server computer has a socket that is bound to a specific port number. it does not need any information about client-computer for connection.in order for objects in a list to be sorted, those objects must implement which interface and method
Comparable...compareTo
in order for objects in a list to be sorted, those objects must implement which interface and method
Comparable...compareTo
public class mod{ public static void main(string argv[]){ } public static native void amethod(); }
Compilation and execution without error
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
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
a numberformatexception is thrown by the parse method at runtime
Compilation fails
nullpointerexception
Compilation fails
# 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
4. mymath.cos(0.123));
Compilation fails at line 2.
import java.lang.math;
Compilation fails at line 2.
given the following:given:given:given:given:given:given:given:given:given:given:given:given:given:given:given:given:given:given: 10. class main {11. static class a { 12. void process() throws exception { throw new exception(); } 13. } 14. static class b extends a { void process() { system.out.println("b "); }16. } public static void main(string[] args) { a a=new b(); . a.process(); what is the result when the above code is run?
Compilation fails because of an error in line 19.
23. }23. }23. }23. object [] myobjects = {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.
java.util.array.compare(a1,a2)java.util.array.sort(myobjects);
Compilation fails due to an error in line 29.
what happens when you try to compile and run this application? object [] myobjects = { 24. new integer(12), new string("foo"), new integer(5), new boolean(true) 29. java.util.array.sort(myobjects); 30. for( int i=0; i<myobjects.length; i++) { system.out.print(myobjects[i].tostring()); system.out.print(" ");
Compilation fails due to an error in line 29.
11. public void count(int i) {11. public void methoda() {11. raf.close();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.
11. public static class point { }11. public static iterator reverse(list list) {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.
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) {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";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.
system.out.println("i threw");system.out.println("nullpointerexception");
Compilation fails.
system.out.println(tokens.length);
Compilation fails.
} catch (interruptedexception e) {}} catch (interruptedexception e) {} system.out.println("all done");} catch (numberformatexception nfe) {
Compilation fails.
the thread that calls wait() goes into the monitor's pool of waiting threads.the value of all four objects prints in natural order
Compilation fails...line 29
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?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.
class someexception: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.
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
56. int y[] =x;57. system.out.println(y[2]);6.6. {6. }6. }6. }6. class sub extends superduper6. dataoutputstream dos = new6. dos.close();6. dos.close();6. fido = (dog)anim;6. file f = new file("xxx.ser");6. public string doit(int... vals) {6. public void run() {6. raf.seek(10);6. s = null;
Compilation succeeds. No exception is thrown during execution.
6. s = null;
Compilation succeeds. No exception is thrown during execution.
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
private class base{} public class vis{ transient int ival; public static void main(string elephant[]){ } }
Compile time error: Base cannot be private
flowlayout is the default layout manager for every jpanel. borderlayout is the default layout manager for every jframe.focusevent is subclass of which of these classes?
ComponentEvent
interface:interface:interface____helps manage the connection between a java program and a database.
Connection
#the correct order in which database -accessing objects should be created:
Connection - Statement- ResultSet - ResultSetMetaData
#81.to connect to a local mysql database named test, use
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test");
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:
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.
nested inside a class declaration are three kinds of declarations. what are they?
Constructor declarations
#86.what are the immediate super classes of the following classes?
Container class
which of these events is generated when the component is added or removed?
ContainerEvent
2. 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) {6. system.out.println("i = " + i + " j = " + j);which lines would be part of the output? (choose all that apply.)
D. i = 1 j = 0
23. private integer limit;23. public string getvalue() {23. which class provides locale-sensitive text formatting for date and time information?
D. java.text.DateFormat
7. 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 line3and be placed before amethod() on line 8?1. class superduper2. {3. void amethod() { }4. } 5.6. class sub extends superduper7. {8. void amethod() { }9. }
D. line 3: private; line 8: protectedWhich statement is true about class Bird and the following class Nightingale?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. }|A. The program will compile and execute. The output will be Before: 0 After: 2.
7. {7. }7. } 8.7. 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;c. line 67. 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;c. line 67. dataoutputstream(bos);7. fileoutputstream fos = new fileoutputstream(f);7. fos.close();7. fos.close();7. 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 line3and be placed before amethod() on line 8?1. class superduper2. {3. void amethod() { }4. } 5.6. class sub extends superduper7. {8. void amethod() { }9. }
D. line 3: private; line 8: protectedWhich statement is true about class Bird and the following class Nightingale?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. }|A. The program will compile and execute. The output will be Before: 0 After: 2.
4. 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");10. else if (z > 5) {11. system.out.println("message three");14. system.out.println("message four");
D. message four
8. raf.close()8. set.add(new apple());8. set.add(new apple());8. set.add(new apple());8. system.out.println("in xxx");8. void amethod() { }8. 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.)
D. transient
8. 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.)
D. transient
#70.are known as intra-relational constraints, meaning that a constraint involves only one relation
DOMAIN + PRIMARY KEY CONTRAINST
# in jtree control, which of the following classes represents for one node?
DefaultMutableTreeNode
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
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
variable declarationsvariable declarationsvariable 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
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
#74.specify the permissible values for an attribute.
Domain constraints
64 bit decimal value - do not use for precise values
Double
the wrapper class for the primitive type double is ____________________.
Double
class in the primary class that has the driver information
DriverManager
class is the primary class that has the driver information
DriverManager
object is uses to obtain a connection to a database
DriverManager
the class is the primary class that has the driver information.
DriverManager
a(n) object is uses to obtain a connection to a database
Drivermanager
# which of the following statements is correct about thread?
During its lifetime, a thread spends some time executing and some time in any of non-executing states
5. which statement is true about this application? class staticstuff { static int x = 10; static { x += 5; } public static void main(string args[]) { system.out.println("x = " + x); } static {x /= 5; } }
E. The code compiles and execution produces the output x = 3.
5. which statement is true about this application?. class staticstuffstatic int x = 10; 4.5. static { x += 5; } 6.7. public static void main(string args[])9. system.out.println("x = " + x);12. static {x /= 5; }
E. The code compiles and execution produces the output x = 3.
5. which statement is true about this application?1. classstaticstuff2 {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. }
E. The code compiles and execution produces theoutput x = 3.
9. system.out.println("x = " + x);9. while (true) { }9. consider the following code: 1. cat sunflower;5. sunflower = new cat();7. pogo = (swampthing)wawa;
E. The code will compile but will throw an exception at line 7, because the runtime class of wawa cannot be converted to type SwampThing.
6. which statement is true about this code? class hasstatic { private static int x = 100; public static void main(string args[]) { hasstatic hs1 = new hasstatic(); hs1.x++; hasstatic hs2 = new hasstatic(); hs2.x++; hs1 = new hasstatic(); hs1.x++; hasstatic.x++; system.out.println("x = " + x); } }
E. The program compiles and the output is x = 104.
6. which statement is true about this code?1. class hasstatic3. private static int x = 100; 4.7. hasstatic hs1 = new hasstatic();9. hasstatic hs2 = new hasstatic();hs1 = new hasstatic();system.out.println("x = " + x);
E. The program compiles and the output is x = 104.
6. set.add(new apple());6. set.add(new apple());6. set.add(new apple());6. system.out.println(h.held);6. system.out.println(scanner.next());6. which statement is true about this code?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. }
E. The program compiles and the output isx=104.
6. which statement is true about this code?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. }
E. The program compiles and the output isx=104.
4. which of the following statements is true?
E. Transient variables are not serialized.
34. }34. value = "classb";35. }35. return value;36. }37.}4.4.4. ??? // what goes here?4. }4. }4. }4. }4. } 5.4. b.method2();4. bufferedoutputstream bos = new4. c.method3();4. dos.writeint(3);4. dos.writeint(3);4. fos.close();4. h.held = 100;4. 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;
E. int, long,float, double
4. 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;
E. int, long,float, double
abstract class can contain methods with declared bodies.
E. public, protected, default, private
public class money
Euro returns correct Country value. - Compilation fails because of an error at line 25
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.
????????????____ are generated when the user presses a key, clicks a button, or selects a menu item.
Events.
object ob2= new object()
Have a nice day
#two streams are packed in a socket are .........
InputStream and OutputStream
# select incorrect statement about flowlayout. (choose 1)
It is the default layout manager type for JFrame.
how is illegalargumentexception used? (choose all correct options.)
It is thrown by certain methods - It should be used by programmers to indicate that preconditions of public
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
string s2 = "xyz"
Line 4, Line 6
25. }25. a a=new a();25. new string("foo"),25. public bootchy(int bootch, string snootch) {25. try {26. a a=new a();26. new integer(5),26. public void setcardlnformation(string cardld,26. system.out.println(a.doit(4, 5));26. system.out.println(a.doit(4, 5));
Line 26 prints "a" to System.out.
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 tester {public class testexception extends exception
Line 46 will compile if the enclosing - Line 46 will compile if enclosed.
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.
s2=s2.intern();
Line 4;Line 6
string s2 = "xyz";string s2 = "xyz";
Line 4;Line 6
55. int []x= {1, 2,3,4, 5};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.
int []x= {1, 2,3,4, 5};
Line 57 will print the value 3.
compilation succeeds. no exception is thrown during execution.compilation will fail because of an error in line 55
Line 57...value 3
compilation will fail because of an error in line 55
Line 57...value 3
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
float floater = new float(3.14f)
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
string s1 = "xyz";
Line 6
string s2 = new string("xyz")
Line 6
string s2 = new string("xyz");string s2 = new string("xyz");
Line 6
string s2 = new string(s1)
Line 6
line 4 executes and line 6 does not
Line 6 executes
# which one statement is true about the following code? 6. system.out.println(".equals() succeeded"); 4. system.out.println("== succeeded");
Line 6 executes and line 4 does not.
system.out.println(".equals() succeeded");
Line 6 executes and line 4 does not.
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
a new directory called dirname and a new file called filename are created, both in the current working directory
No directory
1. file f1 = new file("dirname");1. file f1 = new file("dirname");
No directory is created, and no file is created.
2.2.2.2. {2. {2. }2. animal anim;2. file f2 = new file(f1, "filename");
No directory is created, and no file is created.
byte b = 2; byte b1 = 3; b = b * b1;byte b = 2; byte b1 = 3; b = b * b1;
No output because of compile error at line: b = b * b1;
public class test{public class test{public class test{public class test{public class test{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 mine
No such file found, doing finally; -1
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
# all of the numeric wrapper classes are subclasses of the abstract class ______
Number
... public interface operatecar {... public interface operatecar {... public interface operatecar {... public interface operatecar {// an enum with values right, left// an enum with values right, left// an enum with values right, left// an enum with values right, left// constant declarations, if any// constant declarations, if any// constant declarations, if any// constant declarations, if any// method signatures// method signatures// method signatures// method signatures// now what are n and w.x?//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
three top-level elements occur in a source file, they must appear
Package declaration, imports, class/interface/enum definitions
#if all three top-level elements occur in a source file, they must appear in which order?
Package declaration, imports, class/interface/enum definitions.
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.
#select a correct template of a java source file
Package mypkg; import java.lang class A {}
a method is allowed to have _______, which represent data that will be supplied when the method is called.
Parameters
variables that define ex: args
Parameters
#which of the following statements is correct about overridding methods?
Quet dap an
11.11. fos.close();11. hs1 = new hasstatic();11. public abstract class shape {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();
catch (ioexception x) { system.out.println("io");catch (objectstreamexception x) { system.out.println("object stream");cde which of the following are methods of the java.util.sortedmapinterface?cde which of the following are methods of the java.util.sortedmapinterface?circle c = new circle(); c.shape.setanchor(10,10); c.shape.draw()
Shape s = new Circle...s.draw()
circle c = new circle(); c.shape.setanchor(10,10); c.shape.draw()
Shape s = new Circle...s.draw()
integer with min value of -32,768 and max value of +32,767(inclusive) 16 bit (for memory saving)
Short
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
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.
a class that represents the most general entity in an inheritance hierarchy is called a/an ____.
Superclass.
# if an object may be accessed by some threads. these accesses should be done through ____ methods
Synchronized
#suppose that the class a contains an inner class, named b. in a method of a, to access data of a b object,
The B object must be referred by a reference declared in A.
# which of the following statements is correct about flow layout?
The Flow layout arranges frames in horizontal rows.
select incorrect statement about flowlayout
The Flow layout manager always honors a component's preferred size D The Flow layout manager arranges components in horizontal rows
#what is the role of rmi registry?
The RMI registry is a program that associates names with RMI services
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
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 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 is/are true?
The class will compile if it is declared abstract.- The class may not be instantiated.
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?
The class will compile if it is declared abstract;The class may not be instantiated.
13.13. }13. }
The code compiles and execution produces the output x = 3.
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
interface collection <e>interface foo
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. hs2.x++;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.
public class q
The code compiles, and prints out >>null<<
what happens when you try to compile and run the following code?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<<
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.
c which line of code tells a scanner called scto use a single digit as a delimiter?c which line of code tells a scanner called scto use a single digit as a delimiter?c. headmapc. headmapc. headsetc. headsetc. prim = new integer(9);c. prim = new integer(9);c. sc.usedelimiter("\\d");c. sc.usedelimiter("\\d");c? (choose two.)
The code on line 29 will be executed.vsThe exception will be propagated back to line 27.
(new thread(new myrunnable()))
The code prints "Going to sleep," then "Waking up," and then "All done."
1)an abstract class may not have any final methods.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.
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.
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.
consider the following class:class cruncher {void crunch(int i) {system.out.println("int version");}void crunch(string s) {system.out.println("string version");} 8.public static void main(string args[]) {cruncher crun = new cruncher();char ch = 'p';crun.crunch(ch);}}
The code will compile and produce the following output: int version.
consider the following code: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
the code prints "going to sleep," then "waking up," and then "all done."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
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
1. class staticstuff1. class testthread3 extends thread {1. class xyz {1. dog rover, fido;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.
ab . given the following,ab . given the following,abcd suppose primis an intand wrappedis an integer. which of the following are legal javaabcd suppose primis an intand wrappedis an integer. which of the following are legal javaabcde which of the following are methods of the java.util.sortedsetinterface?abcde which of the following are methods of the java.util.sortedsetinterface?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 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
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
# in which situation are generic collections used?
The collection contains homogenous elements.
#if a java source code contains an assert as an identifier and it will be compiled with jdk version 1.4 or higher, ....
The option "-source 1.4" must be specified when it is compiled.
9. class greebotest {9. 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;9. 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;9. dos.close();9. hasstatic hs2 = new hasstatic();9. oos.writeobject(new object());9. system.out.println("i = " + i);
The output is i = 20.
fileoutputstream fos = new fileoutputstream("xx");
The output is i = 20.
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 fragment print out at line 9? (choose one.)what does the following code fragment print out at line 9? (choose one.)
The output is i = 20.
public class xor
The output: b contains 5.
public class conditional
The output: value is 9.0
system.out.println("value is " + ((x > 4) ? 99.99 : 9));
The output: value is 9.0
the setcardlnformation method breaks encapsulation
The ownerName
20. class classb {20. classa a = new classa();20. public bootchy(string snootch) {20. public class creditcard {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.
public void setcardlnformation(string cardld,string ownername,integer limit)
The ownerName variable breaks encapsulation.
1. import java.io.*; 2.1. import java.lang.math;1. import java.util.*;1. import java.util.*;1. import java.util.*;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.
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.
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
what happens when you try to compile and run the following program? import java.util.*;public class main{treeset<integer> t = new treeset<integer>();t.add(12);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: 18
compilation of class b will fail. compilation of class a will succeedcompilation 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
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
#runtime exception
The right time to deal with runtime exceptions is when you're designing, developing, and debugging your code. Since runtime exceptions should never be thrown in finished code
#suppose you are building a client - server based application using tcp socket technique. assume at the same time, 5 clients are connecting to the server, and then the server needs to send data to the client number 2. how can the server make sure that it sends the data exactly to the 2nd client, rather than mistakenly to other clients?
The server creates a separate InputStream and OutputStream objects for each one. Then, the server uses these two objects to send and receive data to and from the specific client.
#consider the following declaration: int 3_my_var = 0x1c; select a correct statement:
The statement is incorrect because a variable declaration cannot start with a number.
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
The strategy fails because you cannot add static methods to a subclass.
static int x;static methods. which one statement is true about this strategy?
The strategy fails because you cannot subclass java.lang.Math.
static methods. which one statement is true about this strategy?
The strategy fails because you cannot subclass java.lang.Math.
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 FULL - The locale
#84.a text field has a variable-width font. it is constructed by calling new textfield("iiiii"). what happens if you change the contents of the text field to "wwwww"? (bear in mind that i is one of the narrowest characters, and w is one of the widest.)
The text field stays the same width; to see the entire contents you will have to scroll by using the ß and à keys.
#study the following java code: int [] a= { 1, 2, 3, 4, 5 }; select the best choice.
The variable a is a reference to a memory location that stores values.
2. fileoutputstream fos = newfileoutputstream("dest");2. fileoutputstream fos = newfileoutputstream("dest");2. float f;2. for (byte b=10; b<50; b++)2. hipri() {2. implements runnable {2. math mymath = new math();2. public static void main(string args[]) {2. public string doit(int x, int y) {2. public void dosomething() { }2. public void dosomething() throws someexception { }2. public void method1() {2. public void method2() {2. public void method3() {2. public void run() {2. randomaccessfile raf = new2. sbuf.append("-university");
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
jdbc is the java-based api, which provides a set of classes and interfaces written in java to access and manipulate different kinds of databases.jdbc is a java database system. jdbc is a java api for connecting to any kind of dbmsjdbc supports ______ and ______ models
Two-tier and three-tier
jdbc supports ______ and ______ models
Two-tier and three-tier
______________ 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
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
drivers that implement the jdbc api as a mapping to another data access api, such as odbc. drivers of this type are generally ependent on a native library, which limits their portability.
Type 1
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 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
#in jdbc model, which driver types provide access to database through native code libraries c/c++?
Type 2-driver
select incorrect statement about deserialize
We use readObject
select incorrect statement about deserialize (choose 1)
We use readObjectO method of ObjectOutputStream dass to deserialize
#82.result set meta data are retrieved through ________
a ResultSet Object
(4928) which is the four steps are used in working with jdbc?
a. 1)Connect to the database 2)Create a statement and execute the query3)Look at the result set4)Close connection
(188) which of the following are true? (choose two.)
a. An anonymous inner class may implement at most one interface.c. An anonymous inner class may extend a parent class other than Object.
(215) 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));
a. Compilation fails at line 2.
(176) which of the following statements are true? (choose one.)
a. Given that Inner is a nonstatic class declared inside a public class Outerand that appropriate constructor forms are defined, an instance of Inner can be constructed like this: new Outer().new Inner()
(302) which is four-step approach to help you organize your gui thinking.(choose one.)
a. Identify needed components. Isolate regions of behavior. Sketch the GUI.Choose layout managers.
int selfxor(int i) {return i ^ i;}
a. It always returns 0.
(70) which of the following expressions are legal? (choose two.)
a. String x = "Hello"; int y = 9; x += y;c. String x = "Hello"; int y = 9; x = x + y;
(232) which of the following statements are true? (choose two.)
a. StringBuilder is generally faster than StringBuffer.d. StringBuffer is threadsafe; StringBuilder is not.
(242) 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 = new3. randomaccessfile("datafile" ,"rw");4.bufferedoutputstream bos = newbufferedoutputstream(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) { }
a. The code fails to compile.
(146) what is the difference between the rules for method-call conversion andthe rules for assignment conversion? (choose one.)
a. There is no difference; the rules are the same.
(192) which one statement is true concerning the following code1. 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. }
a. There will be a compiler error, because class Greebo does not correctlyimplement the Runnable interface.
(165) when does an exception's stack trace get recorded in the exception object? (choose one.)
a. When the exception is constructed
(210) which of the following are true? (choose two.)
a. When you declare a method to be synchronized, the method alwayssynchronizes on the lock of the current object.d. When you declare a block of code inside a method to be synchronized, youcan specify the object on whose lock the block should synchronize.
(162) which of the following are legal argument types for a switch statement?(choose three.)
a. byteb. inte. char
(63) which of the following are legal? (choose two.)
a. char c = 0x1234;c. char c = '\u1234';
(177) which of the following are legal enums? (choose three.)
a. enum Animals { LION, TIGER, BEAR }c. enum Animals {LION, TIGER, BEAR;int weight;}e. enum Animals {LION(450), TIGER(450), BEAR;int weight; Animals() { } Animals(int w) {weight = w; }}
(159) which of the following are legal? (choose three.)
a. for (int i=0, j=1; i<10; i++, j++)b. for (int i=0, j=1;; i++, j++)d. for (String s = ""; s.length()<10; s += '!')
(57) which of the following are legal import statements? (choose two.)
a. import java.util.Vector;c. import static java.util.Vector.*;
(4930) url referring to databases use the form:
a. protocol:subprotocol:datasoursename
(1423) which two code fragments correctly create and initialize a static array ofint elements? (choose two.)
a. static final int[] a = { 100,200 };b. static final int[] a; static { a=new int[2]; a[0]=100;a[1]=200; }
(199) which of the following methods in the thread class are deprecated?(choose one.)
a. suspend() and resume()
(313) whenever a method does not want to handle exceptions using the try block, the is used.
a. throws
(7256) which jdbc processing model that requires a jdbc driver that can communicate with the particular data source beingaccessed?
a. two-tier
(191) this question involves ioexception, awtexception, and eofexception.they are all checked exception types. ioexception and awtexception extend exception, and eofexception extends oexception.suppose 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.)
a. void doSomething() { ... }c. void doSomething() throws EOFException { ... }d. void doSomething() throws IOException, EOFException { ... }
(186) which of the following may override a method whose signature is voidxyz(float f)? (choose two.)
a. voidxyz(float f)b. public void xyz(float f)
(308) when the user attempts to close the frame window, event ingenerated.
a. window closing
indicates a value that is either true or false
boolean
if(check4biz(storenum)!= null){}
boolean - String
"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 neutered; - String markings;
may appear on the right-hand side of an instanceof operator
class and interface
b in the following code fragment, line 4 is executed.b in the following code fragment, line 4 is executed.b. lastb. lastb. lastb. lastb. sc.usedelimiter("\d");b. sc.usedelimiter("\d");b. wrapped = prim;b. wrapped = prim;b=m;
class base{}
which of the following is correct way of implementing an interface salary by class manager?
class manager implements salary {}
the thread that calls wait() goes into the monitor's pool of waiting threads.
classes
interfaces cannot be instantiated—they can only be implemented by _____ or extended by ______.
classes, interfaces
#in a client-server application model, which side will initialize a connection?
client
which of these method of object class can generate duplicate copy of the object on which it is called?
clone()
12. public class test {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
(151) 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. }
d. The output would be the text value is two followed by the text value is
(1411) which man class properly represents the relationship "man has the bestfriend who is a dog"? (choose one.)
d. class Man { private Dog bestFriend; }
(111) 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. }e. the code compiles and execution produces the output x = 3.(111) 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. }e. the code compiles and execution produces the output x = 3.(114) which modifier or modifiers should be used to denote a variable thatshould not be written out as part of its class's persistent state? (choose the shortest possible answer.)
d. transient
(114) which modifier or modifiers should be used to denote a variable thatshould not be written out as part of its class's persistent state? (choose the shortest possible answer.)
d. transient
the application must be run with the -enableassertions flag or another assertionenabling flag
dai nhat, one or more
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 parrot.java fails at line 7 because method getrefcount() is static in the superclass, and static methods may not be overridden to be nonstatic.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
and the rules governing these conversions are identical
dap an
both primitives and object references can be both converted and cast
dap an
both primitives and object references can be both converted and cast.both primitives and object references can be both converted and cast.both primitives and object references can be both converted and cast
dap an
ch12: this is a section of code that gracefully responds to exceptions.
exception handler
#with respect to the java.sql.statement interface,(1) when we need retrieving data from a table of a database, the method...... of the statement interface should be used.(2) when we need update data in a table of a database, the method...... of the statement interface should be used.
executeQuery(...), executeUpdate(...)
#when you want to delete some rows in a table of a database, the ...... method of the java.sql.statement interface must be used.
executeUpdate()
#you are going to execute an insert statement to add some data into the database. which of the following methods should you use?
executeUpdate()
# you are building a table model class that extends the abstracttablemodel class. which of the following methods is not required to re-implement?
getColumnName()
ch12: this method can be used to retrieve the error message from an exception object.
getMessage
given the following class:given the following class:given the following class: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 class: public class xyz implements java.io.serializable {
iAmPublic, iAmPrivate
given the following class: public class xyz implements java.io.serializable { public int iampublic ; private int iamprivate ; static int iamstatic ; transient int iamtransient ; } assuming the class does not perform custom serialization, which fields are written when an instance of xyz is serialized?
iAmPublic, iAmPrivate
tests to see whether a condition is true
if
e which one statement is true about the following code fragment?
if (s1.equals(s))
3.3. // more code here3. }3. }3. } catch (interruptedexception e) { }3. b b=new b();3. c c=new c();3. dataoutputstream dos = new dataoutputstream(fos);3. dataoutputstream dos = new dataoutputstream(fos);3. fos.write(b);3. holder h = new holder();3. if (s.equals(s1))3. if (s.equals(s1))3. if (s1 == s2)3. if (s1 == s2)3. if (s1 == s2)3. if (s1 == s2)3. if (s1 == s2)3. if (s1 == s2)3. private static int x = 100;3. public class apple {3. public class apple {3. public class apple {3. public class xxx {3. public void method1();3. public void run(string message) {3. randomaccessfile("datafile" ,"rw");3. return "a";3. setpriority(10);3. static int x = 10;3. string delim = ?????; // what goes here?3. system.out.println("cosine of 0.123 = " +3. system.out.println("running");3. t += "zzz";3. void amethod() { }3. which of the following expressions results in a positive value in x?
int x = -1; x = x >>> 5;
#int x= -7, y=3; int result= x%y;
int x=0A;
in the following code fragment, line 4 is executed.in the following code fragment, line 4 is executed.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
in the following code, what are the possible types for variable result? (select the most correct answer) 1. byte b = 11;2. short s = 13;3. result = b * ++s;
int, long, float, double
in the following code, what are the possible types for variable result? byte b = 11;short s = 13;result = b * ++s;
int, long, float, double
result = b * ++s;
int, long, float, double
what are the possible types for variable result
int, long, float, double
#a reference variable can not be
integral value
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
introduces a class that contains method stubs that describe how it should be implemented.
interface
7.}7.}8. "another thread starting up.");8. {8. }8. }8. }8. }8. }8. consider the following code:1. dog rover, fido;2. animal anim; 3.4. rover = new dog();5. anim = rover;6. fido = (dog)anim;which of the following statements is true? (choose one.)d. the code will compile and run.8. consider the following code:1. dog rover, fido;2. animal anim; 3.4. rover = new dog();5. anim = rover;6. fido = (dog)anim;which of the following statements is true? (choose one.)d. the code will compile and run.8. dos.writedouble(math.pi);8. hs1.x++;8. objectoutputstream oos = new objectoutputstream(fos);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
# which of the following layout manager will present components with the same size.
java.awt.GridLayout
suppose 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? (choose all correct options.)
java.io.Externalizable, it must have a no-args - java.io.Serializable and does not implement
# the ....... class makes utilities to write platform-independent code that examines and manipulates folders.
java.io.File
# when we access a file or directory metadata such as name, path, last modified time,... we should use the ........... class.
java.io.File
# the java.io.objectinputstream class is a subclass of the ...class.
java.io.InputStream
# you are required to validate an email string taken from users. a valid email form should be [email protected].# you are required to write a program that stores data retrieved from users to a text file. the data must be stored line by line and in unicode format. which of the following classes is the best choice for storing tasks?
java.io.PrintWriter
# two topmost abstract classes for character streams are ...... and .......
java.io.Reader, java.io.Writer
# in order to allow an object can be serialized into a file, which of the following interfaces needs to be implemented?
java.io.Serializable
# to read/write objects from/to a file as object streams, the class declaration of these objects must implement the marker interface .....
java.io.Serializable
what interfaces can be implemented in order to create a class that can be serialized? (choose all that apply.)
java.io.Serializable. There are no methods - java.io.Externalizable, which defines two methods: readExternal
which of these packages contain all the java's built in exceptions?
java.lang
# in order to use the treeset class, the class that describes elements must implement the ... interface
java.lang.Comparable
# all of the numeric wrapper classes in the java.lang package are subclasses of the abstract class ..
java.lang.Number
which of these package contains classes and interfaces for networking?
java.net
#29.when creating a server on a port that is already in use,the server encounters a fatal error and must be terminated.
java.net.BindException occurs.
which of these package is used for invoking a method remotely?
java.rmi
#you are building an rmi application. which of the following interfaces you must extend for your remote interface?
java.rmi.Remote
#in rmi implementations, all methods, declared in the remote interface, must throw the ...exception
java.rmi.RemoteException
which of these package is used for all the text related modifications?
java.text
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
a dialog prevents user input to other windows in the application until the dialog is closed
modal
mvc is short call of
model-view-controller
which of these methods is defined in mousemotionadapter class?
mouseDragged()
ch13: this is the jlist component's default selection mode.
multiple interval selection mode
#in a subclass, a calling to a constructor of superclass
must be the first line in a constructor of the subclass.
logit("log message 1 ");logit("log message2","log message3");logit("log message4", "log message5", "log message6");main() method?
n is 10, w.x is 11
given the following classes which of the following will compile without error?interface iface{}class cface implements iface{}class base{}public class obref extends base{ public static void main(string argv[]){ obref ob = new obref(); base b = new base(); object o1 = new object(); iface o2 = new cface(); }}
o1=o2;b=ob;o1=b;
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!
#suppose that a, b, c are classes in which b is a subclass of a. study the following declarations: a obja;
objA=objB;
a section of memory that contains both variables (state information) and methods (small programs)
object
#24.which of the following expressions must be true if you create a thread using thread = new thread(object)?
object instanceof Runnable
give: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()
the declaration of the java.util.collection interface is interface collection <e> 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)
"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
public class Cat extends Pet
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()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
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
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 programmer needs to create a logging method that can accept an arbitrary number of arguments. for example, it may be called in thesea programmer needs to create a logging method that can accept an arbitrary number of arguments. for example, it may be called in these
public void logIt(String... msgs)
#which of the following may override a method whose signature is void xyz(float f)?
public void xyz(float f)
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?
public, protected
select the order of access modifiers from least restrictive to most restrictive
public, protected, default, private
catch (exception e) { system.out.print("exception "); }catch (exception x) { system.out.println("exception");catch (interruptedexception e)
running some time
#in windows systems, the ...... program helps creating the stub of a rmi server and the ...... program will work as a rmi container (rmi registry)
rmic.exe, rmiregistry.exe
#1.which of these method is used to implement runnable interface?
run
a(n) object is used to submit a query to a database
statement
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
indicates that a variable or method belongs to a class rather than any object created from a class
static
which of these is used to access member of class before object of that class is created?
static
#the protected modifier cannot be applied to which of the following declarations?
static class A { }
# which of the following methods in the thread class are deprecated? (choose one)
suspend() and resume()
methods in the thread class are deprecated
suspend() and resume()
tells the computer to follow one of many possible paths of execution
switch
keeps two threads from interfering with one another
synchronized
which of these keywords are used to implement synchronization ?
synchronized
class inout
system.out.println(iArgs); - System.out.println(s);
# a high-level filter input stream reads bytes from a low-level input stream, or from another filter input stream, and returns general-format data to its caller
t
# a low-level output stream receives bytes and writes bytes to an output device
t
#a class that is declared final cannot be subclassed
t
#a high-level filter output stream receives general-format data, such as primitives, and writes bytes to a low-level output stream or to another filter output stream
t
#a package is a grouping of related classes, interfaces, enumerations, and annotation types providing access protection and name space management
t
#a reader is similar to a filter input stream but is specialized for reading utf strings in units of unicode characters
t
#a writer is similar to a filter output stream but is specialized for writing java strings in units of unicode characters
t
#abstract classes cannot be instantiated
t
public static void main(string [] args) { new threadtest().newthread();public static void main(string[] args) {public static void main(string[] args) { a that1 = new a();public static void main(string[] args) { animal a = new animal(222.2f);public static void main(string[] args) { int n = 10;public static void main(string[] args) { system.out.println(">>" + s + "<<");public static void main(string[] args){public static void main(string[] args){ object ob1= new object();public static void main(string[] args){ object ob1= new object(); object ob2= ob1;public static void main(string[] args){ string s1 = "xyz";public static void main(string[] args){ string s1 = "xyz";public static void main
the program will run and output only "fliton"
a mehtod that returns the contents of an object as a string should be named ______.
toString
11. public class bootchy {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
first second first third snootchy 420
third second first snootchy 420
public class bootchy
third second first snootchy 420
refers to the object in which the word this appears
this
creates a new exception object and indicates that an an exception situation has occurred
throw
which of these keywords is used to manually throw an exception?
throw
appropriate to pass a cause to an exception's constructor
thrown in response to catching of a different exception type
indicates that a method or constructor may cause an exception to occur
throws
ch12: this informs the compiler of the exceptions that could get thrown from a method.
throws clause`
# you are assigned a job that you need to buy a lock to replace the old one in your company. a lock-set includes 2 components: a lock and a key. each key can only fit one lock.
tight coupling
#73.to execute a select statement "select * from address" on a statement object stmt, use
tmt.executeQuery("select * from Address");
ch13: this is text that appears in a small box when the user holds the mouse cursor over a component.
tool tip
#which modifiers on instance variables will announce to the compiler that these variables are not stored as part of its object's persistent state.
transient
denote a variable that should not be written out as part of its class's persistent state
transient
indicates that, if and when an object is serialized, a variable's value doesn't need to be stored
transient
the jdbc api supports
two-tier and three-tier processing models for database access.
#you are required to build an application that can connect to database to display data to end users. the requirement for the database connectivity is that it must provide a performance as fast as possible.
type 2
the output: value is 99.99
value is 9.0
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
what is the value returned by function compareto() if the invoking string is less than the string compared?
value less than zero
ch13: a list selection listener must have this method.
valueChanged
throws clonenotsupportedexception { return (q13)super.clone(); }throws clonenotsupportedexception { return (q13)super.clone(); }throws clonenotsupportedexception { return super.clone(); } d.public q13 clone()throws clonenotsupportedexception { return super.clone(); } d.public q13 clone()transient methods may not be overridden
variables are not
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 ioexception. suppose class x contains the following method: void dosomething() throws ioexception{ ... }
void doSomething() { ... } - void doSomething() throws EOFException { ... } - void doSomething() throws IOException, EOFException { ... }
c (choose three.)
void doSomething() { ... } void doSomething() throws EOFException { ... } void doSomething() throws IOException, EOFException { ... }
suppose class x contains the following method:
void doSomething(int a, float b){ ... }
#which of the following modifiers makes a variable can be modified asynchronously?
volatile
imposes strict rules on the use of a variable by more than one thread at a time
volatile
which of these formatting strings of simpledateformat class is used to print week of the year?
w
# which of the following methods causes a thread to release the lock of the object that it is currently holding
wait()
# which method is not a member the object class?
waitAll(
# when reading objects from an object stream,
we usually use an explicit casting.
int[] x = new int[25]; after execution, which statements are true? (choose two.)
x[24] is 0 x.length is 25
after execution, which statements are true? (choose two.)
x[24] is 0vsx.length is 25