• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/59

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

59 Cards in this Set

  • Front
  • Back

The bytecode for a class named Hello in the a.b.c package must appear in what directory structure?

The file Hello.class must be in the subdirectory a/b/c

What is the most common signature of a main () method?

public static void main (String [] args)

An instance of a class is a(n) _________

Object

What order do the class declarations, import statement, and package declaration go within a file?

1-The package declaration


2- imports declaration


3- Class declaration

What is the name of the method that guarantees the garbage collector will run?

Trick question! System.gc ( ) suggests that the garbage collector run but does not guarantee it.

True of false: The finalize method of an Object may be invoked multiple times.

False. The finalize method can be invoked at most once.

Is this a constructor or a method? public void MyClass ( ) { }

It is a method because it has a return type.

Are instance initializers run before or after constructor?

Before. Instance initializers are blocks of code that are run before the constructor.

Order the following operators in decreasing order of precedence: ||, ==, *

*, == , ||

How many default statements can a single switch statement have?

A switch statement may have at most one default statement.

How many case statements can a single switch statement have?

Barring any VM limits, there is no limit to the number of case statements that a switch statement can have, provided the constant value of each case statement is unique.

Why should you be careful when evaluating the right-hand side of expressions that include && and || ?

The right-hand side of short-circuit operators will not be evaluated if the value can be determined solely from the left-hand side.

True or false: ( 5 <= 7) || ( 2 < 0 )

True

True or false: A case must be a constant expression.

True

True or false: The collection in a for-each loop must be an array.

False. it can be an array or an object that implements java.lang.Iterable.

A______________statement transfers flow of control out of an enclosing statement.

break

A______________statement within a loop transfers flow of control to the loop continuation point of the loop.

continue

What is the command line used to compile the Java class Wolf.java and what file does it generate?

Run: javac Wolf.java (and it generates Wolf.class)

What is the command line to run the program contained Wolf.class?

java Wolf

Write a line of code to print the number of elements passed into this method: public void method(double ... d)

System.out.println( d.length );

How many arrays are created in this code and how many dimensions in each one?


int [ ] b, c [ ];

Two. b is a one dimensional array and c is a two-dimensional array.

What is returned by the following search?


int [ ] numbers = { 2 , 4, 6, 8 }; Arrays.binnarySearch (numbers, 5);

-3. The number isn't found but would be inserted at index 2 to preserve sort order. Remember that we negate that number and subtract 1 to get the answer.

Write code to print the number of elements in an ArrayList named abc.

System.out.println( abc.size ( ) );

What is the < > called in :


List a = new ArrayList <> ( );?

The Diamond operator

What method do you call on a ArrayList to insert an element after all current elements?

add ( )

What method do you call on an ArrayList to replace the element at a given index with a different one?

set ( )

What is the process called when Java automatically converts an int to an Integer?

Autoboxing

What package are the new date/time classes in?

java.time

What are the three key local date and time classes and what do they represent?

LocalDate is just the date without time without time or time zone. LocalTime is just the time without date or time zone. LocalDateTime is the date and time without time zone.

How do you create an object with current date and time?

LocalDateTime.now ( );

How do you add an hour to a LocalTime object?

LocalTime.plusHours(1) ;

How do you create a Period of a month and a day?

Period.of (0, 1, 1);

What is the class used for formatting a date?

DateTimeFormatter

True or false: An instance method is allowed to reference a static variable

True

True or false: A static method is allowed to reference a instance variable

False (except through a reference to a class instance)

Write a static import to import the static LENGTH variable of a.b.c

import static a.b.c.LENGTH; or import static a.b.c.*;

True or false: Overload methods have the same method signatures

False. The parameter lists must be different.

Which of the following may be different in an overloaded method: method name, return type, accesss modifier, exception list?

return type, access modifier, and exception list may vary. If the method name was different, it would be different method rather than an overloaded method.

Which order does Java use when looking for matches in overloaded methods: autoboxing, exact match, widening primitives, varargs.

Exact match, widening primitives, autoboxing, varargs.

True or false: When passing an ArrayList list to a method, calls to list.add ( ) from the method are reflected in the caller.

True. The caller points to the same object as the method parameter.

True or false: When passing an ArrayList list to a method, calling list = new ArrayList ( ) from the method affects the caller.

False. Parameters are passed by reference so reassignments do not affect the caller.

True or false: A default constructor is always provided in a class.

False. A default constructor is only provided if none are coded.

How do you call one constructor from another in the same class?

this ( )

What interface does Java provide for working with lambdas that declares a single method that returns a boolean?

predicate

Which Characters in this statement are optional (a) -> { return true; }

The parantheses, braces, return statement, and semicolon. It could have been a -> true.

Which characters in this statement are optional? ( ) -> { System.out.println ( ) ; return true; }

None. The parentheses are required when there aren't any parameters. The braces are required because there are multiple statement.

What type would be used for a method parameter if it needed to be able to support any variable?

java.lang.Object

What is the difference between overloading, overriding, and hiding a method?

Overloaded methods share the same name but different signatures and have no polymorphic relationship.


Overridden methods share the same signature and are replaced at runtime in all places it is defined. Hidden methods share the same signature but are only replaced in the subclasses for which they are defined.

Why can an abstract method not be marked final?

By abstract, the method cannont be instantiated directly and must be implemented by a subclass. By marking the method final, no subclass can implement it. Therefore no concrete subclass could be created that includes the method.

True or false: An abstract class that implements an interface is not required to implement any of the interface's abstract methods.

True.

What is one reason default methods were added to interface in Java 8?

To improve backward compatibility. Interface developers can add a new method to an interface without requiring developers using the interface to recompile thier code.

True or false: All methods in Java are virtual methods.

False. Only nonfinal, nonstatic, and nonprivate methods are virtual in Java.

How would you override a private method in Java?

You cannot override a private method, although you can replace it by hiding it.

When do you need to explicitly call super () in your constructor?

When the parent class does not define a no-argument constructor.

True or false: if a parent class does not include a no-argument constructor, the child class cannot declare one.

False

If you have a constructor that calls another constructor in the same class, which should be used first, this ( ) or super ( )?

Only this ( ) would be used in the constructor. The second constructor (super ()) would call the parent constructor itself.

Define a covariant return type.

When a method in a child class overrides a method in a parent class, the return type is permitted to be a subclass of the return type of the method defined in the parent class.

If the try block, catch block, and finally block all throw an exception, which gets thrown to the caller

The one from the finally block

True or flase: If a try statement has catch blocks for IllegalArgumentException and RuntimeException, the catch blocks can be in either order.

False. The more general catch blocks must appear below the more specific ones.