JAVA Need any/all the help I can get.Thank you!! 1. What is list after the follo
ID: 3580376 • Letter: J
Question
JAVA
Need any/all the help I can get.Thank you!!
1. What is list after the following code is executed?
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
list.remove(2);
System.out.println(list);
Answer:
[1, 2, 3, 4, 5]
[2, 3, 4, 5]
[1, 3, 4, 5]
[1, 2, 4, 5]
[1, 2, 3, 4]
2. If no locale is explicitly supplied for user messages, the system uses messages associated with the system's default locale.
Answer:
True
False
3. What is the output of the following?
String j = "jack";
String so = "sophie";
String jso = "jack" + "sophie";
String b = j + so;
System.out.print("x");
if (b != jso) System.out.print("1");
Answer:
4. Which of the following statements are true?
A condition is associated with a lock.
To invoke methods on a condition, the lock must be obtained first.
Once you invoke the await method on a condition, the lock is automatically released. Once the condition is right, the thread re-acquires the lock and continues executing.
The signal method on a condition causes the lock for the condition to be released.
Answer(s):
5. How do you create a condition on a lock?
Answer:
Condition condition = lock.getCondition();
Condition condition = lock.newCondition();
Condition condition = Lock.newCondition();
Condition condition = Lock.getCondition();
6. Which lambda expression represents a function that, given the length and width of a wall, calculates the wall's area?
Answer:
l, w -> l * w
l, w -> calc(l, w)
(l, w) -> 2*l + 2*w
(l, w) -> l * w
7. What does the following code do?
FileInputStream fis = new FileInputStream("test.dat");
Answer:
It creates a new file named test.dat if it does not exist and opens the file so you can write to it.
It creates a new file named test.dat if it does not exist and opens the file so you can write to it and read from it.
It creates a new file named test.dat regardless of whether it exists or not and opens the file so you can write to it.
It creates a new file named test.dat regardless of whether it exists or not and opens the file so you can write to it and read from it.
It creates a FileInputStream for test.dat if test.dat exists.
8. SQL ________ statements may change the contents of a database.
Answer(s):
a. SELECT
UPDATE
DELETE
INSERT
9. A resource bundle is ________.
Answer:
a Java source code that contains image, audio, and text files
a Java class file or a text file that provides locale-specific information
an image file
an audio file
10. A collision occurs ________.
Answer:
when two or more keys are mapped to the same hash value
when two elements have the same key value
when two elements are mapped to the same key
11. If two objects o1 and o2 are equal, what are the values for o1.equals(o2) and o1.hashCode() == o2.hashCode()?
Answer:
true true
true false
false true
false false
12.You should always invoke the unlock method in the finally clause.
Answer:
true
false
13. Which method on a condition should you invoke to wake all waiting threads?
a. condition.wake();
condition.signal();
condition.wakeAll();
condition.signalAll();
14. For an instance of Collection, you can obtain its iterator using ________.
c.getIterator()
c.iterator()
c.iterators()
c.iterable()
15. A(n) _____________________ occurs if no thread can proceed because each thread is waiting for another to complete some work first.
Answer:
16. You can use index to traverse elements in a set.
Answer:
true
false
17. What is the output for the following code?
[1]
[1, 1]
[1, 1, 1]
[1, 1, 1, 1]
18. Which of the following best describes Sally?
Sally cannot be used in a HashSet because it is not serializable
Sally will not compile because to override equals, the signature must be boolean equals(Sally obj)
Sally can be used in a HashSet, but the HashSet will perform poorly because of collisions
Sally should not be used in a HashSet because equal objects may have different hash values.
19. The HashSet and TreeSet hold non-duplicate elements.
Answer:
true
false
20. The elements in HashSet are ordered.
Answer:
true
false
21. Keys for text messages to a user change based on Locale.
Answer:
True
False
22. If two strings are equal, the two strings have the same hashCodes.
Answer:
true
false
23. Result set meta data are retrieved through ________.
Answer:
a Connection object
a Statement object
a ResultSet Object
a PreparedStatement object
24. Which of the data types below does not allow duplicates?
Set
List
Vector
Stack
LinkedList
25.Suppose a list contains {"red", "green", "red", "green"}. What is the list after the following code?
list.remove("red");
{"red", "green", "red", "green"}
{"green", "red", "green"}
{"green", "green"}
{"red", "green", "green"}
26. Which statement is true of the following snippet?
Scanner kybd = new Scanner(System.in);
String inp = kybd.next();
if (inp == "sophie") System.out.println("sophie entered");
else System.out.println("sophie not entered");
kybd.close();
The code prints "sophie entered" if the user enters "sophie" and prints "sophie not entered" otherwise.
The code throws a runtime error.
The code always prints "sophie not entered"
The code always prints "sophie entered"
27. Which of the following code is correct to create an instance of ResourceBundle?
ResourceBundle.getBundle();
ResourceBundle.getBundle(locale);
ResourceBundle.getBundle(resourcefilename);
ResourceBundle.getBundle(resourcefilename, locale);
28. Suppose list1 is ["Atlanta", "Macon"] and list2 is ["Atlanta", "Macon", "Savannah"], which of the following returns true?
list1.contains(list2)
list2.contains(list1)
list1.contains(list2.get(2))
list2.contains(list1.get(0))
29. Which data type should you use if you want to store duplicate elements and be able to insert or delete elements anywhere efficiently?
ArrayList
LinkedList
Vector
Set
Stack
30. Suppose your program frequently tests whether a student is in a soccer team, what is the best data structure to store the students in a soccer team?
ArrayList
HashSet
TreeSet
LinkedList
Vector
31. Given the following code snippet that uses JDBC to create a database connection:
String driver = "org.apache.derby.jdbc.EmbeddedDriver";
String url = "jdbc:derby:Test;create=true";
String user = "";
String pw = "";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, user, pw);
What is the name of the database that this code fragment connects to?
Answer:
32. Analyze the following code.
a. The program displays Red
The program displays Blue
The program displays Green
The program may display Red, Blue, or Green.
The program cannot compile, because the first() method is not defined in Set.
33. ListIterator is a subclass of Iterator.
Answer:
true
false
34. Closing an OutputStream ensures that the data in the buffer are sent to the destination.
Answer:
true
false
35.Every object has the hashCode() method.
Answer:
true
false
a.[1, 2, 3, 4, 5]
b.[2, 3, 4, 5]
c.[1, 3, 4, 5]
d.[1, 2, 4, 5]
e.[1, 2, 3, 4]
import java util public class Test public static void main(StringO args) Set A set new HashSet A 0 set.add new A0); set addinew A0); set add (new A0); set add(new A0); System.out.println(set) class A int r 1 public String toString return r public int hash Code 0 return rExplanation / Answer
The answers for the questions are as follows
1.D
3.x 1
7.C
8.B
9.A
11.B
13.C
19.FALSE
30.E
32.E
33.True
35. TRUE
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.