Java Flashcards
What is the lifecycle of a java program
Source code -> Compiler -> Output -> JVM (Java virtual machine
name the primitive variables in java
short, bit, int, float, long, boolean, byte, double
What is a local variable
defined in method, constructor, or block
what is an instance variable
non-static variables defined in a class outside of a method or any block
what is a static OR class variable
a variable declared using the static keyword in a class outside of any method
what are the differences between a static variable and an instance variable?
an instance variable is unique to the object that defines it. there is only one class variable for all the instance of a class, if the class variable is changed it effects all the instances of the class
What are primary OOP concepts in java
abstraction, encapsulation, polymorphism, inheritance
What is abstraction?
The process of identifying the essential details to be known and ignoring the non essential details from the perspective of the system
What is encapsulation?
controlling the read and write access of classes, it provides the ability to hide data and methods from other classes
What is an access modifier?
Key words that define the accessibility for a class, method, or attribute.
What are the access modifier keywords
private, default, protected, public
What is polymorphism?
Poly: many, Morph: forms
using a method with the same name to perform different tasks
What is an example of polymorphism?
Method overloading or Method overridding
What are the two types of polymorphism that java supports?
Static and Dynamic
What is static polymorphism?
Allows you to implement multiple methods within the same class with the same name.
How would you implement method overloading? 3 answers
- Have a different number of parameters
- The types of the parameters are different
- The order of the parameters are different
What is method overriding?
Using inheritance to customize or completely replace the behavior of a method defined in the parent class.
What is inheritance?
Deriving a class from a class or hierarchy of classes that share a set of attributes and methods
What is an interface?
A completely abstract class that contains:
Only abstract methods
AND / OR
Default methods and final variables
How does another class implement an interface?
By using the keyword implements: public class MyClass implements MyInterface { }
What is a functional Interface?
An interface that has only one abstract method.
A class can implement multiple interfaces?
TRUE
A class can extend multiple classes?
FALSE
If a method in an interface has an implementation, what access modifier must it have?
default OR static
Interface variables are what by definition?
public static and final, visibility cannot be changed
if an interface is implemented by a non abstract class, what must the class do?
override all of the interfaces abstract methods
What are Lambda expressions?
functional constructs without classes.
they can be passed like objects and executed as required.
they also make the modifiers, return type and parameter types completely optional.