• 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
What package is the Scanner class located in? What is the fully qualified name of the Scanner class?
java.util

java.util.Scanner
What is accomplished when you type “import java.awt.Color;” at the top of a file?
Whenever you type “Color”, the compiler knows that you are talking about the Color class that resides in the package called “java.awt”.
What is accomplished when you type “import java.awt.*;” at the top of a file?
You are importing EVERYTHING that is in the package java.awt.
Which java package is automatically imported in it’s entirety into every Java program you write?
java.lang
What method of the String class can be used to pick out one particular character in the string?
charAt
What method of the String class can tell you how many characters are in the String?
length
What method of the String class can be used to compare two Strings for alphabetical order?
compareTo
What method of the String class can select a portion of an existing String?
substring
What does API stand for?
Application Programming Interface
If someone showed you a Java class, how can you quickly identify which members were part of the API for that class?
everything that is public
If a member is declared as “public”, can it be accessed from inside the same class?
Yes
If a member is declared as “public”, can it be accessed from another class?
Yes
If a member is declared as “private”, can it be accessed from inside the same class?
Yes
If a member is declared as “private”, can it be accessed from another class?
No
What is a “getter”?
A method that returns the value of an instance variable of the object.
What is a “setter”?
A method that modifies the value of an instance variable of the object.
Explain why it is important to limit the number of “public” members.
Encapsulation of the fields (instance variables) of a class is very important. We frequently need to make changes to a class. If these changes do not modify the class API, then the modified class will work perfectly well within an existing project. However, if you modify the class in such a way that the API is changed, then you will have to re-program other components of the project so that they will work with the new class. By limiting the API we are free to make more extensive changes to the class without having to re-program other parts of the project.
Name and describe the two visibility specifiers that you should know at this point.
public – these members are visible everywhere

private – these members are visible only within the class
True/False – if you change a class in such a way that the API changes, then other classes which depend on this one will have to be re-coded.
True
True/False – if you change a class without modifying the API, then other classes which depend on this one will have to be re-coded.
False
True/False – in java, when you pass a reference variable as an argument to a method, it is possible for the method to modify the object to which the variable refers.
True
Assume that you have a class called “Stuff”, which contains the following method:

public static void eat(Cat c)

Show the syntax for a statement which will make a call to this method, passing in a brand new Cat object (without using a variable).
Stuff.eat(new Cat());
Is it better to write many small tests, or a few long ones?
Lots of small ones.
What is JUnit?
A useful feature of Java that allows us to quickly write “unit tests” for classes we are writing.
Give an example of the correct syntax for “assertEquals” and “assertTrue” in a JUnit test.
assertEquals(5, 2 + 3);

assertTrue(!“cat”.equals(“dog”));
If a JUnit test has several separate assertions in it, will the test continue after one of the assertions fails?
NO, but other tests will still run.
If a JUnit test suite has several different JUnit tests in it (separate methods), will the rest of the tests run after one of them fails?
YES.
What is a Stack (in general, not just in Java)?
A stack is a simple “linear” data structure in which elements are both inserted (“pushed”) and removed (“popped”) from the same end. (We usually picture the stack vertically, and say that we “push” and “pop” items from the top.)
When you push an entry into the stack does it go on the top or bottom?
Top
When you pop an entry from the stack, does it come off the top or bottom?
Top
If you do not write any constructors, what values will instance variables of the following primitive types be assigned: int, double, boolean, char ?
0, 0.0, false, ‘\0’
If you do not write any constructors, what values will instance variables that are references by assigned?
null
Under what circumstances will Java provide a default constructor for you automatically?
If you don’t write ANY constructors, Java will give you a default constructor automatically.
What is a copy constructor? Give an example.
The copy constructor accepts an argument that is the same type as the object being constructed. It initializes the fields of the current object to match that of the parameter. Example:



public Cat(Cat x) {

numWhiskers = x.numWhiskers;

name = x.name;

}
In what kind of methods does it make sense to use “this”?
Instance methods only.
What does “this” refer to?
“this” is a reference to the current object
How many ints are created by the statement: int[] a = new int[5];
5
How many Strings are created by the statement: String[] a = new String[5];

(Hint: The answer to this question and the previous question are different!)
None. What is created is an array of null-references.
Are the elements of an array of primitives automatically initialized? If so, to what values?
Yes, to 0 or false.
Are the elements of an array of references to objects initialized? If so, to what values?
Yes, to null.
Define the terms mutable and immutable.
A mutable class has a public method (not a constructor) that can be used to change the State of the current object.

Any class that is not mutable is called immutable.
Are String objects mutable?
No
Are Integer objects mutable? (If you’re not sure, inspect the online API documentation and find out!)
No
True/False – Aliasing can lead to problems if the object is mutable.
True
True/False – Aliasing can lead to problems if the object is immutable.
False.
Suppose you are passing (or returning) an array of primitives to/from a method. Is it safe to make a reference copy only?
No
Suppose you are passing (or returning) an array of references to immutable objects to/from a method. Is it safe to make a reference copy only? Is it safe to make a shallow copy?
Reference copy is unsafe. Shallow is safe.
Suppose you are passing or returning an array of references to mutable objects to/from a method. Is it safe to make a reference copy only? Is it safe to make a shallow copy?
Neither one is safe. Only a deep copy is safe in this case.
What is a Java interface?
Typically, it is just a collection of method prototypes that are implemented by several related classes.
What is polymorphism?
Sometimes a single variable can refer to objects of different types. For example, if you have an interface called “CanFly”, then you can create a variable of type “CanFly” which can refer to any kind of object that knows how to fly. (In other words, it can refer to an object of any class which implements the “CanFly” interface.) This kind of variable is “polymorphic”.
What is meant by the term “algorithm”?
A sequence of instructions or steps that can be followed in order to solve a relatively simple well-defined problem. Frequently there are many different known algorithms for solving a problem.
Explain the relationship between exception handling and the call stack. What happens if an exception is thrown but not caught anywhere in your program?
When an exception is thrown, Java looks for an appropriate “catch” block in the place where the problem occurred. If a catch is not found there, then Java discards the current frame on the call stack, and looks for an appropriate catch block in the previous frame. If none is found, that frame is discarded, etc. If the exception is not caught anywhere, then the program terminates, and the exception propagates to the “outside world”, which for us is the Eclipse IDE. Eclipse displays that red and blue error notification with stack trace in the console.
Under what circumstances will the finally block run?
The finally block ALWAYS runs.
What does “overloading” mean?
Writing more than one method in the same class with the same name. (This only works if the signatures of the

methods are different – i.e. the parameter lists have different types.)
Where can you use a “continue” statement?
Inside of any loop.
Describe how a continue statement behaves in a while loop.
Goes to top of loop immediately and checks the boolean condition to see if looping should continue.
Describe how a continue statement works in a for-loop.
It will execute the statement that is usually processed at the end of an iteration through the loop, and then check the boolean condition to see if looping should continue.
Where can you use a “break” statement?
Either in a switch statement or in a loop.
Describe how a break statement behaves.
Causes the inner-most loop or switch statement to be exited immediately.