• 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/25

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;

25 Cards in this Set

  • Front
  • Back
  • 3rd side (hint)
protected class A {
}
How would compiler generated constructor look?
protected A() {}

the access modifier for constructor generated by compiler is the same with as that of the class
Describe algorithm for GC in Java
Garbage collection might be implemented differently depending on particular JVM ( mark and sweep, reference counting, etc. )
Would the following compile:
public enum eFruits {
eFruits( MyColor color ) { col = color; }
ORANGE(MyColor.ORG), APPLE(MyColor.GREEN), GRAPEFRUIT(MyColor.YELLOW);
MyColor getColor() { return col; }

private MyColor col;
}
No. In enums methods should be declared after elements declarations.
Is it possible to change Locale settings of particular DateFormat object after it's instantiation?
No. You cannot change the Locale of DateFormat after it's creation. It leads to compiler error.
Assign true/false to the statements below:
a) Anonymous inner classes (AIC) cannot have any `extends` or `implements` clause;
b) A non static inner class may have static members;
c) AIC can be creater either for interfaces or classes;
d) AIC cannot be static;
e) AIC can have initialization parameters if the class they extend has a corresponding constructor;
a) false;
b) true;
c) true;
d) false;
e) true;
Put the following parts of printf basic syntax in a right order:

a) [flags]
b) [.precision]
c) [arg_index$]
d) %
e) conversion char
f) [width]
Correct order is:
d) c) a) f) b) e)

%[arg_index$][flags][width][.precision]conversion char
What does flags below stand for:
a. "-"
b. "+"
c. "0"
d. ","
e. "("
a. "-" Left justify this argument - Must specify width as well.
b. "+" Include a sign (+ or -) with this argument - Applicable only if conversion char is d or f (i.e. for numbers).
c. "0" Pad this argument with zeroes - Applicable only if conversion char is d or f (i.e. for numbers). Must specify width as well.
d. "," Use locale-specific grouping separators (i.e., the comma in 123,456) - Applicable only if conversion char is d or f (i.e. for numbers).
e. "(" Enclose negative numbers in parentheses - Applicable only if conversion char is d or f (i.e. for numbers).
Should you use the full qualified name of enum element when using it in "case" clause of switch statement?
No. When using enums in switch statement, value in the case should be unqualified ( doesn't include enum name );
What would be the result of compiling and running the source below:
if(b2 != b1 = !b2)
{ System.out.println("true"); }
else
{ System.out.println("false"); }
It doesn't compile, because boolean operators have more precedence than =. (In fact, = has least precedence). in (b2 != b1 = !b2) first b2 != b1 is evaluated which returns a value 'false'. So the expression becomes false = !b2. And this is illegal because false is a value and not a variable;
What would be the result of compiling and executing the "test" method in the source below:
static class Test {
Test getInstance() {
return null;
}

static String getName() {
return "DummyTest";
}
}

static class Tester
{
static void test( String []args ) {
Test obj = new Test();
System.out.println( obj.getInstance().getName() );
}
}
It will compile, run correctly and print "DummyTest".
It's perfectly legal to use null reference of some class to access it's static variables or methods, because instance state doesn't matter at all.
What would be matched by regex:
(\s|\b)0[xX][0-9a-fA-F]+(\s|\b)
in string:
"dad 0x3A 0X5fq 0x3"
Captures all Hex numbers that are delimited by at least one whitespace at either end:
" 0x3A "
" 0x3"
\b means word boundary. By using (\s|\b), we are saying that the number can either start with a space or the number could be at a word boundary.
public class TestClass
{
// insert declaration of a native method here
}

which of the following is correct,

1. native public void nativeMethod(int i);
2. private native void nativeMethod(int i);
3. protected int native nativeMethod();
4. public abstract native void nativeMethod(int i);
5. native int nativeMethod(int i) {}
Two simple rules:
native methods cannot be abstract.
native methods cannot have a body.
Other than that ntive methods follow the same rules as for regular methods.

1. native public void nativeMethod(int i);
Ok
2. private native void nativeMethod(int i);
Ok
3. protected int native nativeMethod();
NG. Should be protected native int nativeMethod();
4. public abstract native void nativeMethod(int i);
NG. Cannot be abstract and native at same time. Remove abstract.
5. native int nativeMethod(int i) {}
NG. Cannot provide implementation here. It should come from native library.
What would be in output for the code below:
//In File Test.java
package testPackage;
import other.*;
class Test
{
public static void main(String[] args)
{
String hello = "Hello", lo = "lo";
System.out.print((testPackage.Other.hello == hello) + " "); //line 1
System.out.print((other.Other.hello == hello) + " "); //line 2
System.out.print((hello == ("Hel"+"lo")) + " "); //line 3
System.out.print((hello == ("Hel"+lo)) + " "); //line 4
System.out.println(hello == ("Hel"+lo).intern()); //line 5
}
}

class Other { static String hello = "Hello"; }
true true true false true

These are the six facts on Strings:
1. Literal strings within the same class in the same package represent references to the same String object.
2. Literal strings within different classes in the same package represent references to the same String object.
3. Literal strings within different classes in different packages likewise represent references to the same String object.
4. Strings computed by constant expressions are computed at compile time and then treated as if they were literals.
5. Strings computed at run time are newly created and therefore are distinct. (So line 4 prints false.)
6. The result of explicitly interning a computed string is the same string as any pre-existing literal string with the same contents. (So line 5 prints true.)
Which variables of the encapsulating class, can an inner class access if the inner class is defined in a static method of encapsulating class?
All static variables
All final automatic variables
IO API:
a) How can you determine whether File object is directory?
b) Which method returns an array of strings naming the files and directories in the directory denoted by File abstract pathname?
c) Which method returns an array of abstract pathnames denoting the files in the directory denoted File abstract pathname?
d) How can you check whether abstract filename is representing a file ( and not a directory )?
e) How can you rename particular file by using File class methods?
a) The isDirectory() method returns true if the file object represents a directory;
b) String[] list();
c) File[] listFiles() ;
d) isFile() method returns true if the file object represents a normal file;
e) renameTo(File newfile) renames the file to newfile.
Which of these methods are defined in the Map interface?

