Java Programming Fundamentals

Test your knowledge of Java programming basics including arrays, loops, operators, syntax, and core concepts like garbage collection and static variables.

20 Questions Published

Questions

Question 1 Multiple Choice (Multiple Answers)

Each pass through a loop is called a/an

  1. enumeration
  2. iteration
  3. culmination
  4. pass through
Question 2 Multiple Choice (Multiple Answers)

Which looping process checks the test condition at the end of the loop?

  1. for
  2. while
  3. do-while
  4. no looping process checks the test condition at the end
Question 3 Multiple Choice (Multiple Answers)

A continue statement causes execution to skip to

  1. the next iteration of the loop
  2. the first statement after the loop
  3. the statement following the continue statement
  4. the return 0; statement
Question 4 Multiple Choice (Single Answer)

In a group of nested loops, which loop is executed the most number of times?

  1. the outermost loop
  2. the innermost loop
  3. all loops are executed the same number of times
  4. cannot be determined without knowing the size of the loops
Question 5 Multiple Choice (Single Answer)

The statement i++; is equivalent to

  1. i = i + i;
  2. i = i - 1;
  3. i = i + 1;
  4. i --;
Question 6 Multiple Choice (Single Answer)

Which looping process is best used when the number of iterations is known?

  1. for
  2. while
  3. do-while
  4. all looping processes require that the iterations be known
Question 7 Multiple Choice (Single Answer)

What's wrong? for (int k = 2, k <=12, k++)

  1. the increment should always be ++k
  2. the variable must always be the letter i when using a for loop
  3. there should be a semicolon at the end of the statement
  4. the commas should be semicolons
Question 8 Multiple Choice (Single Answer)

What's wrong? while( (i < 10) && (i > 24))

  1. the logical operator && cannot be used in a test condition
  2. the while loop is an exit-condition loop
  3. the test condition is always false
  4. the test condition is always true
Question 9 Multiple Choice (Single Answer)

If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block?

  1. parentheses ( )
  2. braces { }
  3. brackets [ ]
  4. arrows < >
Question 10 Multiple Choice (Single Answer)

What's wrong? (x = 4 && y = 5) ? (a = 5) ; (b = 6);

  1. the question mark should be an equal sign
  2. the first semicolon should be a colon
  3. there are too many variables in the statement
  4. the conditional operator is only used with apstrings
Question 11 Multiple Choice (Single Answer)

Each pass through a loop is called a/an

  1. enumeration
  2. iteration
  3. culmination
  4. pass through
Question 12 Multiple Choice (Single Answer)

Which looping process checks the test condition at the end of the loop?

  1. for
  2. while
  3. do-while
  4. no looping process checks the test condition at the end
Question 13 Multiple Choice (Single Answer)

A continue statement causes execution to skip to

  1. the return 0; statement
  2. the first statement after the loop
  3. the statement following the continue statement
  4. the next iteration of the loop
Question 14 Multiple Choice (Single Answer)

Read the following program: public class test { public static void main(String [] args) { int x = 3; int y = 1; if (x = y) System.out.println("Not equal"); else System.out.println("Equal"); } } What is the result?

  1. The output is “Equal”
  2. The output in “Not Equal”
  3. An error at " if (x = y)" causes compilation to fall.
  4. The program executes but no output is show on console.
Question 15 Multiple Choice (Single Answer)

How you can force the garbage collection?

  1. Using delete operator
  2. Using destructor
  3. Garbage collection is an automatic process & cant be forced.
  4. None of the above
Question 16 Multiple Choice (Single Answer)

Difference between Swing and AWT?

  1. AWT are light-weight componenets. Swings are heavy-weight components.
  2. AWT is platform independent. SWING is platform dependent.
  3. AWT are heavy-weight componenets. Swings are light-weight components.
  4. None of the above
Question 17 True/False

Can I have multiple methods in the same class?

  1. True
  2. False
Question 18 Multiple Choice (Multiple Answers)

Which of the following are legal identifiers?

  1. 2variable
  2. variable2
  3. _whatavariable
  4. 3
  5. #myvar
  6. $anothervar
Question 19 Multiple Choice (Single Answer)

What will happen when you compile and run the following code? public class MyClass{ static int i; public static void main(String argv[]){ System.out.println(i); } }

  1. Error Variable i may not have been initialized
  2. null
  3. 1
  4. 0
Question 20 Multiple Choice (Single Answer)

What will happen if you try to compile and run the following code? public class Q { public static void main(String argv[]){ int anar[]=new int[5]; System.out.println(anar[0]); } }

  1. Error: anar is referenced before it is initialized
  2. null
  3. 0
  4. 5