Programming Fundamentals (Java)

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play

1/25

flashcard set

Earn XP

Description and Tags

Comprehensive practice flashcards covering computer architecture, Java syntax, control structures, loops, methods, arrays, ArrayLists, and object-oriented programming concepts.

26 Terms

1
New cards

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).

2
New cards

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.

3
New cards

How are the nine’s complement and ten’s complement of a decimal number AA calculated?

The nine’s complement is obtained by subtracting AA from (10n−1)(10^n - 1) (subtracting each digit from 99). The ten’s complement is obtained by adding 11 to the nine’s complement (or subtracting AA from 10n10^n), where nn is the number of digits.

4
New cards

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 11 (changing every 00 to 11 and every 11 to 00). The two’s complement is found by adding 11 to the one’s complement.

5
New cards

What mathematician's name is the historical origin of the word "algorithm"?

Muhammad ibn Musa-al-Khwarizmi.

6
New cards
<p>Based on the provided flowcharts, what specific process is performed by the flowchart on the right?</p>

Based on the provided flowcharts, what specific process is performed by the flowchart on the right?

It reads two numbers, aa and bb, tests the decision condition a<ba < b, assigns the larger value to big and the smaller value to small, and prints them in descending order (big, small).

7
New cards

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).

8
New cards

What are the four integer primitive types in Java along with their bit sizes?

The four integer types are byte (88-bit), short (1616-bit), int (3232-bit), and long (6464-bit).

9
New cards

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 (3232-bit) and double (6464-bit). Float literals must be appended with an FF or ff, and long literals must be appended with an LL or ll.

10
New cards

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).

11
New cards

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.

12
New cards

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.

13
New cards

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.

14
New cards

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.

15
New cards

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.

16
New cards

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.

17
New cards

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.

18
New cards

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.

19
New cards

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.

20
New cards

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).

21
New cards

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.

22
New cards

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.

23
New cards

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.

24
New cards

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);).

25
New cards

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.

26
New cards

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.