[{"id":"javabeginner-001","courseId":"java-beginner","domain":"language-basics","topic":"Default values for fields","prompt":"A class declares `private int count;` as a field and never assigns it. A method prints `count` right away. What appears?","hint":"Fields that nobody assigns still get a starting value.","explain":"A field you declare but never assign is not left empty. The compiler gives it a default chosen by its type. Local variables are handled differently.","source":"https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html","interaction":{"type":"single"},"options":[{"id":"a","text":"0","why":"An int field defaults to 0 when nothing assigns it, so the method prints 0."},{"id":"b","text":"null","whyNot":"null is the default for object references such as String fields; an int is a primitive and gets 0."},{"id":"c","text":"An error, because count was never initialized","whyNot":"The compiler gives unassigned fields a default, so no error occurs for a field."},{"id":"d","text":"Leftover random data from memory","whyNot":"The compiler sets a field to a default for its type, so its value is not arbitrary."}],"answer":"a","explanation":"Declared fields that are never assigned get a type-based default: 0 for numeric types, false for boolean, '\\u0000' for char, and null for references.","concept":"Declared fields that are never assigned get a type-based default: 0 for numeric types, false for boolean, '\\u0000' for char, and null for references.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"class Counter {\n    private int count;\n\n    void show() {\n        System.out.println(count);\n    }\n}","takeaways":["Unassigned fields get type-based defaults, such as 0 for an int."]},{"id":"javabeginner-002","courseId":"java-beginner","domain":"language-basics","topic":"Primitive types","prompt":"Which TWO statements about Java's primitive types are true?","hint":"Compare each size and range with the type's bit width.","explain":"Each primitive type has a fixed size and range, and the compiler gives unassigned fields a default. Some types that feel primitive are really classes.","source":"https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"By default, int is a 32-bit signed two's complement integer.","why":"int runs from -2^31 to 2^31-1 by default, which is 32 bits signed."},{"id":"b","text":"char is a single 16-bit Unicode character.","why":"char holds one 16-bit Unicode character, from '\\u0000' to '\\uffff'."},{"id":"c","text":"String is a primitive type, just like int.","whyNot":"String is a class. The tutorial says it is not technically a primitive, though the language supports it specially."},{"id":"d","text":"A boolean field defaults to 0 if it is never assigned.","whyNot":"A boolean field defaults to false, not 0."},{"id":"e","text":"long is a 32-bit integer.","whyNot":"long is a 64-bit two's complement integer."},{"id":"f","text":"byte ranges from -256 to 255.","whyNot":"byte is an 8-bit signed integer, so it runs from -128 to 127."}],"answer":"ab","explanation":"Primitive types have fixed sizes: byte 8-bit, short 16-bit, int 32-bit, long 64-bit, and char a 16-bit Unicode character. String is a class, not a primitive.","concept":"Primitive types have fixed sizes: byte 8-bit, short 16-bit, int 32-bit, long 64-bit, and char a 16-bit Unicode character. String is a class, not a primitive.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Know the bit widths: byte 8, short 16, int 32, long 64."]},{"id":"javabeginner-003","courseId":"java-beginner","domain":"language-basics","topic":"String objects are immutable","prompt":"The code below calls a String method and ignores what it returns. What does it print?","hint":"Think about whether a String can be edited once it exists.","explain":"A String holds fixed text. A method that seems to change it computes a new result and hands that back, so the value you see depends on what the method returns.","source":"https://docs.oracle.com/javase/tutorial/java/data/strings.html","interaction":{"type":"single"},"options":[{"id":"a","text":"ada","why":"Strings are immutable. toUpperCase returns a new string and leaves name as it was."},{"id":"b","text":"The name in capitals, ADA","whyNot":"The method returns an uppercase string, but nothing stores it, so name does not change."},{"id":"c","text":"null","whyNot":"Nothing sets name to null here; the method only creates and returns a new string."},{"id":"d","text":"An empty line","whyNot":"The original string is not emptied; String methods return new strings rather than editing this one."}],"answer":"a","explanation":"String is immutable: once created, its characters cannot change. Methods that appear to modify a string create and return a new one.","concept":"String is immutable: once created, its characters cannot change. Methods that appear to modify a string create and return a new one.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"String name = \"ada\";\nname.toUpperCase();\nSystem.out.println(name);","takeaways":["Keep the return value of String methods; the original string never changes."]},{"id":"javabeginner-004","courseId":"java-beginner","domain":"language-basics","topic":"switch fall-through","prompt":"The code below runs with day set to 2. What does it print?","hint":"Look at where the first matching case ends.","explain":"A switch jumps to the matching case label but does not stop there by itself. Control keeps moving down the labels until a break or the end of the switch.","source":"https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html","interaction":{"type":"single"},"options":[{"id":"a","text":"Tue, then Wed","why":"Case 2 matches and prints Tue; with no break, execution falls into case 3, which prints Wed before the break stops it."},{"id":"b","text":"Tue only","whyNot":"That would need a break right after the Tue line; without one, the next case's statements also run."},{"id":"c","text":"Mon, Tue, then Wed","whyNot":"Mon belongs to case 1, which does not match 2, so the switch never runs it."},{"id":"d","text":"Other","whyNot":"default runs only when no case label matches, and case 2 matches here."}],"answer":"a","explanation":"Without a break, a switch falls through: every statement after the matching case label runs, in order, until a break or the end of the switch.","concept":"Without a break, a switch falls through: every statement after the matching case label runs, in order, until a break or the end of the switch.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"int day = 2;\nswitch (day) {\n    case 1:\n        System.out.println(\"Mon\");\n    case 2:\n        System.out.println(\"Tue\");\n    case 3:\n        System.out.println(\"Wed\");\n        break;\n    default:\n        System.out.println(\"Other\");\n}","takeaways":["A missing break makes a switch run the next case's code too."]},{"id":"javabeginner-005","courseId":"java-beginner","domain":"language-basics","topic":"Postfix increment value","prompt":"The code below runs. Judge this statement: the output is 6, and i holds 7 afterward.","hint":"Ask whether the printed value is taken before or after the increment.","explain":"The ++ operator changes a variable by one. Its position around the variable decides whether the surrounding expression sees the old value or the new one.","source":"https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op1.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"Postfix i++ evaluates to the original value, 6, and i becomes 7 after the increment."},{"id":"b","text":"False","whyNot":"The postfix form prints the value i had before the increment, so the output is 6 and i then holds 7."}],"answer":"a","explanation":"The postfix ++ yields the operand's value before the increment; the prefix ++ yields the value after it. Both increase the variable by one.","concept":"The postfix ++ yields the operand's value before the increment; the prefix ++ yields the value after it. Both increase the variable by one.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"int i = 6;\nSystem.out.println(i++);","takeaways":["i++ gives the old value; ++i gives the new one."]}]