The following questions for a Java development position.
Q: What are the different ways to create a thread?
A:
1. Extend the Thread class
2. Implement the Runnable interface. Create a Thread object using an object of the Runnable type.
Q: On a machine with a single processor, what advantage would you gain by having a multi-threaded application?
A: If one thread is waiting for some event like I/O or user input, then other threads can use the CPU. If all threads are computation intensive then having multiple threads might not be that helpful.
Q: What is the disadvantage of using the Spring framework?
A: Since all objects are created at runtime using the XML config, any errors in the bean definition will only be observed at runtime, and not at compile time.
Q: Explain the Java memory model?
A: Data is stored on the Heap and the Stack. There is a common heap for the entire process that is shared by all the threads. Any objects are created on the heap. Each thread gets its own stack, and local variables are created on the stack.
Q: Why would you use a distributed cache in your application?
A:
1. In a standard java process on 32bit JVM, each process can only have a heap of 2 GB. If we want to store more data then it is a problem. By having a distributed cache we can bypass that limitation by being able to store as much data as possible. Now we have a large cloud of data running across multiple machines. This approach is very scalable. As the requirements grow, we just need to add more machines to the cache cluster.
2. We wanted to store data inside memory instead of a database, for faster access to the data.
View further details and comments
Q: What are the new changes coming up in Java 7?
A:
1. More predictable garbage collector. A new garbage collector that promises to achieve lower pause times and better predictability than the current CMS collector (VM-level feature)
2. VM extensions to support the implementation of non-Java languages at performance levels near to that of the Java language itself
3. Project Jigsaw – An implementation-specific, simple, low-level module system focused upon the goal of modularizing the JDK, and the application of that system to the JDK itself
4. NIO2 - New APIs for filesystem access, scalable asynchronous I/O operations, socket-channel binding and configuration, and multicast datagrams. NIO2 uses operating system specific code to access files, directories and network resources, which leads to several speed improvements as well as extended capabilities which were not possible without NIO2. One of the notable improvements offered by NIO2 is the possibility of asynchronous access of (metadata) of files, enabling for example to execute code when a file is change without having to poll the file regularly for changes.
5. Improved type inference for Generics, making it possible to write for example the following:
Map<String , List<String>> myMap = new HashMap<>();
View further details and comments
Q: How does garbage collection work?
A: The default collector has two generations - young and tenured. Most allocations are done in the young generation which is optimized for objects that have a shorter lifetime. Objects that survive several collections get moved to the tenured generation, which is collected less often as compared to the young generation.
Young generation – The collector is a copying collector with an option to collect the generation in parallel.
Tenured generation – The tenured generation is collected using a mark-sweep-compaction algorithm. There is an option to perform this collection concurrently.
View further details and comments
No related posts.










One Response
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
Hi Techbhai,
Another method you may want to add to the list of ways a thread can be created: Callable interface in Java 5
>Implement Callable interface.
>Define the call() method like run()
>Call it using ExecuterService