Chapter 3 - Core Java APIs Flashcards

1
Q

Is java.util.List a class or an interface?

A

The java.util.List is an interface.

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

What does the set method does in a list?

A

Set: replaces an existing value.

Format:
list.set(index,value)

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

What is the sintax to convert a list to an array?

A

Convert a list to an array:

Object[ ] objectArray = list.toArray( );

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

What is the sintax to convert an array to a list?

A

Convert an array to a list:
String[ ] array = {“Hawk”,”robin”};
List list = Arrays.asList(array);

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

Can a list size be changed?

A

List sizes cannot be changed, for example using remove. An UnsupportedOperation Exception is thrown.

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

Can the date and time classes be instantiated directly?

A

No. The date and time classes have private constructors to force you to use static methods.

Below code won’t compile:

LocalDate d = new LocalDate( ); // DOES NOT COMPILE

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

What is the result if invalid numbers are passed to the of( ) method?

A

Passing invalid numbers to of( ) throws DateTimeException.

Example:
LocalDate.of(2015, Month.January, 32); //throws an exception.

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

Are the date and time classes mutable or immutable?

A

The date and time classes are immutable just like the String class.

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

Do arrays have a lenght method or property?

A

Arrays have a lenght property NOT a method.

Example:

char[ ] c = new char [2];

int lenght = c.lenght;

Instead of:

int lenght = c.lenght( );

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

Which method is used in an ArrayList to show the lenght?

A

ArrayLists have a method that is call size. It shows the lenght of an array. In the arraysList ‘size’ is a method not a property as lenght is in arrays.

Example:

ArrayList l = new ArrayList( );
int lenght = l.size( );
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are characteristics of an array?

A
  1. An array has a fixed size.
  2. An array allows multiple dimensions.
  3. An array is ordered.
  4. An array is NOT immutable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What arrays use for comparisons?

A

Arrays use object equality while doing comparison. i.e: equals.

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

What result is generated if a binary search is done for an unsorted array?

A

To do a binarySearch an array must be previously sorted to get a meaningful result, otherwise an undefined result is thrown.

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

What are characteristics of an ArrayList?

A
  1. An arraylist can change size.
  2. An arraylist is ordered.
  3. An arraylist is not immutable.
  4. An arraylist can have multiple dimmensions.
  5. ArrayLists implement equality that means same elements in the same order.

== refers to same objects.

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

Can primitive values be assigned to an array list?

A

Primitive values cannon be assigned to a list. For example:

List weights = new ArrayList;

You can see if there is an object because of the capital letter –> Double

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

Does period allow chaining?

A

Period does not allow chaining. If chaining is present, just the last value in the chain is taken.

Example:

LocalDateTime.of(2015, 5, 10, 11, 22, 33);
Period p = Period.ofDays(1).ofYears(2);
System.out.println(f.format(d));

17
Q

What are the 2 main uses of wrapper classes?

A

There are mainly two uses with wrapper classes.
1) To convert simple data types into objects, that is, to give object form to a data type; here constructors are used.

2) To convert strings into data types (known as parsing operations), here methods of type parseXXX() are used.

18
Q

What the features of the Java Wrapper Classes?

A

Features of the Java wrapper Classes.

1) Wrapper classes convert numeric strings into numeric values.
2) The way to store primitive data in an object.
3) The valueOf() method is available in all wrapper classes except Character
4) All wrapper classes have typeValue() method. This method returns the value of the object as its primitive type.

19
Q

What are the method access modifiers?

A

public - method can be called from any class.

private - method can be called from within the same class.

protected - method can be called from classes in the same package or subclasses.

default (Package Private) Access - The method can only be called from classes in the same package. There is no keyword for default access.