Question
A database server processes queries based on their priority and time of arrival. The priority associated with each query is an integer in the range
-
A database server processes queries based on their priority and time of arrival. The priority associated with each query is an integer in the range from 1 to 100. Two designs have been proposed:
Design 1: Keep all the queries in one list, sorted by their time of arrival.
Design 2: Keep the queries in 100 lists; each list holds all the queries of a given priority, sorted by their time of arrival.
Which of the following three operations will be more efficient with Design 1 than with Design 2?
Process the earliest query of the highest priority
Report how many queries have arrived within the last hour
Create a single list of all queries sorted by priority and, within the same priority, by time of arrival.
-
I only
-
II only
-
III only
-
I and II only
-
II and III only
-
Consider the following method.
private int swap(int a, int b) { if (a < b) { b = a; a = b; } return b - a; }
What are the values of the variables a, b and c after the following statements are executed?
int a = 2, b = 5; int c = swap(a, b);
-
2, 5, 0
-
2, 5, 3
-
2, 5, -3
-
2, 2, 0
-
5, 2, 3
-
-
Consider the following class
public class BankAccount { private int balance; public BankAccount() { balance = 0; } public BankAccount(int amt) { balance = amt; } public int getBalance() { return balance; } public void makeDeposit(int amt) { balance += amt; } }
What is the output when the following code segment (in a client class) is executed?
List
bank = new ArrayList (); bank.add(new BankAccount()); bank.add(new BankAccount(5)); bank.add(new BankAccount(10)); bank.add(new BankAccount(15)); for (BankAccount customer : bank) customer.makeDeposit(10); int total = 0; for (BankAccount customer : bank) total += customer.getBalance(); System.out.println(total); -
0
-
30
-
40
-
60
-
70
-
-
The statement
System.out.println(Integer.MAX_VALUE);
prints 2147483647 which is equal to 231 - 1. What does the following statement print?
System.out.println(Integer.MAX_VALUE + 2);
-
0
-
2147483649
-
2147483647.0
-
-2147483647
-
Nothing: it causes a ArithmeticException
-
-
Brad has derived his class from a library class JPanel. JPanel's paintComponent method displays a blank picture in a panel. Brad has redefined JPanel's paintComponent to display his own picture. Brad's class compiles with no errors, but when he runs the program, only a blank background is displayed. Which of the following hypotheses cannot be true in this situation?
-
Brad misspelled "paintComponent" in his method's name.
-
Brad specified an incorrect return type for his paintComponent method.
-
Brad chose the wrong type for a parameter in his paintComponent method.
-
Brad specified two parameters for his paintComponent method, while JPanel's paintComponent takes only one parameter.
-
Brad has a logic error in his paintComponent code which prevents it from generating the picture.
-
-
Suppose each pixel (picture element) in a digital image is represented by a 24-bit color value. How much memory does it take to store an uncompressed image of 2048 pixels by 1024 pixels?
-
2 KB
-
2 MB
-
6 MB
-
6 GB
-
32 TB
-
-
Consider the following method.
public void printSomething(String s) { int n = s.length(); if (n < 1) return; String s1 = s.substring(1, n); printSomething(s1); System.out.println(s); printSomething(s1); }
How many letters 'A' and how many letters total will be printed as a result of calling printSomething("ABCD")?
A's Total 1 10 4 10 1 26 4 26 15 26 -
Consider the following method.
public int countSomething(int[] arr) { int m = arr[0]; int count = 1; for (int k = 1; k < arr.length; k++) { int a = arr[k]; if (a > m) { m = a; count = 1; } else if (m == a) count++; } return count; }
For which of the following arrays will countSomething return 3?
-
int[] arr = {0, 1, 1, 1, 1};
-
int[] arr = {1, 6, 5, 4, 0};
-
int[] arr = {1, 0, 5, 6, 1};
-
int[] arr = {3, 2, 1, 0, 5};
-
None of the above
-
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started