a) contains( Object o )
b) remove( Object o )
c) values()
b) and c)

Map also defines:
containsKey(Object o),
containsValue(Object o)
Does code below compile and run correctly?
static public long main( String... args ) { return 42; }
No. The main method should return nothing, eslewhere it would lead to java.lang.NoSuchMethodError to be thrown at load time.
What happens when you try to compile and run the following class:

public class TestClass
{
public static void main(String[] args) throws Exception
{
int a = Integer.MIN_VALUE;
int b = -a;
System.out.println( a+ " "+b);
}
}
It prints: -2147483648 -2147483648

This happens because negative integers are stored in 2's complement form (complement the bits and add 1). For example:

Integer 1 in binary is 00000000 00000000 00000000 00000001 (32 bits)

So -1 in binary would be (complement the bits for 1 and add 1) :

Step 1 (complement the bits of 1): 11111111 11111111 11111111 11111110
Step 2 (add 1 to step 1): 11111111 11111111 11111111 11111111.

Now, let's see what happens in this question:

a = Integer.MIN_VALUE = 10000000 00000000 00000000 00000000

To get -a, apply the above two steps:

Step 1 (complement the bits): 011111111 11111111 11111111 11111111
Step 2 (add 1) : 10000000 00000000 00000000 00000000

So you got the exact same value that you started with!

(Note that you can see the binary form of an integer using Integer.toBinaryString(i) method.)
Describe the result of the compiling and executing of the code below:

static class Test
{
static void test() {
String[] strArr = { "a", "b", "c" };
List<String> dogList = Arrays.asList( strArr );
System.out.println( dogList );

List<String> cloneList = new ArrayList<String>( dogList.size() );
for( String elm: dogList )
cloneList.add( elm );
strArr[0] = "e";
System.out.println( dogList );
dogList.set( 0, "q" );
dogList.add( "stuff" );
System.out.println( dogList );
for( String s: strArr )
System.out.println( s );
System.out.println( cloneList );
cloneList.add( new String("Whatever!") );
System.out.println( cloneList );
}
}
Runtime exception. The line below leads to the exception because current list is backed by the array:
dogList.add( "stuff" );

Arrays.asList() returns fixed-sized list backed with array, so adding elements to it is prohibited and results into run-time exception.
hint: backed array
Describe the result of the compiling and executing of the code below:

static class Test
{
static void test( String []args ) {
TreeMap<String,Integer> myMap = new TreeMap<String,Integer>();
myMap.put( "ak", 50 ); myMap.put( "co", 60 );
myMap.put( "ca", 70 ); myMap.put( "ar", 80 );

NavigableMap<String,Integer> myMap2 = myMap.headMap( "d", true );
myMap.put( "f1", 90 );
myMap2.put( "cz", 100 );
myMap2.put( "hi", 100 );
System.out.println( myMap.size() + " " + myMap2.size() );
}
}
Runtime exception. The line below causes IllegalArgumentException: key out of range to be thrown:
myMap2.put( "hi", 100 );

Exp: head or tial submap backed with main map can't be extended with keys out of the range specified at the stage of it's initialization.
hint: backed maps, boundaries
Name immutable built-in types in Java
Strings and Wrappers
What is yield() method designated for?
yield() forces running thread to step back & make scheduler to decide which thread should run
Name default delimiter for Scanner
default delimiter for Scanner is space ( not comma )
Which of the following classes can be instantiated using new keyword:

a) Date;
b) NumberFormat;
c) DateFormat;
d) Calendar.
Only a) Data & d) Calendar.
Name widening, narrowing, autoboxing, unboxing rules
primitives can be widen and narrowed and autoboxed, wrappers can't be widen & narrowed, but can be unboxed