Java Programming Fundamentals
Test your knowledge of Java programming basics including arrays, loops, operators, syntax, and core concepts like garbage collection and static variables.
Questions
Each pass through a loop is called a/an
- enumeration
- iteration
- culmination
- pass through
Which looping process checks the test condition at the end of the loop?
- for
- while
- do-while
- no looping process checks the test condition at the end
A continue statement causes execution to skip to
- the next iteration of the loop
- the first statement after the loop
- the statement following the continue statement
- the return 0; statement
In a group of nested loops, which loop is executed the most number of times?
- the outermost loop
- the innermost loop
- all loops are executed the same number of times
- cannot be determined without knowing the size of the loops
The statement i++; is equivalent to
- i = i + i;
- i = i - 1;
- i = i + 1;
- i --;
Which looping process is best used when the number of iterations is known?
- for
- while
- do-while
- all looping processes require that the iterations be known
What's wrong? for (int k = 2, k <=12, k++)
- the increment should always be ++k
- the variable must always be the letter i when using a for loop
- there should be a semicolon at the end of the statement
- the commas should be semicolons
What's wrong? while( (i < 10) && (i > 24))
- the logical operator && cannot be used in a test condition
- the while loop is an exit-condition loop
- the test condition is always false
- the test condition is always true
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?
- parentheses ( )
- braces { }
- brackets [ ]
- arrows < >
What's wrong? (x = 4 && y = 5) ? (a = 5) ; (b = 6);
- the question mark should be an equal sign
- the first semicolon should be a colon
- there are too many variables in the statement
- the conditional operator is only used with apstrings
Each pass through a loop is called a/an
- enumeration
- iteration
- culmination
- pass through
Which looping process checks the test condition at the end of the loop?
- for
- while
- do-while
- no looping process checks the test condition at the end
A continue statement causes execution to skip to
- the return 0; statement
- the first statement after the loop
- the statement following the continue statement
- the next iteration of the loop
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?
- The output is “Equal”
- The output in “Not Equal”
- An error at " if (x = y)" causes compilation to fall.
- The program executes but no output is show on console.
How you can force the garbage collection?
- Using delete operator
- Using destructor
- Garbage collection is an automatic process & cant be forced.
- None of the above
Difference between Swing and AWT?
- AWT are light-weight componenets. Swings are heavy-weight components.
- AWT is platform independent. SWING is platform dependent.
- AWT are heavy-weight componenets. Swings are light-weight components.
- None of the above
Can I have multiple methods in the same class?
- True
- False
Which of the following are legal identifiers?
- 2variable
- variable2
- _whatavariable
- 3
- #myvar
- $anothervar
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); } }
- Error Variable i may not have been initialized
- null
- 1
- 0
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]); } }
- Error: anar is referenced before it is initialized
- null
- 0
- 5