Java Programming Fundamentals and Collections
Test your knowledge of Java programming concepts including ArrayList, List interface, Iterator, flow control, data types, operators, and String handling.
Questions
class H { public static void main (String[] args) { String s1 = "HHH"; StringBuffer sb2 = new StringBuffer(s1); System.out.print(sb2.equals(s1) + "," + s1.equals(sb2)); }}
- Prints: false,false
- Prints: true,false
- Prints: false,true
- Prints: true,true
- None of the above
Java is a programming language originally developed by
- Dennis Ritchie
- Edsger Dijkstra
- James Gosling
- Louis Pasteur
Commonly used metasyntactic variable names are
- Hello and world
- Foo and Bar
- i and j
- int and float
Amoeba operating system was developed by
- Linus Torvalds
- Dennis Ritchie
- Sun Microsystems
- Andrew S. Tanenbaum
SQL was developed by
- Donald D. Chamberlin and Raymond F. Boyce
- Donald D. Chamberlin
- Raymond F. Boyce
- none
Why we use "Type Def" in C ?
- Modifying existing Data type.
- Used for defining type of data type used.
- Creating new data type names
- Not a valid key word
"typedefs" used for data types are not machine dependent.
- True
- False
"typedefs" used for data types are not machine dependent.
- True
- False
Consider the following code: int x, y, z; y = 1; z = 5; x = 0 - (++y) + z++; After execution of this, what will be the values of x, y and z?
- x = 4, y = 1, z = 5
- x = 3, y = 2, z = 6
- x = -7, y = 1, z = 5
- x = 4, y = 2, z = 6
In the code below, what data types the variable x can have? byte b1 = 5; byte b2 = 10; x = b1 * b2;(A) byte (B) int (C) short (D) long (E) float (F) double
- (A), (B), (D) & (E)
- (B), (C) & (D)
- (B), (D), (E) & (F)
- (B), (D) & (E)
- (D) & (F)
Given the declarations boolean b; short x1 = 100, x2 = 200, x3 = 300; Which of the following statements are evaluated to true? (A) b = x1 * 2 == x2; (B) b = x1 + x2 != 3 * x1; (C) b = (x3 - 2x2<0) || ((x3 = 400)<2**x2); (D) b = (x3 - 2*x2>0) || ((x3 = 400) 2x2);
- (A), (B) & (C)
- (A), (C) & (D)
- (B) & (C)
- (A) & (C)
- (A) & (D)
Which of the following represent legal flow control statements? (A) break; (B) break(); (C) continue outer; (D) continue(inner); (E) return; (F) exit();
- (A), (B) & (C)
- (A), (C) & (E)
- (A), (C) & (D)
- (A) & (E)
- (C) & (E)
Given: • d is a valid, non-null Date object • df is a valid, non-null DateFormat object set to the current locale What outputs the current locales country name and the appropriate version of d’s date?
- Locale loc = Locale.getLocale();System.out.println(loc.getDisplayCountry()+ “ “+ df.format(d));
- Locale loc = Locale.getDefault();System.out.println(loc.getDisplayCountry()+ “ “ + df.format(d));
- Locale bc = Locale.getLocale();System.out.println(loc.getDisplayCountry()+ “ “+ df.setDateFormat(d));
- Locale loc = Locale.getDefault();System.out.println(loc.getDispbayCountry()+ “ “+ df.setDateFormat(d));
What is an Iterator ?
- Enables you to cycle through a collection in the forward direction only, for obtaining or removing elements
- just for loop
- while loop
- It is an class for storing objects
What is the List interface?
- The Set interface
- list stores elements in an ordered way but may contain duplicate elements
- List interface provides support for ordered collections of objects.
- All of the above
Which implementation of the List interface provides for the fastest insertion of a new element into the middle of the list?
- Vector
- Array List
- Linked List
- None of the above
What is difference between array & arraylist?
- Array: can store primitive ArrayList: Stores object only
- Array: fix size ArrayList: resizable
- Array: can have multi dimensional ArrayList: can have multi dimensional
- Array: lang ArrayList: Collection framework
What is the Parent Class of ArraList?
- AbstractList
- List
- Array
- All of the Above
What are the constructors of ArrayList?
- ArrayList( )
- ArrayList(Collection c)
- ArrayList(int capacity)
- All of the Above
What is an ArrayList?
- Class
- Interface
- Abstract Class
- All of the above