Module 3: Generics & Serialization

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/34

flashcard set

Earn XP

Description and Tags

Module 3: Generics & Serialization

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

35 Terms

1
New cards

It is a method of allowing abstraction over types.

Generics

2
New cards

This make classes more dynamic in terms of handling types.

Generics

3
New cards

Instead of allowing a specific type, a _____ object accepts different type as its parameter.

generic

4
New cards

Using generics, we can achieve the following:

  • Abstraction over Type

  • Enforce Compile Time Type Safety

  • Strengthens Relationship

  • Declaration of Programmers Intent

  • Removes the need of casting

5
New cards

a class will not be bounded by a specific type

Abstraction Over Type

6
New cards

moves checking of ClassCastException to compilation time

  • Enforce Compile Time Type Safety

7
New cards

In Generics, we move the checking of ClassCastException to ____ time

compilation time

8
New cards

code states how class must be used instead of focusing on type

Declaration of Programmers Intent

9
New cards

Limitation of Generics

  1. Instantiate a generic type

  2. Use primitive for generic type

  3. Infer compatibility with classes

10
New cards

To apply generics for a class, _____ brackets are provided after the classname.

angle

11
New cards
public class Sample<?>{ /* class code */ }

What values can be put in the “?” ?

  1. T - Type

  2. E - Element

  3. K - Key

  4. N - Number

  5. V - Value

12
New cards

We can limit the type of data to be accepted even when generics is applied using?

Generic Bounds

13
New cards

There 2 different bound forms in generics.

  • Upperbound

  • Lowerbound

14
New cards

uses extends keyword. It is the limit that states that the accepted type must be a subtype of the given class.

Upperbound

15
New cards

uses super keyword. It is the limit that states that the accepted type must be a supertype of the given class.

Lowerbound

16
New cards

All data travels in the form of?

bytes

17
New cards

Aall data travels in the form of bytes. Since object is also a form of data, it is needed to converted to a byte form before it can be passed through a certain network. Java now handles this in a process which they call as ?

Serialization

18
New cards

It is a process in which current state of Object will be saved in stream of bytes.

Serialization

19
New cards

TRUE OR FALSE

As byte stream create is platform neutral hence once objects created in one system can be deserialized in other platform.

TRUE

20
New cards

Translate the Object state to Byte Streams. This Byte stream can be used for different purpose.

  • Write to disk

  • Store in memory

  • Send byte stream to other platform over network

  • Save in database as Binary Large Object (BLOB)

21
New cards

An interface that is implemented when serialization is desired.

Serializable Interface

22
New cards

This interface means that no methods must be defined to conform with it.

Marker Interface

23
New cards

The Serializable interface can be found from _____ package.

Java IO

24
New cards

NOTES:

  • If a class implements Serializable then all of its future subclasses are also Serializable automatically

  • If the superclass did not implement Serializable, the following will happen on deserialization:

    1. The default constructor will be invoked from the superclass.

    2. All fields will initialized with the default values.

NOTES:

  • If a class implements Serializable then all of its future subclasses are also Serializable automatically

  • If the superclass did not implement Serializable, the following will happen on deserialization:

    1. The default constructor will be invoked from the superclass.

    2. All fields will initialized with the default values.

25
New cards

It is a version number associated to each serializable class by serialization runtime.

serialVersionUID

26
New cards

This version number is used during deserialization process to verify that the sender and receiver of a serialized object have loaded class for that object which is compatible with respect to serialization.

serialVersionUID

27
New cards

TRUE OR FALSE

Defining a serialVersionUID field in serializable class is mandatory.

FALSE

Defining a serialVersionUID field in serializable class is not mandatory

28
New cards

If a serializable class have explicit serialVersionUID then this field should be of type ____ and must be ____ and ___. It is advised that ____ access modifier must be used.

long

static

final

private

29
New cards

NOTES:

If there is no serialVersionUID field defined explicitly then serialization runtime will calculate default value for that class.

NOTES:

If there is no serialVersionUID field defined explicitly then serialization runtime will calculate default value for that class.

30
New cards

TRUE OR FALSE

  • It is advisable to define serialVersionUID

TRUE

31
New cards

If there is a difference between serialVersionUID of loaded receiver class and corresponding sender class then ______ will be thrown.

InvalidClassException

32
New cards

To exclude certain fields from Serialization, the _____ modifier can be used.

transient

33
New cards

This exludes the modified field from the process. When the object is deserialized, the instance will receive the default value for the field.

transient

34
New cards

Two ways to exclude certain fields from Serialization

  • Transient

  • Static

35
New cards

NOTES:

Another way to exclude is to use static modifier. This also excludes the field from Serialization. However, this is due to a different cause. When a variable is declared as static, the variable is a standalone value. This value is not a part of the instance but rather a part of the class itself. Therefore, serialization will not include it.

NOTES:

Another way to exclude is to use static modifier. This also excludes the field from Serialization. However, this is due to a different cause. When a variable is declared as static, the variable is a standalone value. This value is not a part of the instance but rather a part of the class itself. Therefore, serialization will not include it.