Java basics Flashcards
What is a class?
• A class is a template for creating multiple objects.
• A class defines states and behavior that an object can exhibit.
Is Java pass by reference or pass by value?
Java is always pass by value.
It means the argument is copied to the parameter variable, so that the method operates on the copy.
When the value of an object is passed, the reference to it is passed.
What is unboxing and autoboxing in Java
Autoboxing is the automatic conversion the java compiler makes between the primitive types and their corresponding object wrapper classes.
i.e.: converting an int to Integer.
If the conversion goes the other way, its called unboxing.
What is the difference between an abstract class and an interface?
Abstract classes specify what an object is, by defining characteristics of an object type. They can have a constructor and can hold a state.
Interfaces are used to establish a contract about what an object can do. They define capabilities that are promised to be provided by an implementing object.
What are the different access modifiers available in Java
There are four types of Access modifiers:
public - accesible from everywhere in the application.
protected - accessible within the package and the subclasses in any package.
package private (default) - accessible strictly within the package.
private - accessible only within the same class where it is declared.
What is a final class, what is a final method?
final class - cannot be extended.
final method - cannot be overridden.
What is a defender method?
Defender methods are - default methods - which were added in Java 8 to interfaces.
With them, it is possible to add new methods to interfaces.
What is the purpose of garbage collector in Java and when is it used?
The purpose of garbage collection is to - identify and discard - those objects, that are no longer needed by the application, in order for the resources to be reclaimed and reused.