Java Flashcards
What is a JVM?
JVM (Java Virtual Machine) is an abstract machine. It provides runtime environment in which java bytecode can be executed.
The JVM performs following operation:
- Loads code
- Verifies code
- Executes code
- Provides runtime environment
JVM provides definitions for the:
- Memory area
- Class file format
- Register set
- Garbage-collected heap
- Fatal error reporting etc.
What is Object Oriented Programming?
The object-oriented programming is basically a computer programming design philosophy or methodology that organizes/ models software design around data, or objects rather than functions and logic.
An object is referred to as a data field that has unique attributes and behavior. Everything in OOP is grouped as self-sustainable objects.
What are the four pillars of OOP?
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
What does abstraction mean and why it’s useful?
Abstraction allows us to hide the implementation of a function from the interface. This process is called “abstraction” in OOP, because we are abstracting away the gory implementation details of a class and only presenting a clean and easy-to-use interface via the class’ member functions.
It’s useful because this separation:
- helps isolate the impact of changes
- reduces complexity (you don’t need to understand the implementation, only the interface)
What does Encapsulation mean?
In OOP, we encapsulate by binding the data and functions which operate on that data into a single unit, the class. By doing so, we can hide private details of a class from the outside world and only expose functionality that is important for interfacing with it.
Encapsulation protects data and functions from outside interference and misuse. Therefore, it also provides security.
What does Inheritance mean?
The concept allows us to inherit or acquire the properties of an existing class (parent class) into a newly created class (child class). It is known as inheritance. It provides code reusability.
Programmers applying the technique of inheritance arrange these classes into what is called an “IS-A” type of relationship.
What does Polymorphism mean?
Polymorphism means “many forms”, and it occurs when we have many classes that are related to each other by inheritance.
Therefore, calling code only needs to be written to handle objects from the root of the hierarchy, and any object instantiated by any child class in the hierarchy will be handled in the same way.
e.g.: we have an Animal class (parent) and Pig, Dog and Cat classes (child). Pig, Dog and Cat extends the Animal class. In this case you can do this: Animal myAnimal = new Animal(); Animal myPig = new Pig(); Animal myDog = new Dog();
This is polymorphism.