1. What are a java object and java application?
Java objects are a combination of data and procedures working on the available data and are provided by the execution of an application. These are made during the compilation of an application. Objects are characterized by their state (stored in fields (variables)) and behavior (displayed in methods (functions)). Objects are created from templates known as classes.
Java applications are programs written in Java and read by the Java virtual machine.
2. How does Java handle integer overflows and underflows?
It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.
3. What are the advantages and disadvantages of Java Sockets?
Following are the advantages and disadvantages of Java Sockets:
- Flexible and easy to implement for general communications.
- Causes low network traffic unlike HTML forms and CGI scripts that generate and transfer whole web pages for each new request.
- Allows only to send packets of raw data between applications.
- Both the client-side and server-side have to provide mechanisms to make the data useful in any way.
4. How do we use threads?
We can implement threads by using runnable interface or by inheriting from the Thread class.
5. What is an immutable class?
Immutable class is class where contents cannot be changed once they are created. Similarly, immutable objects are the objects whose state cannot be changed once constructed.
6. What are “pass by reference” and “pass by value”?
Pass by Reference means the passing the address itself rather than passing the value while pass by Value means passing a copy of the value to be passed.
7. What are the differences between Array List and Vector?
Following are the differences between Array List and Vector:
|It is not thread-safe||It thread-safe|
|hold onto their contents using an Array||Each method is surrounded by a synchronized block|
|Increases its array size by 50 percent.||defaults to doubling the size of its array|
8. What are the differences between HashMap and HashTable?
Following are the differences between HashMap and HashTable:
|Allows null values as key and value||Doesn’t allow null values as key and value|
Does not guarantee that the order of the map will remain constant over time
|Order of the map will remain constant over time|
|It is unsynchronized||It is synchronized|
9. What is synchronization and why is it important?
Synchronization is the capability to control access of multiple threads to shared resources with respect to multithreading. It is important because it does not allow one thread to modify a shared object while another thread is in the process of using or updating that object’s value.
10. What are the differences between an Interface and an Abstract class?
Following are the differences between an Interface and an Abstract class:
|Interface Class||Abstract Class|
|Can have instance methods that implement a default behavior||Can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract.|
|Has all public members and no implementation||May have the usual flavors of class members (private, protected, etc.), but has some abstract methods|
11. What are the differences between multiple processes and multiple threads?
Following are the differences between multiple processes and multiple threads:
|Multiple Process||Multiple Threads|
|Multiple processes consist of a complete set of its own variables and data and are safe to use||Multiple threads share the same variable and the same data are riskier in the sense that they share the same data|
|Have much more overhead||Have less overhead and individual threads can be standalone if other threads are destroyed|
|Inter process communication is slower and more restrictive||Communication between threads is faster|
12. What is Externalizable interface?
Externalizable is an interface with the methods readExternal and writeExternal and gives us control over the serialization mechanism. Thus if your class implements this interface, you can customize the serialization process by implementing these methods.
13. How are Observer and Observable used?
Subclasses of the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the changes. The Observer interface is implemented by objects that observe Observable objects.
14. What is static class in java?
In Java, any member declared as static can be accessed ahead of the creation of objects of a class without reference to any object. It is used with variables, methods, blocks and nested class. Static as a keyword in Java describes how objects are managed in the memory. Static is used for a common constant variable or a method at every instance of a class.
15. What are the different types of inner classes?
- Nested top-level classes
- Member classes
- Local classes
- Anonymous classes
16. Objects are passed by value or by reference?
Java only supports pass by value. With objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same object.
Read more at Java Interview Question: Java Basics