Section 1

Preview this deck

Which of the following are interfaces to ArrayList? List, Map, Queue, RandomAccess, and Set.

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (82)

Section 1

(50 cards)

Which of the following are interfaces to ArrayList? List, Map, Queue, RandomAccess, and Set.

Front

List and RandomAccess are interfaces to ArrayList.

Back

Will this line compile without errors? Object [ ] obj = new Object ();

Front

Incorrect because they have () instead of [] after the type.

Back

When you pass a variable as an argument to a method call, what are you passing?

Front

A copy of the value. You always get a copy of whatever is in the variable - either a primitive or a reference. So for objects, you get a copy of the reference.

Back

What is the keyword transient?

Front

It marks a member variable not to be serialized when it is persisted to streams of bytes.

Back

Can a constructor be declared static?

Front

No, constructors are for creating new instance objects. Static methods are for non-instance code, so it makes no sense to have a static constructor.

Back

What will be printed? System.out.println("roberto".substring(3, 7));

Front

erto

Back

What access is the generated constructor given when one is not supplied?

Front

If the class is public, than it is public. Otherwise the default constructor is default.

Back

Can a constructor be declared private?

Front

Yes. This can be used to control the creation of the object by other less restrictive methods.

Back

Can a constructor have a synchronized modifier?

Front

No; they can never be synchronized.

Back

Are instance variables assigned a default value?

Front

Yes, member or instance variables are always given a default value.

Back

What will be printed? System.out.println("roberto".replaceAll("o", "!").substring(2, 6));

Front

bert

Back

Can a private method be overridden?

Front

No, but the can be re-declared in the subclass. This is not polymorphism.

Back

Can you compare a boolean to an int?

Front

No, booleans are true and false keywords and nothing else.

Back

What is the keyword native?

Front

The native keyword is applied to a method to indicate that the method is implemented in native code using JNI.

Back

Will this line compile without errors? double[ ][ ][ ] numbers = new double[ ][ ][ ];

Front

No. When the new operator is used, at least one array dimension in a multi-dimensional array must be given a size.

Back

What are the access specifiers in order of most restrictive to least?

Front

Private, Default, Protected, and Public.

Back

What does continue do?

Front

The continue statement skips the current iteration of a for, while, or do-while loop. The unlabeled form skips to the end of the innermost loop's body and evaluates the boolean expression that controls the loop. A labeled continue statement skips the current iteration of an outer loop marked with the given label.

Back

Will this line compile without errors? Object [3] obj = new Object [3]() ;

Front

Incorrect because the size is in the declaration and the extra () after the [] is not the correct syntax.

Back

Will this line compile without errors? Object obj [ ] = new Object [3]();

Front

Incorrect because the () after the [] is not the correct syntax.

Back

Will this line compile without errors? Object [7] obj = new Object [7];

Front

Incorrect because the size is not assigned when it is declared.

Back

What is the output of the following code segment? int value = 1; switch (value) { case 0: System.out.println("Dog"); case 1: System.out.println("Cat"); case 1: System.out.println("Fish"); default: System.out.println("Cow"); }

Front

This will not compile because it includes a case statement with the same value twice.

Back

Fill in the blank. Import statements are ______.

Front

Required in all versions of Java.

Back

What will be printed? System.out.println("roberto".replaceAll("o","!").substring(1, 6));

Front

!bert

Back

Will this line compile without errors? Object [ ] obj = new Object [ ];

Front

Incorrect because they do not assign a size to the array.

Back

What are the access levels in order of most restrictive to least?

Front

Class, Package, Sub class, and World.

Back

If break statements are not used in a switch, what will happen?

Front

Once a case statement is entered, the code will continue to execute in each case below it, until it hits a break statement.

Back

Will this line compile without errors? Object obj = new Object ();

Front

Yes.

Back

Can the access specifier for an overriding method allow more or less access than the overridden method?

Front

More. The access specifier for an overriding method can allow more, but not less, access than the overridden method.

Back

Will this line compile without errors? Object obj [ ] = new Object [7];

Front

Yes.

Back

Given: public void simpleTest () { int i; System.out.println(i); } What will occur?

Front

A compiler error will occur since the value has not been initialized.

Back

Will this line compile without errors? Object obj [ ] = {new Object [1], new Object [2]};

