SCJP 8 Flashcards

Terms Definitions
can abstract methods be private?
no
Which one is threads-safe, StringBuffer or StringBuilder?
StringBuffer
name class modifiers
final, abstract or strictfp
access modifiers
public private protected packagepublic private protected packagepublic private protected packagepublic private protected packagepublic private protected packagepublic private protected packagepublic private protected packagepublic private protected packagepublic private protected packagepublic private protected packagepublic private protected packagepublic private protected package
What is the output of:class AddBoxing { static void go(Integer x) { System.out.println("Integer"); } static void go(long x) { System.out.println("long"); } public static void main(String[] args) { int i=5; go(i); }}
long
Which is an access member modifier: protected or static?
protected
can a class implementing an interface declare any new runtime exceptions for an implementation method?
yes
Overriding
methods with same name but different implementation
True or False. Threads that are blocked/sleeping/waiting are considered alive.
True
True/False - If a superclass is Serializable, then according to normal Java interfacerules, all subclasses of that class automatically implement Serializable implicitly.
True (pg468)
T/F: The following is a legal identifier:int $c;
T(p. 5)
what can have synchronized modifier?
method, code block only
To see how to implement the second type of the anonymous classes look in the middle of 677
NA


What is the output of the following code?
 
String x = "01234567";
System.out.println(x.length() );
returns 8p436
Name some Nonaccess Member Modifiers (there are at least 7)
final, abstract, transient, synchronized, native, strictfp, and static (p. 39)
Define coupling
 
The degree to which one class knows about another class. (Ref: p. 152)
what is the syntax of a var-arg param
doStuff(int... x);
Look at the last paragraph on page 667 and top of 668
NA
Which exam watch is important?
The one on page 708
T/F: An method signature may be legal (and compile) even if it violates JavaBeans standards.
T (p. 10).
who must implement an abstract classes abstract methods?
the first concrete subclass
For an example to see how can wait be passed a number, look at the bottom of page
751
How can one use the java.util.Scanner class to search data?
Instantiate a Scanner instance, passing in the data to be searched, and then call its findInLine() method, passing in the data to search for:Scanner s = new Scanner("search me");String token = s.findInLine("a"); //put the above in a loop for searching the entire string.(p. 501)
Which of the following is not a keyword? (Choose one)a. whileb. nextc. natived. strictfpe. goto
b. next (p. 6)
What's the difference between overloading and overriding?
An overloaded method is a completely different method (just reuse of the method name). It must have a different parameter list than the method it is overloading and it may or may not have a different return type.Overriding's goal is to change the method implementation and overriding methods must have the same definition; that is, the parameter list must be exactly the same and the return type must be of the same type or a covariant.(p. 127 & 128)
When using wait(), what are two important points to remember when it comes to coding?
to use try/catch blocks. InterruptedException. Also, to syncrhonize the block that calls wait on an object
List the five options available for the conversion characters of the format string
b booleanc chard integerf floating points string(p. 508)
T/F: JavaBeans naming standards allows for non-public method signatures.
False - getter and setter method signatures must be marked public.(p. 9)
how many copies of a static variable are there?
one, all instances share it
What does sleep() do?
It dlows your thred down by forcing it to go into a sleep mode before coming back to Runnable
What is the output?static void main(){ int x[4] = new int[4]; x[3] = 1; x[0] = 1; x[2] = 7; x[1] = 5; for (int i=0; i { System.out.println(" " + x[i]); }}
Does not compile. int x[4] is not legal.
public abstract class SomeClass{  void someMethod() {    // Code  }}
Will this code compile?
Yes - You can have an abstract class with no abstract methods. (pg 42)
Which of the following are invalid constructors and why?a.) void Foo() { }b.) private Foo() { }c.) final Foo() { }d.) Foo() { }
a - constructors dont have return typesc - constructors cant be finalpg48
True or False. You can overload run()
True. But then calling this method will be like calling any other method in the class. Execution will happen on the same call stack. For an example look at top of 706
In what order will the following happen?*What special case will cause a different order?Typically when the first line of the static main method creates an instance of the parent class:1) Parent’s Static Initialization blocks2) Child’s Static Initializ
Answer: 1,3,5, *If the main method is imbedded in the child object then the order would be:1,2,3,5pg(234-237)
What argument is passed to the String.split() method, and what does the method return?
One passes a regex expression to the method, and the method returns an array of Strings containing the tokens produced by the split process.String[] tokens = "StringToSplit".split("regEx");(p. 502/503)
Can a subclass inherit a private member from it's superclass?
No, when a member is declared private, a subclass can't inherit it.
class Clothing { Clothing(String s) { }}class TShirt extends Clothing { }Choose one of the following:a. This code will run without errorsb. This code will have a runtime error.c. This code will have a compiling error.
c.  The superclass Clothing does not have a no-arg constructor.  You must type a constructor in the subclass or you will get a compiling error (pg 138)
Are the sleep() and yield() methods static or non-static?
they are static. And they affect the currently running thread. so t.sleep() or t.yield() does not affect thread t. They affect the currently running thread.
How do you create a String that uses a double quote or a backslash?
Escape the character within the string:System.out.println("\" \\");prints:" \(p. 504)
What is the difference between the access controls protected and default?
A default member of one class may only be accessed by classes within the same package.  Protected members, may additionally be accessed by classes extending the member's declaring class, regardless of the package.
Every class that's loaded in Java, has a java.lang.________ instance that corresponds to this class. What is so special about this instance?
Class. The lock of this instance is the one to be acquired when syncrhronizing static methods
The following code will compile:import java.util.*;import java.text.*;class TestCalendar{ public static void main(String[] args) { Date now = new Date(); //(1) Locale locPT = new Locale("it"); //(2) Calendar c = new Calendar(); //(3) NumberF
a, b, d, e. "c" is false because it needs to be declared like the following: Calendar c = Calendar.getInstance(); (pg477)
how many classes can a souce code file have?
only ONE public class. name must match file name.
So if you are to explain the p (the reference variable), what would you say?
it's a reference that refers to an instance of popcorn, but an instnace of an anonymous class (subclass of Popcorn)
/ 45
Term:
Definition:
Definition:

Leave a Comment ({[ getComments().length ]})

Comments ({[ getComments().length ]})

{[comment.username]}

{[ comment.comment ]}

View All {[ getComments().length ]} Comments
Ask a homework question - tutors are online