Java Basics Flashcards

1
Q

Method Overloading

A
  • (if a class has) multiple methods having the same name but different parameters
  • it increases the readability and reusability of the program
  • there are two ways to overload the method: changing the number of arguments; changing the data type
  • a good example is System.out.println() method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Constant

A
  • it is a value that can’t be changed after assigning it
  • We use static and final modifiers (aka non-access modifiers), to declare any variable as constant
  • its identifier name must be in capital letters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

“final” keyword

A
  • it is a non-access modifier applicable only to a variable, a method, or a class
  • when a variable is declared with the final keyword, its value can’t be modified.
  • when a method is declared with the final keyword, it can’t be overridden.
  • when a class is declared with the final keyword, it can’t be extended (inherited).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Modifiers

A
  • are specific keywords that we can use to make changes to the characteristics of a variable, method, or class and limit its scope
  • Java has two types of modifiers: access modifiers and non-access modifiers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Non-Access Modifiers

A
  • provide information about the characteristics of a class, method, or variable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the seven types of Non-Access Modifiers?

A
  • static
  • final
  • abstract
  • synchronized
  • volatile
  • transient
  • native
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

static methods

A
  • when a method is declared with the static keyword, it is known as the static method
  • Any static member can be accessed before any objects of its class are created and without reference to any object.
  • the most common example of a static method is the main() method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the restrictions of the static methods?

A
  • they can only directly call other static methods
  • they can only directly access static data
  • they can’t refer to this or super in any way
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

private keyword

A

an access modifier used for attributes, methods, and constructors, making them only accessible within the declared class

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

protected keyword

A

used for attributes, methods, and constructors, making them accessible in the same package and subclasses

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

int vs. Integer

A
  • int is a primitive data type while Integer is a type of class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

“new” keyword

A
  • it is used to create an instance of the class.
  • it instantiates a class by allocating memory for a new object and returning a reference to that memory.
  • we can also use the new keyword to create the array object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the two types of data types Java provides?

A
  • primitive

- reference

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

Examples of reference data types

A
  • Array
  • class
  • interface
  • String
  • Enumeration
  • Annotations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Serializable

A

In Java, it is a marker (empty) interface and has no fields or methods to implement.

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

Serialization

A

In Java, it is a process of converting the Java code Object into a Byte Stream, to transfer the Object Code from one JVM to another and recreate it using the process of Deserialization.

17
Q

Why need serialization

A
  • communication
  • Persistence
  • Deep Copy
  • Caching
  • Cross JVM Synchroniaztion
18
Q

Instantiation

A

Creating an object of the class

  • to call the constructor of a class that creates an instance (object)
  • it occupies the initial memory for the object and returns a reference.
  • two ways to create an instance: using the new keyword; using the static factory method
Example:
// defines a reference (variable) that can hold an object
ClassName reference;
// instantiation
reference = new Constructor();