Front

Yes.

Back

Where can an anonymous inner class be defined?

Front

An anonymous class is an expression. So anywhere an expression is used.

Back

Will this line compile without errors? Object obj [ ] = new Object[ ] ;

Front

Incorrect because they do not assign a size to the array.

Back

Can a top-level class be marked as protected?

Front

No, a top-level class can only be marked public or default. The protected access is just for member variables and methods, and allows subclasses outside the superclass package to inherit the protected members.

Back

Will this line compile without errors? Object obj [] = new {new Object(), new Object()};

Front

Incorrect because the first new operator is being used with the {} initialization method.

Back

Will this line compile without errors? Object [ ] obj = new Object [3]();

Front

Incorrect because the () after the [] is not the correct syntax.

Back

Will this line compile without errors? Object [ ] obj = new Object [7];

Front

Yes.

Back

True or False - during arithmetic, when the operands or different types, the resulting type is always the widest of the two type.

Front

False, the result of an arithmetic operation on any two primitive operands will be at least an int -- even if the operands are byte and short.

Back

Can a class be declared as final?

Front

Yes, a class can be declared final; that is, the class cannot be sub-classed. This is done for security and design.

Back

What best describes the result of the following code segment? The ArrayList sampleArrayList has already been declared and initialized. int i = 63; sampleArrayList.add(i);

Front

The int is converted to an Integer via auto boxing and then placed into the ArrayList. Primitives cannot be stored in an ArrayList. However, if they are placed into their primitive wrapper class they can be stored. Java will automatically make that conversion via its autoboxing feature if a primitive is placed into an ArrayList.

Back

What is the difference between the default and protected access specifier?

Front

Default does not allow sub class access. Both allow package access.

Back

Will this line compile without errors? Object obj [ ] = {new Object(), new Object()};

Front

Yes.

Back

Will this line compile without errors? double[ ][ ][ ] numbers = new double[7][ ][ ];

Front

Yes.

Back

Does each source file need a public class in it?

Front

No.

Back

What does break do?

Front

The break statement has two forms: labeled and unlabeled. An unlabeled break statement terminates the innermost switch, for, while, or do-while statement, but a labeled break terminates an outer statement.

Back

What will be printed? System.out.println("roberto".replaceAll("o", "!").substring(1, 7));

Front

!bert!

Back

Will this line compile without errors? Object obj [ ] = new Object() ;

Front

Incorrect because they have () instead of [] after the type.

Back

Can overriding methods throw different exceptions than that of the super?

Front

Overriding methods cannot throw any new or broader exception that is checked. Unchecked does not apply.

Back

Will this line compile without errors? double[ ][ ] numbers = {{1,2,3},{7,8},{4,5,6,9}};

Front

Yes.

Back

Will this line compile without errors? Object [8] obj = new Object [ ];

Front

Incorrect because the size is not assigned when it is declared.

Back

Section 2

(32 cards)

InterruptedIOException is a subclass of?

Front

IOException

Back

IllegalAccessException is a subclass of?

Front

ReflectiveOperationException

Back

NoSuchMethodException is a subclass of?

Front

ReflectiveOperationException

Back

Which lines will not compile? Integer luckyNumber = 66; System.out.println(luckyNumber.booleanValue()); System.out.println(luckyNumber.charValue()); System.out.println(luckyNumber.byteValue()); System.out.println(luckyNumber.shortValue()); System.out.println(luckyNumber.longValue()); System.out.println(luckyNumber.floatValue()); System.out.println(luckyNumber.doubleValue());

Front

Lines two and three will not compile, because you cannot convert the Integer wrapper class to a boolean or char primitive. For the Integer class, the methods booleanValue and charValue do not exist.

Back

ClassNotFoundException is a subclass of?

Front

ReflectiveOperationException

Back

Which method of the Stringbuilder class attempts to reduce storage used for the character sequence?

Front

The trimToSize method attempts to reduce storage used for the character sequence.

Back

True or False, octal literals must start with a 0.

Front

True

Back

True or False, octal literals can start with \u.

Front

False

Back

If a variable is cast to an invalid object, what is the effect?

Front

This will cause a runtime exception to be thrown.

Back

How can this interface be correctly implemented? public interface TestInterface { public boolean errorState(); }

Front

