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.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

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)); }}

  1. Prints: false,false
  2. Prints: true,false
  3. Prints: false,true
  4. Prints: true,true
  5. None of the above
Question 2 Multiple Choice (Single Answer)

Java is a programming language originally developed by

  1. Dennis Ritchie
  2. Edsger Dijkstra
  3. James Gosling
  4. Louis Pasteur
Question 3 Multiple Choice (Single Answer)

Commonly used metasyntactic variable names are

  1. Hello and world
  2. Foo and Bar
  3. i and j
  4. int and float
Question 4 Multiple Choice (Single Answer)

Amoeba operating system was developed by

  1. Linus Torvalds
  2. Dennis Ritchie
  3. Sun Microsystems
  4. Andrew S. Tanenbaum
Question 5 Multiple Choice (Single Answer)

SQL was developed by

  1. Donald D. Chamberlin and Raymond F. Boyce
  2. Donald D. Chamberlin
  3. Raymond F. Boyce
  4. none
Question 6 Multiple Choice (Single Answer)

Why we use "Type Def" in C ?

  1. Modifying existing Data type.
  2. Used for defining type of data type used.
  3. Creating new data type names
  4. Not a valid key word
Question 7 True/False

"typedefs" used for data types are not machine dependent.

  1. True
  2. False
Question 8 True/False

"typedefs" used for data types are not machine dependent.

  1. True
  2. False
Question 9 Multiple Choice (Single Answer)

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?

  1. x = 4, y = 1, z = 5
  2. x = 3, y = 2, z = 6
  3. x = -7, y = 1, z = 5
  4. x = 4, y = 2, z = 6
Question 10 Multiple Choice (Single Answer)

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

  1. (A), (B), (D) & (E)
  2. (B), (C) & (D)
  3. (B), (D), (E) & (F)
  4. (B), (D) & (E)
  5. (D) & (F)
Question 11 Multiple Choice (Single Answer)

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);

  1. (A), (B) & (C)
  2. (A), (C) & (D)
  3. (B) & (C)
  4. (A) & (C)
  5. (A) & (D)
Question 12 Multiple Choice (Single Answer)

Which of the following represent legal flow control statements? (A) break; (B) break(); (C) continue outer; (D) continue(inner); (E) return; (F) exit();

  1. (A), (B) & (C)
  2. (A), (C) & (E)
  3. (A), (C) & (D)
  4. (A) & (E)
  5. (C) & (E)
Question 13 Multiple Choice (Single Answer)

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?

  1. Locale loc = Locale.getLocale();System.out.println(loc.getDisplayCountry()+ “ “+ df.format(d));
  2. Locale loc = Locale.getDefault();System.out.println(loc.getDisplayCountry()+ “ “ + df.format(d));
  3. Locale bc = Locale.getLocale();System.out.println(loc.getDisplayCountry()+ “ “+ df.setDateFormat(d));
  4. Locale loc = Locale.getDefault();System.out.println(loc.getDispbayCountry()+ “ “+ df.setDateFormat(d));
Question 14 Multiple Choice (Single Answer)

What is an Iterator ?

  1. Enables you to cycle through a collection in the forward direction only, for obtaining or removing elements
  2. just for loop
  3. while loop
  4. It is an class for storing objects
Question 15 Multiple Choice (Single Answer)

What is the List interface?

  1. The Set interface
  2. list stores elements in an ordered way but may contain duplicate elements
  3. List interface provides support for ordered collections of objects.
  4. All of the above
Question 16 Multiple Choice (Single Answer)

Which implementation of the List interface provides for the fastest insertion of a new element into the middle of the list?

  1. Vector
  2. Array List
  3. Linked List
  4. None of the above
Question 17 Multiple Choice (Multiple Answers)

What is difference between array & arraylist?

  1. Array: can store primitive ArrayList: Stores object only
  2. Array: fix size ArrayList: resizable
  3. Array: can have multi dimensional ArrayList: can have multi dimensional
  4. Array: lang ArrayList: Collection framework
Question 18 Multiple Choice (Single Answer)

What is the Parent Class of ArraList?

  1. AbstractList
  2. List
  3. Array
  4. All of the Above
Question 19 Multiple Choice (Single Answer)

What are the constructors of ArrayList?

  1. ArrayList( )
  2. ArrayList(Collection c)
  3. ArrayList(int capacity)
  4. All of the Above
Question 20 Multiple Choice (Single Answer)

What is an ArrayList?

  1. Class
  2. Interface
  3. Abstract Class
  4. All of the above