Java Programming Fundamentals

Test your knowledge of basic Java programming concepts including loops, variables, Boolean operations, conditionals, functions, and Java-specific features like AWT and applets.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What's the difference between an Applet and an application ?

  1. An application is only available on Windows
  2. Applets can paint words, applications cannot.
  3. Applets are run over the web.
  4. None of the above.
Question 2 Multiple Choice (Single Answer)

What is the main function of any variable ?

  1. To add numbers together
  2. To keep track of data in the memory of the computer
  3. To print words on the screen
  4. To write Java
Question 3 Multiple Choice (Single Answer)

What is the proper way to declare a variable ?

  1. variableName variableType;
  2. variableName;
  3. variableType;
  4. variableType variableName;
Question 4 Multiple Choice (Single Answer)

Booleans are _______.

  1. True or False
  2. Single characters
  3. Text
  4. All numbers
Question 5 Multiple Choice (Single Answer)

The following statements make “length” be what number ? int length; length = 4; length ++;

  1. 4
  2. 5
  3. 6
  4. 8
Question 6 Multiple Choice (Single Answer)

What is an assignment statement ?

  1. Adding a number to an int
  2. Assigning a multiplication
  3. Assigning a name to a variable
  4. Assigning a value to a variable
Question 7 Multiple Choice (Single Answer)

What will be the value of “num” after the following statements? int num; num = (5+4); num = num / 9; num = 12;

  1. 0
  2. 1
  3. 12
  4. 9
Question 8 Multiple Choice (Single Answer)

If you want your conditional to depend on two conditions BOTH being true, what is the proper notation to put between the two Boolean statements ?

  1. &
  2. &&
  3. |
  4. ||
Question 9 Multiple Choice (Single Answer)

Which of the following means that in order for the conditional to happen, either x must be less than 3 or y must be greater than or equal to 4 ?

  1. if ((x < 3) && (y > 4))
  2. if (x < 3 y >= 4)
  3. if ((x < 3) || (y > = 4))
  4. if ((x > 3) || (y < = 4))
Question 10 Multiple Choice (Single Answer)

What is a loop ?

  1. A new type of Applet
  2. A segment of code to be run a specified amount of times
  3. A segment of code to be run infinite times
  4. A segment of code to be run once
Question 11 Multiple Choice (Single Answer)

What is essential in making sure that your loop is not infinite ?

  1. That there is a Boolean statement somewhere in your code
  2. That your Boolean statement will at some point be false
  3. That your Boolean statement will at some point be true
  4. All of the above
Question 12 Multiple Choice (Single Answer)

Which is NOT a section of all types of loops ?

  1. Initialization
  2. Loop Body
  3. Test statement
  4. The word "while"
Question 13 Multiple Choice (Single Answer)

In a ‘for’ loop, what section of the loop is not included in the parentheses after “for” ?

  1. Initialization
  2. Loop Body
  3. Test statement
  4. Update
Question 14 Multiple Choice (Single Answer)

What is a function in terms of Computer Science ?

  1. A group of code lines that performs a specific task
  2. A group of code lines that performs a whole program
  3. Something that contains an ‘init’
  4. The purpose of Java
Question 15 Multiple Choice (Single Answer)

What is the difference between private and public functions ?

  1. Public functions are free, you have to buy private ones
  2. Public functions are the only ones you can download
  3. Public functions can be used by anyone, private can only be used by other code in the class you are writing
  4. Public functions can’t be used
Question 16 Multiple Choice (Single Answer)

What does AWT stands for ?

  1. Advanced Window Toolkit
  2. Abstract window Toolkit
  3. Adjust Window Toolkit
  4. None of these
Question 17 Multiple Choice (Single Answer)

Given: class Hexy { public static void main(String[] args) { Integer i = 42; String s = (i<40)?"life":(i>50)?"universe":"everything"; System.out.println(s); } } What is the result?

  1. null
  2. life
  3. universe
  4. everything
  5. Compilation fails
  6. An exception is thrown at runtime
Question 18 Multiple Choice (Single Answer)

class Fork { public static void main(String[] args) { if(args.length == 1 | args[1] .equals("test")) { System.out.println ("test case"); } else { System.out.println("production " + args[0]); } }}And the command-line invocation:java Fork live2What is the result?

  1. test case
  2. production
  3. test case live2
  4. Compilation fails
  5. An exception is thrown at runtime
Question 19 Multiple Choice (Single Answer)

Given: class Foozit { public static void main(String[] args) { Integer x = 0; Integer y = 0; for(Short z = 0; z < 5; z++) if((++x > 2) || (++y > 2)) X++ ; System.out.println(x + " " + y); } } What is the result?

  1. 5 1
  2. 5 2
  3. 5 3
  4. 8 1
  5. 8 2
  6. 8 3
Question 20 Multiple Choice (Single Answer)

Given: class Titanic { public static void main(String[] args) { Boolean bl = true; boolean b2 = false; boolean b3 = true; if((bl & b2) | (b2 & b3) & b3) System.out.print("alpha "); if((bl = false) | (b1 & b3) | (bl | b2)) System.out.print("beta "}; } } What is the result?

  1. beta
  2. alpha
  3. alpha beta
  4. Compilation fails
  5. No output is produced
  6. An exception is thrown at runtime