โ† All 1Z0-819 Flashcard Decks

Java Fundamentals & Object-Oriented Programming Flashcards

8 cards from real 1Z0-819 practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 8 Java Fundamentals & Object-Oriented Programming flashcards as text
  1. What is the main purpose of the Java Virtual Machine (JVM)?

    Answer: To convert Java bytecode to machine code at runtime

    The Java Virtual Machine (JVM) is responsible for executing Java bytecode. After Java source code is compiled into bytecode, the JVM translates this platform-independent bytecode into machine-specific instructions at runtime. This 'write once, run anywhere' capability is a core feature of Java, enabled by the JVM's role as an interpreter and runtime environment.

  2. Which keyword is used to create a subclass in Java?

    Answer: extends

    In Java, the `extends` keyword is used to establish an inheritance relationship between classes. When a class `A` `extends` class `B`, `A` becomes a subclass (or child class) of `B`, inheriting its public and protected methods and fields. This promotes code reuse and establishes an 'is-a' relationship.

  3. What is encapsulation in object-oriented programming?

    Answer: Using private fields with public getters/setters

    Encapsulation is an object-oriented programming principle that bundles data (fields) and methods that operate on the data within a single unit (a class). It involves restricting direct access to some of an object's components, typically by making fields `private`. Access to these private fields is then controlled through public `getter` and `setter` methods, ensuring data integrity and controlled modification.

  4. What does the 'static' keyword denote in Java?

    Answer: Class-level access without needing an object

    The `static` keyword in Java indicates that a member (field or method) belongs to the class itself, rather than to any specific instance of the class. This means you can access `static` members directly using the class name, without needing to create an object of that class. `static` methods can only access `static` variables and call `static` methods.

  5. What is polymorphism in Java?

    Answer: One interface, many implementations

    Polymorphism, meaning 'many forms,' is a core OOP concept allowing objects to take on multiple forms. In Java, this often manifests as an object of a subclass being treated as an object of its superclass, or an object implementing an interface being treated as an object of that interface. This enables a single interface or method to be used for different underlying data types or implementations, promoting flexibility and extensibility.

  6. What is the result of using 'final' with a variable in Java?

    Answer: The variable is assigned only once

    When the `final` keyword is used with a variable in Java, it means that the variable's value can only be assigned once. After its initial assignment, the value of a `final` variable cannot be changed, making it a constant. This applies to both primitive types (value itself is constant) and reference types (the reference itself is constant, not the object it points to).

  7. What is inheritance in Java?

    Answer: Allowing a class to reuse another class's code via 'extends'

    Inheritance is a fundamental OOP concept where a new class (subclass or child class) derives properties and behaviors from an existing class (superclass or parent class). In Java, this is achieved using the `extends` keyword. It promotes code reusability, allowing subclasses to inherit and potentially override methods and fields from their superclass, establishing an 'is-a' relationship.

  8. Which interface must be implemented to sort objects in Java?

    Answer: Comparable

    To sort objects in Java based on their 'natural order,' the class of these objects must implement the `Comparable` interface. This interface requires the implementation of the `compareTo()` method, which defines how instances of the class should be ordered relative to each other. For custom sorting criteria, the `Comparator` interface is used.