public class ClassX implements TestInterface{ public boolean errorState() { return false; } } An object can act as any interface it implements. and public class ClassX implements TestInterface{ private boolean errorState() { return false; } } An object can also act as any of its superclasses.

Back

What is the last value that is sent to standard out for x in the given code segment? int x=0; do{ x=x+2; System.out.println("x: " + x); }while(--x<5);

Front

x: 6 The do while statement will increment x by 2 each time through the loop, and then, before it checks the while condition, it will first decrement it by 1.

Back

Is this valid? Object [] o = {"Song Book", 35.95, new Guitar(), 6};

Front

Yes, it is fine to have subtypes as elements in an array of a supertype.

Back

Running out of Java heap memory is an example of what?

Front

Running out of heap memory results in a java.lang.OutOfMemoryError unchecked error.

Back

java.io.Serializable is a marker interface, also known as a tag interface. What is the unique attribute of marker interfaces?

Front

A marker interface includes no methods or fields.

Back

int b1 = 0b_0101_0101_0101_0101; int b2 = 0b_1010_1010_1010_1010; int b3 = b1 & b2; System.out.println("Value:" + b3); What will be the result?

Front

A compilation error will occur because an underscore cannot be used after the b in the literal. The other underscores are allowed.

Back

What is missing from the following multi-dimensional array declaration: int[][] array = int[10][10];

Front

The new keyword is needed to establish memory allocation.

Back

Which statement is correct? ArrayList d1 = new ArrayList(); ArrayList d2 = new ArrayList<>(); ArrayList<> d3 = new ArrayList<>(); ArrayList<Double> d4 = new ArrayList<>(); ArrayList<Double> d5 = new ArrayList<Float>();

Front

The declarations for d1, d2, and d4 are valid as they will compile.

Back

What version of Unicode is supported by Java SE 7?

Front

Unicode standard, version 6.0.0

Back

Java 7's Garbage-First (G1) garbage collector is planned as the long-term replacement of which collector?

Front

Java 7's Garbage-First (G1) garbage collector is planned as the long-term replacement of the Concurrent Mark-Sweep (CMS) collector.

Back

Will this compile? int ivar = 77; Integer integer = ivar;

Front

Primitives and their wrapper classes are automatically converted back and forth with autoboxing and auto-unboxing.

Back

Which access modifiers can be applied to constructors?

Front

Constructors can have package-private, private, protected, and public access modifiers applied to them.

Back

Which literal data types must be cast in order to work with an int data type?

Front

Literals of type long, float, and double must be explicitly cast to an int to be used with a variable of the type int.

Back

What is the new method of the Locale class to Java SE 7?

Front

The getUnicodeLocaleAttributes method was introduced to the Locale class in JDK 1.7 along with the getDefault, setDefault, getScript, getExtension, getExtensionKeys, getUnicodeLocalType, getUnicodeLocaleKeys, toLanguageTag, forLanguageTag, and getDisplay script. It's presented here to stress your need to be familiar with the Javadoc documentation of the Java API specification.

Back

True or False, octal literals can start with \x.

Front

False

Back

Is this valid? static final long APHELION = 152,097,701;

Front

Commas are not allowed in numeric literals, so a compiler error will occur.

Back

What is the value for the variable sum? int[][] sampleArray = new int[3][4]; for (int i = 0; i < 3; i++) { sampleArray[i][i+1] = 2; } int sum = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { sum += sampleArray[i][j]; } }

Front

4

Back

Can a member variable be declared synchronized?

Front

No, the keyword synchronized marks method code so that it cant be run by more than one thread at a time.

Back

What will be printed? System.out.println("roberto".replaceAll("o", "!").substring(2, 7));

Front

bert!

Back

If you want to define an unchecked exception, your exception must extend (directly or indirectly) which class?

Front

If you want to define an unchecked exception, your exception must extend the RuntimeException class.

Back

In the following code segment, how many times will an even number be sent to standard out? for(int x=0 ; x<10 ; x++){ if(x%2 == 0){ System.out.println("x: " + x + " - Even"); continue; } else{ System.out.println("x: " + x + " - Odd"); } x++; }

Front

1 time

Back

Is this valid? short s = 1000s;

Front

There is no s postfix.

Back

What is the primitive storage range of a byte?

Front

-128 to 127

Back