Java Basic Online Quiz

Java basics

30 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

If the last index of array list is 12, what is the length of the array?

  1. 13
  2. 12
  3. 11
  4. Unknown
Question 2 Multiple Choice (Single Answer)

What is the index of the last element of array list[]?

  1. list[list.length]
  2. list.length-1
  3. list[-1]
  4. list[list.length-1]
Question 3 Multiple Choice (Single Answer)

How do you declare an array of ten Strings?

  1. String[] running = new String[10];
  2. String[] running = String[10];
  3. String[10] running = new String[];
  4. String running = String[10];
Question 4 Multiple Choice (Single Answer)

How do you declare an array of booleans?

  1. boolean[] running;
  2. boolean running[];
  3. boolean[10] running;
  4. boolean running[10];
Question 5 Multiple Choice (Single Answer)

What Java keyword can be used to end a method?

  1. stop
  2. break
  3. return
  4. done
Question 6 Multiple Choice (Single Answer)

What Java keyword is used to create objects?

  1. new
  2. create
  3. construct
  4. abracadabra
Question 7 Multiple Choice (Single Answer)

What is the value of "This is Patrick".length()?

  1. Syntax error
  2. 15
  3. 13
  4. 17
Question 8 Multiple Choice (Single Answer)

The technique of breaking a problem down into smaller, more easily managed pieces, is called:

  1. Designing the algorithm
  2. Procedural decomposition
  3. Stupid
  4. Patrick
Question 9 Multiple Choice (Single Answer)

Which error prevents Java from running your program?

  1. Runtime error
  2. Logic error
  3. Syntax error
  4. Spelling error
Question 10 Multiple Choice (Single Answer)

Who coined the terms "bug" and "debug"?

  1. Aniket
  2. Grace Hopper
  3. Ada Lovelace
  4. Katherine Johnson
Question 11 Multiple Choice (Single Answer)

Which of the following are valid Java String literals?

  1. ""Hello", she said"
  2. "Falling\n\tleaves"
  3. "Can't tell"
  4. If he'll just listen once
Question 12 Multiple Choice (Single Answer)

What is the value of "1" + "3" + 2?

  1. 15
  2. 132
  3. 42
  4. 6
Question 13 Multiple Choice (Single Answer)

What is the value of (int) Math.abs((double) 5 / -4 )?

  1. 1
  2. 2
  3. 1.00
  4. 1.25
Question 14 Multiple Choice (Single Answer)

If x is an integer > 10, how would you print the ten's digit?

  1. x / 10 % 10
  2. x % 10
  3. x / 10
  4. x % 10 * 10
Question 15 Multiple Choice (Single Answer)

Which of the following type conversions requires an explicit type cast?

  1. int to double
  2. int to String
  3. double to int
  4. double to String
Question 16 Multiple Choice (Single Answer)

What is the value of 3 * 7 + 8.4 / 2?

  1. 25.2
  2. 25
  3. 12.6
  4. 14.6
Question 17 Multiple Choice (Single Answer)

If str="foolishness", which expression returns "ess"?

  1. str.substring(8)
  2. str.substring(9)
  3. str.substring(8,4)
  4. str.substring(9,3)
Question 18 Multiple Choice (Single Answer)

If str="foolishness", which expression returns "lish"?

  1. str.substring(3,7)
  2. str.substring(4,8)
  3. String.substring(str, 3, 7)
  4. str.substring(3,6)
Question 19 Multiple Choice (Single Answer)

Given x is an integer, which of the following is a valid conditional?

  1. if (x > 2 or < 5)
  2. if (x = 4)
  3. if (x < 2 && x > 5)
  4. if (x)
Question 20 Multiple Choice (Single Answer)

What values can be generated by the following code: (int) (Math.random() * 3)

  1. Floating point numbers between 0 and 3.
  2. Integers between 0 and 2.
  3. Integers between 0 and 3.
  4. Doubles from 0 to 3, including 0 but not including 3.
Question 21 Multiple Choice (Single Answer)

How do you create an array of 20 integers?

  1. int[20] myArray;
  2. int[] myArray = new int[20];
  3. int myArray = [20];
  4. int[] myArray = int[20];
Question 22 Multiple Choice (Single Answer)

Which of following constant declarations is valid?

  1. public static final void foo;
  2. public static final int USERS = 20;
  3. public FINAL SIZE = 10;
  4. public static boolean final BORED = TRUE;
Question 23 Multiple Choice (Single Answer)

Which loop will iterate 10 times?

  1. for (int i=0; i<10; i++)
  2. for (x=0; x<10; x++)
  3. for (int y=1; y<10; y++)
  4. for (int j=0; j<=10; j++)
Question 24 Multiple Choice (Single Answer)

Which of the following class names follows proper Java naming conventions?

  1. myClass
  2. The_Classiest_Class
  3. MyClassyClass
  4. aniketsclasstoendallclasses
Question 25 Multiple Choice (Single Answer)

Which of the following variable names follows proper Java naming conventions?

  1. another_variable_name
  2. Int
  3. myIdentifier
  4. variabletrackinghowmanyuserslogin
Question 26 Multiple Choice (Single Answer)

Which of following are legal Java identifiers?

  1. 2answer
  2. maybe
  3. foo+bar
  4. can't_decide
Question 27 Multiple Choice (Single Answer)

Which value can you assign to a boolean variable?

  1. true
  2. 1
  3. null
  4. False
Question 28 Multiple Choice (Single Answer)

Which is the correct signature for the main() method?

  1. public static int main(String args)
  2. public static void main(String arg)
  3. public static final main()
  4. public static void main(String[] args)
Question 29 Multiple Choice (Single Answer)

Which of following is not a primitive data type?

  1. boolean
  2. String
  3. int
  4. double