Java Programming Fundamentals and Object-Oriented Programming Review

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

1/31

flashcard set

Earn XP

Description and Tags

Comprehensive practice questions and review cards covering Java basics, OOP principles, inheritance, exceptions, collections, and I/O streams.

32 Terms

1
New cards

What is the meaning of "platform-independent" in Java?

Write once, run anywhere.

2
New cards

What is the primary purpose of the Java Virtual Machine (JVM)?

It is used to interpret and execute Java bytecode.

3
New cards

Which two components constitute the Java platform?

The Java Virtual Machine (JVM) and the Java Application Programming Interface (API).

4
New cards

What are the file extensions for Java source code and compiled Java code?

Java source code uses the extension .java, and compiled bytecode uses the extension .class.

5
New cards

What is the entry point method of a Java application?

The main method.

6
New cards

What is the default value of an uninitialized instance variable of type double in Java?

0.0

7
New cards

What is the output of attempting to modify an array element using an enhanced for-loop, as in: for (int i : a) { i = 1; } System.out.println(a[1]);?

0, because the enhanced for-loop variable receives a copy of each element's value and does not modify the underlying array.

8
New cards

What is a checked exception in Java?

A checked exception is an exception that is checked during compilation time.

9
New cards

Which access modifier is used to hide members of a class from outside classes?

private

10
New cards

If a class does not explicitly declare a constructor, what does the Java compiler automatically provide?

A default constructor.

11
New cards

Can constructors be overridden in Java?

No, constructors cannot be overridden because they are not inherited by subclasses.

12
New cards

When both a single-int overload method(int x) and a varargs overload method(int... a) exist, which one is chosen when passing a single integer argument like method(2)?

The exact match method(int x) is selected over the variable-argument method.

13
New cards

In Java inheritance, are instance variables overridden dynamically like instance methods?

No, instance variables are resolved at compile time based on the reference type, not overridden dynamically at runtime.

14
New cards

What is the difference between composition and inheritance?

Composition is a way to create objects by combining existing objects, while inheritance is a way to reuse code.

15
New cards

What is the key structural difference between a standard array and an ArrayList in Java?

A standard array has a fixed length that cannot change, whereas an ArrayList can dynamically adjust its size.

16
New cards

Which method is used to determine the number of elements in an ArrayList?

size()

17
New cards

What happens when a duplicate element is added to a Java Set?

The Set will keep the old element and reject/not add the duplicated one, preserving unique elements.

18
New cards

What is the internal data structure difference between HashSet and TreeSet?

HashSet is backed by a hash table, whereas TreeSet is backed by a balanced binary tree (Red-Black tree).

19
New cards

Which keyword prevents an object's member variable from being serialized during ObjectOutputStream operations?

transient

20
New cards

What are the fundamental data units of low-level streams and high-level streams?

The low-level stream's data unit is a byte; the high-level stream's data unit is a primitive type or character.

21
New cards

Which method of the File class checks if a file is marked as hidden?

isHidden()

22
New cards

Which checked exception is thrown when an attempt is made to open a nonexistent file using FileInputStream?

FileNotFoundException

23
New cards

What is the return type of the instanceof operator?

A boolean.

24
New cards

What is the correct syntax for an interface named B to inherit from interface A?

public interface B extends A {}

25
New cards

What is the accessibility scope of a variable declared with the default (package-private) modifier?

It can be accessed by classes and subclasses defined within the same package.

26
New cards

Which abstract class is the direct superclass of all numeric wrapper classes (Byte, Short, Integer, Long, Float, Double) in java.lang?

java.lang.Number

27
New cards

Why does calling super(color, price) after setting this.type = type in a subclass constructor cause a compile error?

Because a call to the superclass constructor (super()) must be the very first statement in a constructor.

28
New cards

Can a top-level outer class be declared with the private access modifier?

No, declaring a top-level class as private causes a compile-time error.

29
New cards

What is the result of calling str.concat(" University!") on a String str = "FPT" without reassigning the return value?

The length of str remains 3 because Strings in Java are immutable.

30
New cards

What does comparing two distinct newly allocated Integer objects with == (e.g., new Integer(0) == new Integer(0)) return?

false, because == compares object memory references, not their primitive values.

31
New cards

What is the range of values that can be assigned to a variable of type short in Java?

−215-2^{15} through 215−12^{15} - 1 (−32768-32768 to 3276732767).

32
New cards

Why does passing a primitive double x to a method that performs x = x - 2; fail to modify the value of x in the caller?

Java uses pass-by-value, so the method receives a copy of the primitive value and modifications are local to that method.