Java basics Flashcards

1
Q

What is a class?

A

• A class is a template for creating multiple objects.

• A class defines states and behavior that an object can exhibit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Is Java pass by reference or pass by value?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is unboxing and autoboxing in Java

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference between an abstract class and an interface?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the different access modifiers available in Java

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a final class, what is a final method?

A

final class - cannot be extended.
final method - cannot be overridden.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a defender method?

A

Defender methods are - default methods - which were added in Java 8 to interfaces.
With them, it is possible to add new methods to interfaces.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of garbage collector in Java and when is it used?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly