Chapter 3 - Core Java APIs Flashcards Preview

JAVA 8 OCA > Chapter 3 - Core Java APIs > Flashcards

Flashcards in Chapter 3 - Core Java APIs Deck (19)
Loading flashcards...
1

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

The java.util.List is an interface.

2

What does the set method does in a list?

Set: replaces an existing value.

Format:
list.set(index,value)

3

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

Convert a list to an array:
Object[ ] objectArray = list.toArray( );

4

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

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

5

Can a list size be changed?

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

6

Can the date and time classes be instantiated directly?

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

7

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

Passing invalid numbers to of( ) throws DateTimeException.

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

8

Are the date and time classes mutable or immutable?

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

9

Do arrays have a lenght method or property?

Arrays have a lenght property NOT a method.

Example:

char[ ] c = new char [2];

int lenght = c.lenght;

Instead of:

int lenght = c.lenght( );

10

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

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( );

11

What are characteristics of an array?

1. An array has a fixed size.

2. An array allows multiple dimensions.

3. An array is ordered.

4. An array is NOT immutable.

12

What arrays use for comparisons?

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

13

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

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

14

What are characteristics of an ArrayList?

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.

15

Can primitive values be assigned to an array list?

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

16

Does period allow chaining?

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

What are the 2 main uses of wrapper classes?

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

What the features of the Java Wrapper Classes?

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

What are the method access modifiers?

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.