public boolean hasNext() {
return count<=capacity;
}
public Value next() {
v.set(count++);
return v;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
}
public static void main(String[] args) {
Values vs = new Values(10);
Value result = null;
for(Value v:vs){
if(result == null){
result = v;
}
else{
result.set(result.get()+v.get());
}
}
System.out.println(result.get());
}
}
a) 20 b)40 c)45 d)55 e)throws NullpointerException
8. If add keyword “final” before a class member function, it means:
a) The method can’t access the non-final member variable.
b) The method can’t modify the member variable.
c) The method can’t be override by subclass.
d) The method is a thread-safe function.
e) The method can’t be accessed by other non-final function.
9. About java memory and garbage collector, which statement is correct
a) Moving variable from locale to class will make GC more effectively.
b) When Full GC is executing, all the user threads will be paused.
c) If object A contains a reference of object B and object B contains a reference of object A, the two objects can’t be reclaimed by GC.
d) When a thread exits, all objects which created by that thread will be reclaimed
e) It is recommended that calling “System.gc()” to control the memory usage.
10. About java classpath and classloader, which statement is NOT correct
a) User can specify the classpath by using the option “-cp” in Java command line.
b) If user doesn’t specify classpath, the JVM search the class from the current folder by default.
c) A JVM can load two different versions of a library.
d) To define customized class loader, it is possible to load class from internet at runtime.
11. Which data structure has best performance when remove an element from it
a) Vector b)ArrayList c)LinkedList d)HashMap e)HashSet
12. Which is the correct way to convert bytes from charset “gb2312” to “utf-8”
byte[] src , dst;
a) dst = new String(src,”utf-8”).getBytes(“gb2312”);
b) dst = new String(src,”gb2312”).getBytes(“utf-8”);
c) dst = new String(src,”utf-16”).getBytes();
d) dst = new String(src).getBytes();
e) None of above.