中级农民
- 积分
- 109
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2011-4-8
- 最后登录
- 1970-1-1
|
Java & oop
1. what is oop? what are the advantages of oop?
2. how to import packages in java? what if you import a package twice?
3. what is polymorphism? have you ever used polymorphsim in a project? Describe it.
4. how to implement a queue using stacks?
5. what is java generics?
Java Generic methods and generic classes enable programmers to specify, with a single method declaration, a set of related methods or, with a single class declaration, a set of related types, respectively.
A generic class is defined with the following format:
class name<T1, T2, ..., Tn> { /* ... */ }
Generics also provide compile-time type safety that allows programmers to catch invalid types at compile time.
6. what is the difference between abstract class and interface?
abstract Classes Interfaces
7. difference between final and finally
8. what is mutex?
When I am having a big heated discussion at work, I use a rubber chicken which I keep in my desk for just such occasions. The person holding the chicken is the only person who is allowed to talk. If you don't hold the chicken you cannot speak. You can only indicate that you want the chicken and wait until you get it before you speak. Once you have finished speaking, you can hand the chicken back to the moderator who will hand it to the next person to speak. This ensures that people do not speak over each other, and also have their own space to talk.
Replace Chicken with Mutex and person with thread and you basically have the concept of a mutex.
A Mutex is a mutually exclusive flag. It acts as a gate keeper to a section of code allowing one thread in and blocking access to all others. This ensures that the code being controled will only be hit by a single thread at a time. Just be sure to release the mutex when you are done
Mutex is basically mutual exclusion. Only one thread can acquire the resource at once. When one thread acquires the resource, no other thread is allowed to acquire the resource until the thread owning the resource releases. All threads waiting for acquiring resource would be blocked.
Semaphore is used to control the number of threads executing. There will be fixed set of resources. The resource count will gets decremented every time when a thread owns the same. When the semaphore count reaches 0 then no other threads are allowed to acquire the resource. The threads get blocked till other threads owning resource releases.
In short, the main difference is how many threads are allowed to acquire the resource at once ?
• Mutex --its ONE.
• Semaphore -- its DEFINED_COUNT, ( as many as semaphore count)
9. difference between int and integer in java
10. is java pass by reference or pass by value?
By value
11. can java garbage collection manually? how?
Yes, but not recommended. By call system.gc() which will call runtime.gc()
12. difference between JDK and JRE.
JRE: Java Runtime Environment. It is basically the Java Virtual Machine where your Java programs run on. It also includes browser plugins for Applet execution.
JDK: It's the full featured Software Development Kit for Java, including JRE, and the compilers and tools (like JavaDoc, and Java Debugger) to create and compile programs.
Usually, when you only care about running Java programs on your browser or computer you will only install JRE. It's all you need. On the other hand, if you are planning to do some Java programming, you will also need JDK.
13. what is static? 然后写了如下代码让我说输出是什么
static members belong to the class instead of a specific instance.
It means that only one instance of a static field exists[1] even if you create a million instances of the class or you don't create any. It will be shared by all instances.
Since static methods also do not belong to a specific instance, they can't refer to instance members (how would you know which instance Hello class you want to refer to?). staticmembers can only refer to static members. Instance members can, of course access staticmembers.
void func() {
static int x = 0;
printf(“%d\n”, x);
x = x + 1;
}
int main(int argc, char *argv[]) {
func();
func();
func();
return 0;
}
14. 关于java里的super关键字,可惜我记不太清楚了,大概写一下,如果我写错了,希望大家斧正
super class A{
foo();
}
class B extends A{. 1point3acres.com/bbs
foo();
bar();
}
int main{
A var = new B();
var.foo();
var.bar();
}
问这个foo和bar调用的是A的还是B的
15.Compare the time complexity of insertion and deletion between dynamic array and linkedlist. visit 1point3acres.com for more.
16. what is hashtable? what is the potential issue of hashtable?
Fixed size table of array
Constant time insertion
这个楼主没懂,就问了一句,他引导我从“garbage collection”上面去考虑,可惜楼主还是没想到
面完之后查了一下,似乎是想考hashtable当key被回收而value没有被回收的时候,会发生内存泄露。
17.difference between hashtable and hashmap in java
1. The HashMap class is roughly equivalent to Hashtable, except that it is non synchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesn't allow nulls).
2. HashMap does not guarantee that the order of the map will remain constant over time.
3. HashMap is non synchronized whereas Hashtable is synchronized.
4. 1) HashMap's iterators are NOT fail-safe. They are fail-fast. There is a huge difference in meaning between those two terms. 2) There is no set operation on a HashMap. 3) The put(...) operation won't throwIllegalArgumentException if there was a previous change. 4) The fail-fast behaviour of HashMap alsooccurs if you change a mapping. 5) The fail-fast behaviour is guaranteed. (What is not guaranteed is the behaviour of a HashTable if you make a concurrent modification. The actual behaviour is ... unpredictable.)
|
|