Tuesday, December 25, 2012

1. Java Basics

1. import statically

You cannot import a package or a Class statically.
You can only import static members or method of a class statically.
EX.
package x.y; //package must in front of import.
import static com.foo.X.*;
import com.foo.*;

2. You cannot directly invoke the garbage collector. You can suggest the JVM to perform garbage collection by calling System.gc();




3. 

Modifier    | Class | Package | Subclass | World
————————————+———————+—————————+——————————+———————
public      |  ✔    |    ✔   |    ✔    |   ✔
————————————+———————+—————————+——————————+———————
protected   |  ✔    |    ✔   |    ✔    |   ✘
————————————+———————+—————————+——————————+———————
default     |  ✔    |    ✔   |    ✘    |   ✘
————————————+———————+—————————+——————————+———————
private     |  ✔    |    ✘   |    ✘    |   ✘

4. Main() should be public

remember these standard expressions for declaring main():
1. final public static void main(String[] arg)
2. public static void main(String args[])
3. static public void mian(String...args)

5. Java identifier(s) cannot start with a digit.
2Next (X) 



3-2 
a.equals(b) throws an exception if they refer to instances of different classes.

3-3
+ is overloaded such that if any one of its two operands is a String then it will convert the other operand to a String and create a new string by concatenating the two.
plus sign '+' transforms int char into string

3-4 The following code snippet will not compile:
int i = 10;
System.out.println( i<20 ? out1() : out2() );

        Assume that out1 and out2 have method signature: public void out1(); and public void out2();  
3-5 (a instanceof b)
a: must not be a primitive
b: must be a Class


3-9
        The following types can be used as a switch variable:
byte, char, short, int, String, and enums.
Note that long, float, double, and boolean are not allowed.    



No comments:

Post a Comment