String Class Flashcards

1
Q

Difference between “==” and equals()

A

”==” is a binary operator, used to compare primitives and sometimes objects, but with objects compares the memory reference.
equals() is a method, used for checking equality of two objects defined by business logic

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

Difference between String vs StringBuilder vs StringBuffer

A

String Class is inmutable
StringBuilder is mutable but not thread-safe
StringBuffer is mutable and thread-safe

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

Access Level «protected»

A

Same class, same package, sub class in another package

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

Access Level «defalut»

A

Same class, same package

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

Access Level «private»

A

Same class

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

Access Level «public»

A

Anyplace

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

static Keyword

A
  • Can be used without object instances
  • Used when the problem is best solved without object
  • Used when objects of the same type need to share fields
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

static Methods

A
  • Are called class
  • Are useful for APIs that are not object oriented
  • Are commonly used in place of constructors to perform tasks related to object initialization
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Difference between Abstract class and interface

A
Abstract class usually contains at least one abstract method, cannot be instantied
Interface contains only abstract methods, cannot be instantied
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Features of list interface

A
- Is an ordered collection of elements
Behaviors
- Adding, getting, removing and overwriting elements at a specific index
- Getting the size of the list
- Allows duplicate elements
- Ordered
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Features of set interface

A
  • Contains only unique elements
  • Has no index
  • Duplicate elements are not allowed
  • You can iterate through elements to access them
  • TreeSet provides sorted implementation
  • Unordered
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Features of map interface

A
  • Stores multiple key-value pairs, key is unique and associated to the value.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Features of deque interface

A
  • Can be used as a stack or a queue
  • Like a deck
  • A Queue provides FIFO operations add, remove.
  • A Stack provides LIFO operaions, push and pop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Features of comparable interface

A
  • Overrides the compareTo method
  • Provides only one sort option
  • Collections.sort(collection)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Features of comparator interface

A
  • Implemented by using compare method
  • Enables you to create multiple comparator classes
  • Enables you to create and use numerous sorting options
  • Collections.sort(collection, comparator class)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

finally block

A

Always runs regardless of wheter or not an error ocurred during the execution of the try block

17
Q

TreeMap

A

A map where the keys are automatically sorted

18
Q

HashTable

A

A classic associative array implementation with keys and values, is synchronized

19
Q

HashMap

A

An implementation just like HashTable except that it accepts null keys and values. Also, it is not synchronized

20
Q

Extends and implements

A

In a normal class you can implement multiple interfaces, but not extends multiple classes

21
Q

Stack vs Heap memory

A

Stack is a dedicated space to save information and Heap is dynamically space that grows as part of the program

22
Q

Garbage Collector

A

Free up memory space is not being used anymore, ensure memory is using efficiently