IPU Java Important Questions Answers
IPU Java Important Questions Answers
use `ObjectOutputStream`/`ObjectInputStream`.
Q: Write a program to copy contents from one file to another using streams.
A: 1. Load driver
2. Create connection
3. Create statement
4. Execute query
5. Process result
6. Close connection.
A: `Statement` is used for static queries. `PreparedStatement` is used for dynamic queries and
A: JDBC is platform-independent, pure Java, and works better with Java apps. ODBC is native and
platform-dependent.
A: TCP is reliable and connection-oriented. UDP is faster but connectionless and unreliable.
A: Use `ServerSocket` on server side and `Socket` on client side. Use streams for communication.
A: `ServerSocket` waits for client connections. `Socket` represents the client-server connection.
Q: What are the differences between extending the Thread class and implementing the
Runnable interface?
A: `Runnable` allows multiple inheritance. `Thread` class gives more control. Both can be used to
create threads.
A: Synchronization ensures only one thread accesses a critical section at a time to prevent data
inconsistency.
A: RMI uses stub, skeleton, registry, and remote interfaces for object-based communication over
network.
2. Implement interface
A: Set a proper `SecurityManager`, use policy files, and validate remote object inputs.
A: JNI allows Java to call native code (e.g., C/C++). Used for performance and system-level
operations.
Q: Describe the steps to integrate native C code with Java using JNI.
2. Generate header
3. Implement in C
A: Pros: Speed, native access. Cons: Platform dependency, complexity, harder debugging.
A: Create a List and use `Iterator` for forward-only and `ListIterator` for bi-directional traversal.
A: `Set` does not allow duplicates. `List` allows duplicates and maintains insertion order.
`Collections.synchronizedList()` if needed.