Harder Java Cards Flashcards

1
Q

What are the primitive data types?

A

char, byte, short, int, long, float, double, boolean

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

Can a user define their own primitive data types?

A

No they cannot.

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

What is the printed when you use a variable of type char without initializing it (assuming that the declaration is an instance variable).

A

The default value of char is 0, which when printed, translates to an empty space.

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

When assigning a unicode value to a char variable, what is the allowed range?

A

‘\u000’ to ‘\uffff’

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

Can an identifier have the same spelling as a Java keyword?

A

Yes, but only if the case is changed, because Java is case sensitive. Int is a valid identifier, while int is not (because int is a reserved word).

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

Can a double variable be assigned to an int variable?

A

Yes, but only if the variable is cast to an int.

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

Can an int variable be assigned to a double variable?

A

Yes, and no casting is needed because Java widens the variable.

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

In what ways can an object of a wrapper class (i.e. Integer) be created?

A

By assigning a primitive to a wrapper class variable (autoboxing), by using the constructors of the wrapper class, and by calling the static method valueOf( ).

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

What wrapper classes define a constructor that accepts a String argument representing the value that needs to be wrapped?

A

All of them except for Character.

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

Which wrapper classes define a no argument constructor?

A

None of them.

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

What is autoboxing?

A

When a primitive value or variable is assigned to an reference variable of its wrapper type, Java automatically creates an object of that type and assigns its value to the primitive value passed.

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

What is unboxing?

A

When an object of a primitive wrapper class is converted to its corresponding primitive value.

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

How can you compare objects of wrapper classes for equality?

A

You can use the == operator because Java unboxes the wrapper objects into their corresponding primitives, and also use .equals( ) because it is overridden in all of the wrapper classes to compare the values of the objects passed.

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

What will happen if a wrapper reference variable that refers to null is unboxed?

A

Java will throw a RuntimeException of NullPointerException.

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

What happens to a char primitive when it is used as an operand to arithmetic operators?

A

Its corresponding ASCII value is used.

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

What is binding in the context of inheritance?

A

Binding refers to the resolving of variables or methods that would be called for a reference variable.

17
Q

When are instance variables bound?

A

At compile time.

18
Q

When are methods bound?

A

At run time.

19
Q

What is variable hiding?

A

Variable hiding happens when a variable is declared in a local scope that has the same name as one that exists in the outer scope.

20
Q

What happens when a child class defines a static method with the same signature as a static method in the parent class?

A

The child class method hides the parent class method.

21
Q

When talking about polymorphism, what is the difference between method hiding and method overriding?

A

Hiding methods only happens when the methods are static, and binding occurs at compile time, as static methods are not polymorphic. Overriding instance methods are bound at runtime.

22
Q

How is the Gregorian calendar system defined in the core classes in the Date-Time API?

A

ISO-8601 is defined as