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;
27 Cards in this Set
- Front
- Back
What are the access specifiers? |
package public private protected |
|
How about class types |
Anonymous Inner Top Abstract |
|
Hashset vs. Treeset |
Hashset is not ordered, Treeset is ordered. Tresset add, remove and contains methods have O(logn) complexity. Hashset has O(1) complexity |
|
Difference between yield() and join() in threads |
* yield() - tell VM that willing to let other threads be scheduled in its place |
|
Vector vs. other collections? Why are collections better than vectors? |
Collections in the framework now use read locks as opposed to read/write locks |
|
What is the benefit of Generics at runtime (if any?) |
No typecasting required (typecasting requires JVM to look up class loaders) |
|
What are weak references and how do you use them? |
Use weak reference for a cache, for example. The JVM can free up the memory and you can get the data again if it goes away |
|
Stack vs. Heap? |
tbd |
|
Hashtable vs. Hashmap |
Hashtable is synchronized
HashMap can contain null values and keys, table cannot contain nulls at all |
|
Mechanisms for maintaining sessions? |
* URL rewriting (pose security risk) * Cookies (preferred) |
|
Servlet lifecycle methods |
* init() * service() --> doPost(), doGet() * destroy() {Called once} |
|
Can an interface contain a variable? |
Yes they can (but probably shouldn't!). If so, they must be static because interfaces cannot be instantiated.
Can, but doesn't require a final specifier |
|
Can you define an enum inside an interface? |
Yes! Moreover, you can define methods inside that enum which is inside the interface ;) |
|
What are the major differences between doPost and doGet. When to use which? |
doPost() - parameters passed inline and are encrypted. No maximum size for data! Slower b/c does not write content length. Does not have to be idempotent
doGet() - Params appended to URL. Faster. SHOULD BE IDEMPOTENT |
|
What does: Executor.execute(Runnable) do? |
Executes asynchronously |
|
What does Executor.submit(Runnable) do? |
Executes, returns Future object. You can use this object to check when the thread ends |
|
What does Executor.submit(Callable) do? |
Executes, returns Future object. The Callable implementation can return a value! |
|
Using executors, how can you track the return value of a thread method call? |
Use Executor.submit(Callable) [[Not submit(Runnable) ]]! |
|
What does Executor.shutdown do? |
The Executor service will not shut down immediately, but will no longer accept new tasks. Once all threads have finished current tasks, the ExecutorService shuts down. |
|
How can you terminate an Executor immediately? |
Executor.shutDownNow() |
|
Explain the access specifiers: * public * protected * private * default |
public - accessible by anyone protected - this class, or sub class private - only this class default - any class in this package |
|
What is a CountDownLatch? |
A kind of synchronizer which allows one Thread to wait for one or more Threads before it starts processing. (Not reusable once the count reaches zero!) Example: CountDownLatch latch = new CountDownLatch(3); latch.await(); // Main thread waits: // Each thread calls: latch.countDown() |
|
What is a CyclicBarrier |
CyclicBarrier is initialized with the number of threads to wait for the barrier. Once the barrier is reached by all threads, they will all process.
Each thread calls await(), then blocks. When all threads called await(), they all cross the barrier and continue processing |
|
What is the advantage of new Lock interface over synchronized block in Java? |
Lock method tryLock allows method to back out if the lock is not available immediately or before a timeout expires. - good for solving deadlock problem. Locks are not auto released like a sync block is. You need to explicitly release them (try-finally) |
|
What are the differences between sleep() and wait() |
sleep() is used for pausing. Locks are not released. wait() is used for inter-thread communication. Locks are released during a wait(). |
|
what is volitile? |
guarantees visibility of changes to variables across threads (ensures each thread gets the value from memory and not thread cache).
Should also use synchronize with these variables. |
|
Why we call start() method which in turns calls run() method, why not we directly call run() method ? |
calling start() will instantiate a new thread and call run. Calling run directly calls it on the current thread!! |