APIs Flashcards

1
Q

What class represents a date without any time or time zone information.

A

java.time.LocalDate

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

What classes did java.time replace in Java 8?

A

java.util.Date

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

Are the following classes thread safe: LocalDate, LocalTime, LocalDateTime, Instant, Period, and Duration.

A

Yes, they are also immutable.

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

What are temporal adjusters?

A

A key tool for adjusting time objects.

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

T/F: Literal strings within the same class in the same package represent references to the same String object.

A

True.

Same with literal strings in different classes in the same package and literal strings within different classes in different packages.

They all represent references to the same object.

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

When are strings computed by constant expressions computed?

A

At compile time.

This means they are then treated as if they were literals.

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

Would a string created at run time be the same as an already existing string literal of the same value?

A

No.

They are newly created and therefore distinct.

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

What will this print out?

String foo = null;
System.out.println(foo + “foo”);

A

nullfoo

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

Can any of the following classes be extended:

String, StringBuffer, and StringBuilder.

Boolean, Integer, Byte.

java.lang.System

A

No, they are all final.

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

Will Period mess with the time component of the date, particularly if near Daylight Savings Time?

A

No.

Duration may change it though.

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

What will the following code print?

        List s1 = new ArrayList( );
        try{
            while(true){
                s1.add("sdfa");
            }
        }catch(RuntimeException e){
            e.printStackTrace();
        }
        System.out.println(s1.size());
A

Nothing. It will throw an error at runtime that will not be caught by the catch block.

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

Are arrays and ArrayList thread safe?

A

No.

If you have multiple threads trying to add and remove elements from an ArrayList or an array, you have to write additional code to ensure thread safety.

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

What is the best way to find out if two Strings are equal?

A

Use String’s equals( ) method.

Note: equalsIgnoreCase( ) may be used to trick you because it returns the same letter, but not character. (‘A’ is not the same character as ‘a’.)

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

How long of a period will the following code return?

LocalDate ld2 = ld.plus(Period.ofMonths(1).ofDays(1) );

A

One day.

Even though previous chained method call ofMonths( ) returned a period of one month, since ofDays( ) is a static method, it will only return one day.

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

Is the length( ) method of the String class final?

A

Yes.

In fact, String is final. So, all methods are implicitly final.

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