In October, we threw a Java basics Pop Quiz at all our Java neophytes. Quite a few of you, 1,330 in fact, decided to humor us and test your knowledge of Java programming. Like any good instructor should, I’m going to take this opportunity to go over the results with you.

Question 1: Static methods
Our first question covered static methods, asking you to pick the best definition of static from four choices. As you can see in Figure A, 65.3 percent of you chose the correct definition: A static method may be called without declaring an instance of a class.

Figure A
Results for Question 1

There was some confusion regarding this question though. As member rjlorimer pointed out in this discussion post, a static method technically can’t be overridden either, since by definition, it belongs to the class and not an instance of that class. We like to reward critical thinking like that on the part of quiz takers, so I’m going to award rjlorimer a point of extra credit for bringing this to my attention.

Question 2: Garbage collection
The second question of our quiz—“How do you force garbage collection?”—generated a bit of confusion too. Garbage collection is a function of the Java Virtual Machine and refers to the act of freeing memory used by variables when they are no longer needed by an application. In reality, this is a bit of a trick question, since, currently at least, it’s not possible to force garbage collection at all in Java. As Figure B shows, only 46.2 percent of you chose the correct answer, making this the most-missed question on the quiz.

Figure B
Results for Question 2

Question 3: Array declarations
The third question tested your knowledge of array instantiation. We showed you the following array declaration code snippet:
int a[] = new int[25];

Then, we asked you to pick which statements were true regarding the resulting array. Of the four answers, two were correct: a[24] is zero, and a.length is 25. Figure C shows the results for this question:

Figure C
Results for Question 3

Remember, Java automatically initializes all value types to a nonnull value, so a[0] could not be null. Also, Java arrays are zero-based, so while there are 25 elements in the array, the highest valid index would be 24.

Dealing in aggregate, it’s a bit difficult to arrive at a number for how many of you got this question right by providing both correct answers. We know that 45.4 percent knew that a.length would be 25, and 28.3 percent knew that a[24] would be 0, but we don’t know what percentage of those two groups gave both those answers—our survey tool doesn’t tell us that easily. That should answer the questions some of you had about why you had to grade your own work.

Question 4: The modulus operator
Remember in fourth grade math class when you were doing division with remainders? Java can tell you the remainder of a division problem using the modulus operator (%): 12 % 3 = 0. Judging from the results for question number four, shown in Figure D, a shade under 70 percent of you are familiar with modulus in Java.

Figure D
Results for Question 4

Question 5: Implicit casting
The final question tested your knowledge of implicit typecasting, where Java automatically converts a variable of one type into a variable of another type. Java will do this for you with numeric types as long as it doesn’t result in a loss of precision: Casting from an int to a long is implicit, while you’d need to explicitly cast a long to an int. Failure to use an explicit cast when necessary results in a compiler error. As you can see from Figure E, the vast majority of you appear to have a handle on this sort of thing. (Note that the results don’t add up to exactly 100 percent here, due to rounding.)

Figure E
Results for Question 5

Quiz feedback

What do you think of our pop quiz? Would you like to see more of them in the future? You can suggest topics for future quizzes in the discussion below.