1/25
Comprehensive practice flashcards covering computer architecture, Java syntax, control structures, loops, methods, arrays, ArrayLists, and object-oriented programming concepts.
What are the two major advantages of high-level programming languages compared to low-level languages?
High-level languages are easier to program in (programs take less time to write, are shorter, easier to read, and more likely to be correct) and they are portable (they can run on different kinds of computers with few or no modifications).
How does an interpreter differ from a compiler when translating a high-level program?
An interpreter reads a high-level program and executes it line by line, alternately reading lines and performing computations, whereas a compiler translates the program into machine language before execution.
How are the nine’s complement and ten’s complement of a decimal number A calculated?
The nine’s complement is obtained by subtracting A from (10n−1) (subtracting each digit from 9). The ten’s complement is obtained by adding 1 to the nine’s complement (or subtracting A from 10n), where n is the number of digits.
How are the one’s complement and two’s complement of a binary number determined?
The one’s complement is found by subtracting each digit from 1 (changing every 0 to 1 and every 1 to 0). The two’s complement is found by adding 1 to the one’s complement.
What mathematician's name is the historical origin of the word "algorithm"?
Muhammad ibn Musa-al-Khwarizmi.

Based on the provided flowcharts, what specific process is performed by the flowchart on the right?
It reads two numbers, a and b, tests the decision condition a<b, assigns the larger value to big and the smaller value to small, and prints them in descending order (big, small).
What changes are introduced by Compact Source Files and Instance Main Methods (JEP 512) starting in Java SE 25?
Programs can be written without declaring an enclosing class, the main method can be written simply as void main() without public, static, or String[] args, and console I/O can be done using the IO class (such as IO.println and IO.readln).
What are the four integer primitive types in Java along with their bit sizes?
The four integer types are byte (8-bit), short (16-bit), int (32-bit), and long (64-bit).
What are the two floating-point primitive types in Java, and how are literal values explicitly typed as float or long?
The two types are float (32-bit) and double (64-bit). Float literals must be appended with an F or f, and long literals must be appended with an L or l.
How is a constant variable declared in Java, and what naming convention is used?
A constant is declared by prepending the keyword final to the variable declaration and assigning an initial value. By convention, constant names are written in all uppercase letters with words separated by underscores (e.g., KMS_PER_MILE).
What are the rules and constraints when declaring a local variable using var (introduced in Java 10)?
var works only for local variables declared inside a method, the variable must be initialized immediately so the compiler can infer its type, and the inferred type remains strictly fixed.
How does the Java logical exclusive OR (^) operator evaluate its operands?
The ^ operator evaluates to true if its two boolean operands have different truth values (one is true and the other is false), and evaluates to false if both operands are true or both are false.
How does short-circuit evaluation work for the Java && and || operators?
For &&, if the first condition is false, Java skips evaluating the second condition because the overall expression is guaranteed to be false. For ||, if the first condition is true, Java skips evaluating the second condition because the overall expression is guaranteed to be true.
Which data types are supported by the expression in a Java switch statement?
Primitive types byte, short, char, and int; wrapper classes Byte, Short, Character, and Integer; the String class; and enum types.
What is the key operational difference between a while loop and a do-while loop?
A while loop checks its condition at the entry point before running the loop body (running zero or more times), whereas a do-while loop checks its condition on exit, ensuring the body runs at least once.
How do the control flow keywords break and continue function inside a loop?
break terminates the loop completely and exits it, while continue skips the remainder of the current iteration and jumps directly to the next iteration of the loop.
What components define a method signature in Java?
A method signature consists of the method name and the types and number of its parameters. It does not include the return type or access modifiers.
How does parameter passing differ between primitive-type and reference-type arguments in Java?
Primitive parameters are passed by value (a copy of the data is made, leaving the caller's variable unchanged). Reference parameters pass a copy of the reference/address, allowing the method to modify the contents of the caller's underlying object.
What is the difference between a class (static) method and an instance (non-static) method?
A static method belongs to the class itself and can be called directly without instantiating an object. An instance method belongs to an object of the class and must be called on a specific instance.
What are the primary tradeoffs between standard Java arrays and ArrayLists?
Arrays are more efficient and have a fixed size; ArrayLists are resizable, more flexible, provide built-in convenience methods, but are less efficient and can only store objects (requiring autoboxing for primitives).
What are autoboxing and autounboxing in Java?
Autoboxing is the automatic conversion of a primitive type (such as int or double) into its corresponding wrapper class object (Integer or Double). Autounboxing is the automatic conversion in the reverse direction.
What happens if you attempt to call add or remove on a list created with List.of?
It throws an UnsupportedOperationException because lists created with List.of are immutable.
What occurs to the default constructor when a programmer explicitly writes any constructor in a Java class?
The default no-argument constructor is no longer provided automatically once any constructor is explicitly defined.
What does the this keyword represent in Java, and how can it be used within constructors?
The this keyword is a reference to the current object. In constructors, it can be used to refer to instance variables (e.g., this.name = name;) or to invoke another overloaded constructor in the same class (e.g., this("Bob", 1);).
What automatically generated components are provided by a Java record (introduced in Java 16)?
A record automatically creates private final fields, a canonical constructor, getter methods without the get prefix (e.g., name()), equals(), hashCode(), and toString(). Setters are not allowed because records are immutable.
In object-oriented design, what is the difference between high cohesion and loose coupling?
High cohesion means all member variables and methods of a class are closely related to a single, well-defined purpose. Loose coupling means classes depend minimally on the internal details of other classes.