0

Java Basic Online Quiz

Description: Java basics
Number of Questions: 30
Created by:
Tags: programming
Attempted 0/29 Correct 0 Score 0

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

  1. 13

  2. 12

  3. 11

  4. Unknown


Correct Option: A

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]


Correct Option: B

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


Correct Option: A

How do you declare an array of booleans?

  1. boolean[] running;

  2. boolean running[];

  3. boolean[10] running;

  4. boolean running[10];


Correct Option: A

What Java keyword can be used to end a method?

  1. stop

  2. break

  3. return

  4. done


Correct Option: C

What Java keyword is used to create objects?

  1. new

  2. create

  3. construct

  4. abracadabra


Correct Option: A

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

  1. Syntax error

  2. 15

  3. 13

  4. 17


Correct Option: B

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


Correct Option: B

Which error prevents Java from running your program?

  1. Runtime error

  2. Logic error

  3. Syntax error

  4. Spelling error


Correct Option: C

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

  1. Aniket

  2. Grace Hopper

  3. Ada Lovelace

  4. Katherine Johnson


Correct Option: B

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


Correct Option: B

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

  1. 15

  2. 132

  3. 42

  4. 6


Correct Option: B

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

  1. 1

  2. 2

  3. 1.00

  4. 1.25


Correct Option: A

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


Correct Option: A

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


Correct Option: C

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

  1. 25.2

  2. 25

  3. 12.6

  4. 14.6


Correct Option: A

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)


Correct Option: A

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)


Correct Option: A

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)


Correct Option: C

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.


Correct Option: B

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


Correct Option: B

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;


Correct Option: B

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


Correct Option: A

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

  1. myClass

  2. The_Classiest_Class

  3. MyClassyClass

  4. aniketsclasstoendallclasses


Correct Option: C

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

  1. another_variable_name

  2. Int

  3. myIdentifier

  4. variabletrackinghowmanyuserslogin


Correct Option: C

Which of following are legal Java identifiers?

  1. 2answer

  2. maybe

  3. foo+bar

  4. can't_decide


Correct Option: B

Which value can you assign to a boolean variable?

  1. true

  2. 1

  3. null

  4. False


Correct Option: A

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)


Correct Option: D

Which of following is not a primitive data type?

  1. boolean

  2. String

  3. int

  4. double


Correct Option: B
- Hide questions